Main Page   Packages   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

Thread.cpp

Go to the documentation of this file.
00001 /*
00002  * $Id: Thread.cpp,v 1.2 2002/07/08 04:58:12 mindstorm2600 Exp $
00003  * 
00004  * This class encapsulates the thread library functionality through SDL
00005  * and GNU Pth
00006  */
00007 #include<iostream.h>
00008 #include<errno.h>
00009 #ifdef USE_GNUPTH
00010 #include<pth.h>
00011 #endif
00012 #include<stdlib.h>
00013 #include<errno.h>
00014 #include<unistd.h>
00015 #include"Thread.h"
00016 
00017 namespace clawsoft{
00018 Thread::Thread(){
00019         setClassName("Thread");
00020 }
00021 
00022 int Thread::start(){
00023  Thread *t = this;
00024  int r;
00025 #ifdef USE_GNUPTH
00026  thread = pth_spawn(PTH_ATTR_DEFAULT, runMethod, t);
00027 #else
00028  thread = SDL_CreateThread(runMethod, t);
00029 #endif
00030  return r;
00031 }
00032 
00033 void Thread::detach(){
00034 #ifdef USE_GNUPTH
00035         pth_cancel(thread);
00036 #else
00037         SDL_KillThread(thread);
00038 #endif
00039 #ifdef USE_DEBUG
00040  cerr << "DETACHING THREAD\n";
00041 #endif
00042 }
00043 
00044 int Thread::_start(){
00045  int y;
00046  y = start();
00047 #ifdef USE_GNUPTH
00048  void *rr;
00049  pth_join(thread, &rr);
00050 #endif
00051  return y;
00052 }
00053 
00054 void Thread::killMe(){
00055 #ifdef USE_GNUPTH
00056         pth_cancel(thread);
00057 #else
00058         SDL_KillThread(thread);
00059 #endif
00060 }
00061 
00062 #ifdef USE_GNUPTH
00063 void *Thread::runMethod(void *meptr){
00064 #else
00065 int Thread::runMethod(void *meptr){
00066 #endif
00067  Thread *me = (Thread *)meptr;
00068  me->run();
00069 #ifdef USE_GNUPTH
00070  return NULL;
00071 #else
00072  return 0;
00073 #endif
00074 }
00075 
00076 void *Thread::run(){
00077  cerr << "You should override this method in a new class\n";
00078  return NULL;
00079 }
00080 
00081 };

Powered by:

SourceForge Logo