summaryrefslogtreecommitdiff
path: root/src/thread.hpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2012-04-14 16:39:39 +0200
committerMartin Sustrik <sustrik@250bpm.com>2012-04-15 06:57:37 +0200
commitda8b8000bd2a84c04a3a9cd6ce57f9bc814595cf (patch)
treec35be3404a8133ba5c4ef2a203bb7fa6fc108e22 /src/thread.hpp
parente86827511b35231679085dc236e9744184ed4609 (diff)
thread_t rewritten in C style
thread_t is one of the classes where C++ syntax creates more problems then it solves. This patch converts it into simple C-style pseudo-class. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/thread.hpp')
-rw-r--r--src/thread.hpp41
1 files changed, 11 insertions, 30 deletions
diff --git a/src/thread.hpp b/src/thread.hpp
index b7a7607..8258dab 100644
--- a/src/thread.hpp
+++ b/src/thread.hpp
@@ -35,45 +35,26 @@ namespace xs
typedef void (thread_fn) (void*);
- // Class encapsulating OS thread. Thread initiation/termination is done
- // using special functions rather than in constructor/destructor so that
- // thread isn't created during object construction by accident, causing
- // newly created thread to access half-initialised object. Same applies
- // to the destruction process: Thread should be terminated before object
- // destruction begins, otherwise it can access half-destructed object.
+ // Class encapsulating OS thread.
- class thread_t
+ struct thread_t
{
- public:
-
- inline thread_t ()
- {
- }
-
- // Creates OS thread. 'tfn' is main thread function. It'll be passed
- // 'arg' as an argument.
- void start (thread_fn *tfn_, void *arg_);
-
- // Waits for thread termination.
- void stop ();
-
- // These are internal members. They should be private, however then
- // they would not be accessible from the main C routine of the thread.
thread_fn *tfn;
void *arg;
-
- private:
-
#ifdef XS_HAVE_WINDOWS
- HANDLE descriptor;
+ HANDLE handle;
#else
- pthread_t descriptor;
+ pthread_t handle;
#endif
-
- thread_t (const thread_t&);
- const thread_t &operator = (const thread_t&);
};
+ // Creates OS thread. 'tfn' is main thread function. It'll be passed
+ // 'arg' as an argument.
+ void thread_start (thread_t *self_, thread_fn *tfn_, void *arg_);
+
+ // Waits for thread termination.
+ void thread_stop (thread_t *self_);
+
}
#endif