aboutsummaryrefslogtreecommitdiff
path: root/src/ito.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-10-06 03:25:22 +0000
committerMike Buland <eichlan@xagasoft.com>2011-10-06 03:25:22 +0000
commit208b983734d7431699f4bd3534e08321e42ada86 (patch)
treea6865f0db36e9c3b8dd13b9ed4d10d282f0f7cbf /src/ito.h
parent1358cb4c7325e01c13533ca402cccc28575cdf14 (diff)
downloadlibbu++-208b983734d7431699f4bd3534e08321e42ada86.tar.gz
libbu++-208b983734d7431699f4bd3534e08321e42ada86.tar.bz2
libbu++-208b983734d7431699f4bd3534e08321e42ada86.tar.xz
libbu++-208b983734d7431699f4bd3534e08321e42ada86.zip
Renamed most of the core threading system, some ancillary systems need some
kind of prefix or something, we could stick with Ito, I will until I think of something else.
Diffstat (limited to 'src/ito.h')
-rw-r--r--src/ito.h107
1 files changed, 0 insertions, 107 deletions
diff --git a/src/ito.h b/src/ito.h
deleted file mode 100644
index 9f50b2a..0000000
--- a/src/ito.h
+++ /dev/null
@@ -1,107 +0,0 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_ITO_H
9#define BU_ITO_H
10
11#include <pthread.h>
12
13namespace Bu
14{
15 /**
16 * Simple thread class. This wraps the basic pthread (posix threads)
17 * system in an object oriented sort of way. It allows you to create a
18 * class with standard member variables and callable functions that can be
19 * run in it's own thread, one per class instance.
20 *@ingroup Threading
21 */
22 class Ito
23 {
24 public:
25 /**
26 * Construct an Ito thread.
27 */
28 Ito();
29
30 /**
31 * Destroy an Ito thread.
32 */
33 virtual ~Ito();
34
35 /**
36 * Begin thread execution. This will call the overridden run function,
37 * which will simply execute in it's own thread until the function
38 * exits, the thread is killed, or the thread is cancelled (optionally).
39 * The thread started in this manner has access to all of it's class
40 * variables, but be sure to protect possible multiple-access with
41 * ItoMutex objects.
42 * @returns True if starting the thread was successful. False if
43 * something went wrong and the thread has not started.
44 */
45 bool start();
46
47 /**
48 * Forcibly kill a thread. This is not generally considered a good
49 * thing to do, but in those rare cases you need it, it's invaluable.
50 * The problem with stopping (or killing) a thread is that it stops it
51 * the moment you call stop, no matter what it's doing. The object
52 * oriented approach to this will help clean up any class variables
53 * that were used, but anything not managed as a member variable will
54 * probably create a memory leak type of situation. Instead of stop,
55 * consider using cancel, which can be handled by the running thread in
56 * a graceful manner.
57 *@returns True if the thread was stopped, false otherwise. When this
58 * function returns the thread may not have stopped, to ensure that the
59 * thread has really stopped, call join.
60 */
61 bool stop();
62
63 /**
64 * Join the thread in action. This function performs what is commonly
65 * called a thread join. That is that it effectively makes the calling
66 * thread an the Ito thread contained in the called object one in the
67 * same, and pauses the calling thread until the called thread exits.
68 * That is, when called from, say, your main(), mythread.join() will
69 * not return until the thread mythread has exited. This is very handy
70 * at the end of programs to ensure all of your data was cleaned up.
71 *@returns True if the thread was joined, false if the thread couldn't
72 * be joined, usually because it isn't running to begin with.
73 */
74 bool join();
75
76 private:
77 pthread_t ptHandle; /**< Internal handle to the posix thread. */
78 int nHandle; /**< Numeric handle to the posix thread. */
79
80 protected:
81 /**
82 * The workhorse of the Ito class. This is the function that will run
83 * in the thread, when this function exits the thread dies and is
84 * cleaned up by the system. Make sure to read up on ItoMutex,
85 * ItoCondition, and cancel to see how to control and protect
86 * everything you do in a safe way within this function.
87 *@returns I'm not sure right now, but this is the posix standard form.
88 */
89 virtual void run()=0;
90
91 /**
92 * This is the hidden-heard of the thread system. While run is what the
93 * user gets to override, and everything said about it is true, this is
94 * the function that actually makes up the thread, it simply calls the
95 * run member function in an OO-friendly way. This is what allows us to
96 * use member variables from within the thread itself.
97 *@param pThread Should always be this.
98 *@returns This is specified by posix, I'm not sure yet.
99 */
100 static void *threadRunner( void *pThread );
101
102 void yield();
103
104 };
105}
106
107#endif