00001 /* 00002 wefts_os_base.h 00003 Abstract base class for os dependant implementations 00004 00005 $Id: wefts_os_base.h,v 1.2 2003/08/16 13:23:58 jonnymind Exp $ 00006 --------------------------------------------- 00007 Begin : 2003-08-15 16:30 00008 Author : Giancarlo Niccolai 00009 00010 Last modified because: 00011 00012 */ 00013 00014 /************************************************************************** 00015 * This program is free software; you can redistribute it and/or modify * 00016 * it under the terms of the GNU Library General Public License as * 00017 * published by the Free Software Foundation; either version 2.1 of the * 00018 * License, or (at your option) any later version. * 00019 ***************************************************************************/ 00020 00021 00022 #ifndef WT_OS_BASE_H 00023 #define WT_OS_BASE_H 00024 00025 #include <wefts_cleanup.h> 00026 #include <string> 00027 00042 namespace Wefts { 00043 00054 class OSMutexBase { 00055 protected: 00057 OSMutexBase(){} 00058 00059 public: 00061 virtual inline void lock()=0; 00062 00064 virtual inline bool trylock()=0; 00065 00067 virtual inline void unlock()=0; 00068 }; 00069 00085 class OSConditionBase { 00086 protected: 00088 OSConditionBase() {} 00089 00090 public: 00092 virtual void signal()=0; 00093 00107 virtual bool wait( OSMutexBase &mtx, CleanupItem guard )=0; 00108 00117 virtual bool timedWait( OSMutexBase &mtx, long seconds, 00118 long nanoseconds, CleanupItem guard )=0; 00119 }; 00120 00126 class OSThreadBase { 00127 protected: 00132 OSThreadBase() {} 00133 00138 OSThreadBase( bool ) {} 00139 00140 protected: 00145 virtual void exit( void *data )=0; 00146 00147 public: 00154 virtual bool start( void *(*func)(void *), void *data )=0; 00155 00157 virtual bool stop()=0; 00158 00160 virtual void *join()=0; 00161 00169 virtual int enableCancel()=0; 00170 00175 virtual int disableCancel()=0; 00176 00184 virtual bool setCancelState( int state )=0; 00185 00187 virtual void testCancel()=0; 00193 virtual void setCancelDeferred()=0; 00200 virtual void detach()=0; 00201 00202 00205 virtual bool same() const=0; 00206 00208 virtual bool equal( const OSThreadBase &th ) const =0; 00209 00216 virtual bool setCurrent()=0; 00217 00218 /* Invalidate current thread. 00219 This function must make so that the invalidated thread always returns 00220 false when same() or equal() are called. If equal() method is called 00221 upon another invalid thread, the result is undefined. 00222 */ 00223 virtual void invalidate()=0; 00224 00226 virtual bool operator==( OSThreadBase &th ) { return equal( th ); } 00227 00229 virtual bool operator!=( OSThreadBase &th ) { return ! equal( th ); } 00230 }; 00231 00233 class OSSpecificDataBase 00234 { 00235 protected: 00237 OSSpecificDataBase() {} 00238 00239 public: 00240 00242 virtual void *data() const =0; 00243 00245 virtual void data(const void *dt) =0; 00246 }; 00247 00249 void OSPushCleanupAndExecute( 00250 void (*runner)(void *), 00251 void (*cleaner)(void *), 00252 void *data ); 00253 00255 std::string OSErrorDescription( int osCode ); 00256 00258 } // namespace 00259 00260 #endif 00261 00262 /* end of wefts_os_pthread.h */