summaryrefslogtreecommitdiff
path: root/NxWidgets/nxwm/include
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-05-12 11:47:09 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-05-12 11:47:09 -0600
commit761d051218d4bf29a71532d7e67a18beda63cb30 (patch)
treecf7f509dda831dcc7257e379e4d241a01348f08e /NxWidgets/nxwm/include
parent9cbcaf0b572ee505767e47fcc41cfe660c8e3ae3 (diff)
downloadnuttx-761d051218d4bf29a71532d7e67a18beda63cb30.tar.gz
nuttx-761d051218d4bf29a71532d7e67a18beda63cb30.tar.bz2
nuttx-761d051218d4bf29a71532d7e67a18beda63cb30.zip
Fixe a race confition in NxWM::CCalibration
Diffstat (limited to 'NxWidgets/nxwm/include')
-rw-r--r--NxWidgets/nxwm/include/ccalibration.hxx33
1 files changed, 28 insertions, 5 deletions
diff --git a/NxWidgets/nxwm/include/ccalibration.hxx b/NxWidgets/nxwm/include/ccalibration.hxx
index a54a35bf7..f114a19a2 100644
--- a/NxWidgets/nxwm/include/ccalibration.hxx
+++ b/NxWidgets/nxwm/include/ccalibration.hxx
@@ -1,7 +1,7 @@
/****************************************************************************
* NxWidgets/nxwm/include/ccalibration.hxx
*
- * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -175,22 +175,45 @@ namespace NxWM
/**
* Return true if the calibration thread is running normally. There are
- * lots of potential race conditions. Let's hope that things are running
- * orderly and we that we do not have to concern ourself with them
+ * lots of potential race conditions. There are also two ambiguous
+ * states:
+ *
+ * 1) The thread may have been started but not yet running
+ * (CALTHREAD_STARTED), or the
+ * 2) The thread may been requested to terminate, but has not yet
+ * terminated (CALTHREAD_STOPREQUESTED)
+ *
+ * Both of those states will cause isRunning() to return false.
*
* @return True if the calibration thread is runnning normally.
*/
inline bool isRunning(void) const
{
- // What if the boundary states CALTHREAD_STARTED and CALTHREAD_STOPREQUESTED?
-
return (m_calthread == CALTHREAD_RUNNING ||
m_calthread == CALTHREAD_HIDE ||
m_calthread == CALTHREAD_SHOW);
}
/**
+ * Return true if the calibration thread is has been started and has not
+ * yet terminated. There is a potential race condition here when the
+ * thread has been requested to terminate, but has not yet terminated
+ * (CALTHREAD_STOPREQUESTED). isStarted() will return false in that case.
+ *
+ * @return True if the calibration thread has been started and/or is
+ * running normally.
+ */
+
+ inline bool isStarted(void) const
+ {
+ return (m_calthread == CALTHREAD_STARTED ||
+ m_calthread == CALTHREAD_RUNNING ||
+ m_calthread == CALTHREAD_HIDE ||
+ m_calthread == CALTHREAD_SHOW);
+ }
+
+ /**
* The calibration thread. This is the entry point of a thread that provides the
* calibration displays, waits for input, and collects calibration data.
*