aboutsummaryrefslogtreecommitdiff
path: root/src/stable/condition.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-05 22:41:51 +0000
commitec05778d5718a7912e506764d443a78d6a6179e3 (patch)
tree78a9a01532180030c095acefc45763f07c14edb8 /src/stable/condition.h
parentb20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff)
downloadlibbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz
libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/condition.h')
-rw-r--r--src/stable/condition.h130
1 files changed, 65 insertions, 65 deletions
diff --git a/src/stable/condition.h b/src/stable/condition.h
index 2c27720..53eb9ff 100644
--- a/src/stable/condition.h
+++ b/src/stable/condition.h
@@ -14,77 +14,77 @@
14 14
15namespace Bu 15namespace Bu
16{ 16{
17 /** 17 /**
18 * Ito condition. This is a fairly simple condition mechanism. As you may 18 * Ito condition. This is a fairly simple condition mechanism. As you may
19 * notice this class inherits from the Mutex class, this is because all 19 * notice this class inherits from the Mutex class, this is because all
20 * conditions must be within a locked block. The standard usage of a 20 * conditions must be within a locked block. The standard usage of a
21 * condition is to pause one thread, perhaps indefinately, until another 21 * condition is to pause one thread, perhaps indefinately, until another
22 * thread signals that it is alright to procede. 22 * thread signals that it is alright to procede.
23 * <br> 23 * <br>
24 * Standard usage for the thread that wants to wait is as follows: 24 * Standard usage for the thread that wants to wait is as follows:
25 * <pre> 25 * <pre>
26 * Condition cond; 26 * Condition cond;
27 * ... // Perform setup and enter your run loop 27 * ... // Perform setup and enter your run loop
28 * cond.lock(); 28 * cond.lock();
29 * while( !isFinished() ) // Could be anything you're waiting for 29 * while( !isFinished() ) // Could be anything you're waiting for
30 * cond.wait(); 30 * cond.wait();
31 * ... // Take care of what you have to. 31 * ... // Take care of what you have to.
32 * cond.unlock(); 32 * cond.unlock();
33 * </pre> 33 * </pre>
34 * The usage for the triggering thread is much simpler, when it needs to 34 * The usage for the triggering thread is much simpler, when it needs to
35 * tell the others that it's time to grab some data it calls either signal 35 * tell the others that it's time to grab some data it calls either signal
36 * or broadcast. See both of those functions for the difference. 36 * or broadcast. See both of those functions for the difference.
37 *@ingroup Threading 37 *@ingroup Threading
38 */ 38 */
39 class Condition : public Mutex 39 class Condition : public Mutex
40 { 40 {
41 public: 41 public:
42 /** 42 /**
43 * Create a condition. 43 * Create a condition.
44 */ 44 */
45 Condition(); 45 Condition();
46 46
47 /** 47 /**
48 * Destroy a condition. 48 * Destroy a condition.
49 */ 49 */
50 ~Condition(); 50 ~Condition();
51 51
52 /** 52 /**
53 * Wait forever, or until signalled. This has to be called from within 53 * Wait forever, or until signalled. This has to be called from within
54 * a locked section, i.e. before calling this this object's lock 54 * a locked section, i.e. before calling this this object's lock
55 * function should be called. 55 * function should be called.
56 */ 56 */
57 int wait(); 57 int wait();
58 58
59 /** 59 /**
60 * Wait for a maximum of nSec seconds and nUSec micro-seconds or until 60 * Wait for a maximum of nSec seconds and nUSec micro-seconds or until
61 * signalled. This is a little more friendly function if you want to 61 * signalled. This is a little more friendly function if you want to
62 * perform other operations in the thrad loop that calls this function. 62 * perform other operations in the thrad loop that calls this function.
63 * Like the other wait function, this must be inside a locked section. 63 * Like the other wait function, this must be inside a locked section.
64 *@param nSec The seconds to wait. 64 *@param nSec The seconds to wait.
65 *@param nUSec the micro-seconds to wait. 65 *@param nUSec the micro-seconds to wait.
66 */ 66 */
67 int wait( int nSec, int nUSec ); 67 int wait( int nSec, int nUSec );
68 68
69 /** 69 /**
70 * Notify the next thread waiting on this condition that they can go 70 * Notify the next thread waiting on this condition that they can go
71 * ahead. This only signals one thread, the next one in the condition 71 * ahead. This only signals one thread, the next one in the condition
72 * queue, that it is safe to procede with whatever operation was being 72 * queue, that it is safe to procede with whatever operation was being
73 * waited on. 73 * waited on.
74 */ 74 */
75 int signal(); 75 int signal();
76 76
77 /** 77 /**
78 * Notify all threads waiting on this condition that they can go ahead 78 * Notify all threads waiting on this condition that they can go ahead
79 * now. This function is slower than signal, but more effective in 79 * now. This function is slower than signal, but more effective in
80 * certain situations where you may not know how many threads should be 80 * certain situations where you may not know how many threads should be
81 * activated. 81 * activated.
82 */ 82 */
83 int broadcast(); 83 int broadcast();
84 84
85 private: 85 private:
86 pthread_cond_t cond; /**< Internal condition reference. */ 86 pthread_cond_t cond; /**< Internal condition reference. */
87 }; 87 };
88} 88}
89 89
90#endif 90#endif