summaryrefslogtreecommitdiff
path: root/src/itomutex.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-26 15:06:49 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-26 15:06:49 +0000
commit530014a3cce53e86dce8917e98a4e86d02f176aa (patch)
treec667c996fb91692b101f75296206b8420f19bf73 /src/itomutex.h
parent066282ae6de25cf92780dbdaa2fd70a033e95659 (diff)
downloadlibbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.tar.gz
libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.tar.bz2
libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.tar.xz
libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.zip
Merged Ito and put it in the BU namespace. I should probably clean up the
formatting on the comments, some of the lines wrap, but I'm not too worried about it right now. I also fixed up the doxygen config and build.conf files so that everything is building nice and smooth now.
Diffstat (limited to 'src/itomutex.h')
-rw-r--r--src/itomutex.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/itomutex.h b/src/itomutex.h
new file mode 100644
index 0000000..80956b8
--- /dev/null
+++ b/src/itomutex.h
@@ -0,0 +1,61 @@
1#ifndef ITO_MUTEX_H
2#define ITO_MUTEX_H
3
4#include <pthread.h>
5
6namespace Bu
7{
8 /**
9 * Simple mutex wrapper. Currently this doesn't do anything extra for you
10 * except keep all of the functionality together in an OO sorta' way and keep
11 * you from having to worry about cleaning up your mutexes properly, or initing
12 * them.
13 *@author Mike Buland
14 */
15 class ItoMutex
16 {
17 public:
18 /**
19 * Create an unlocked mutex.
20 */
21 ItoMutex();
22
23 /**
24 * Destroy a mutex. This can only be done when a mutex is unlocked.
25 * Failure to unlock before destroying a mutex object could cause it to
26 * wait for the mutex to unlock, the odds of which are usually farily low
27 * at deconstruction time.
28 */
29 ~ItoMutex();
30
31 /**
32 * Lock the mutex. This causes all future calls to lock on this instance
33 * of mutex to block until the first thread that called mutex unlocks it.
34 * At that point the next thread that called lock will get a chance to go
35 * to work. Because of the nature of a mutex lock it is a very bad idea to
36 * do any kind of serious or rather time consuming computation within a
37 * locked section. This can cause thread-deadlock and your program may
38 * hang.
39 */
40 int lock();
41
42 /**
43 * Unlock the mutex. This allows the next thread that asked for a lock to
44 * lock the mutex and continue with execution.
45 */
46 int unlock();
47
48 /**
49 * Try to lock the mutex. This is the option to go with if you cannot avoid
50 * putting lengthy operations within a locked section. trylock will attempt
51 * to lock the mutex, if the mutex is already locked this function returns
52 * immediately with an error code.
53 */
54 int trylock();
55
56 protected:
57 pthread_mutex_t mutex; /**< The internal mutex reference. */
58 };
59}
60
61#endif