From: Karel G. <kg...@us...> - 2001-12-21 20:25:00
|
Update of /cvsroot/micomt/mico/include/mico/os-thread In directory usw-pr-cvs1:/tmp/cvs-serv19868/include/mico/os-thread Modified Files: pthreads.h Log Message: - made global debug mutex not recursive - renamed swap16 to swap_16 because of name clash with OpenBSD's swap16 macro - fixed time service for compilation on *BSD - removed old gcc related params from configure - added checking for pthread's symbols in libc_r (needs for FreeBSD, OpenBSD) - added semaphore implementation based on mutex & condvar (needs for OpenBSD) it is used on OSes which doesn't provide POSIX implementation and semaphore.h Index: pthreads.h =================================================================== RCS file: /cvsroot/micomt/mico/include/mico/os-thread/pthreads.h,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -r1.27 -r1.28 *** pthreads.h 2001/11/24 19:45:26 1.27 --- pthreads.h 2001/12/21 20:24:56 1.28 *************** *** 374,377 **** --- 374,382 ---- * counter for resources shared between threads. */ + + #ifdef HAVE_SEMAPHORE_H + // the OS provides POSIX semaphore implementation + // in semaphore.h header file + class Semaphore __NAME( :public NamedObject ) { *************** *** 465,468 **** --- 470,507 ---- //@} }; + + #else // HAVE_SEMAPHORE_H + + // the OS doesn't provide POSIX semaphore implementation + // in semaphore.h header file so we will use own + // implementation based on mutex and condition variable + + class Semaphore __NAME(:public NamedObject) + { + Mutex _M_mutex; + CondVar _M_condition; + unsigned int _M_counter; + public: + enum ErrorType { + NoError, //!< No error on semaphore + NoPermission, //!< Permission denied + TryAgain, //!< Try again + SemInvalid, //!< Invalide semaphore + Interrupted, //!< Interrupted by signal + UnknownError //!< Unknow error + }; + + //! \name Constructor/Destructor + //@{ + Semaphore(unsigned int __value = 0); + ~Semaphore(); + //@} + + void wait(); + Semaphore::ErrorType trylock(); + void post(); + }; + + #endif // HAVE_SEMAPHORE_H /******************************* basic Thread class *********************************/ |