Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PosixThread.cpp

Go to the documentation of this file.
00001 #include <unistd.h>
00002 #include "OSDependent/Posix/PosixThread.h"
00003 
00004 extern "C" void *threadEntry(void *arg);
00005 
00006 PosixThread::PosixThread(Runnable *runnable) :
00007 _tid(0),
00008 _runnable(runnable)
00009 {
00010 }
00011 
00012 PosixThread::~PosixThread()
00013 {
00014 }
00015 
00016 int 
00017 PosixThread::start()
00018 {
00019   return ::pthread_create(&_tid, NULL, threadEntry, _runnable);
00020 }
00021 
00022 int 
00023 PosixThread::join()
00024 {
00025   return ::pthread_join(_tid, NULL);
00026 }
00027 
00028 void 
00029 PosixThread::sleep(long msec)
00030 {
00031   struct timeval timeout;
00032   timeout.tv_sec = msec / 1000;
00033   timeout.tv_usec = (msec % 1000) * 1000;
00034   ::select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout);
00035 }
00036 
00037 void *
00038 threadEntry(void *arg)
00039 {
00040   Runnable *runnable = (Runnable *)arg;
00041   runnable->run();
00042   return NULL;
00043 }
00044 

Generated on Mon Oct 7 09:33:31 2002 for Gaia by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001