00001 #include <assert.h>
00002 #include "semaphore.h"
00003
00004
00005
00006 Semaphore::Semaphore( const char* name )
00007 {
00008 #ifdef WIN32
00009 semaphore = new CSemaphore( 1, 1, name, NULL );
00010 singleLock = new CSingleLock( semaphore );
00011
00012 this->name = new char[ strlen( name ) + 1 ];
00013 strcpy( this->name, name );
00014 #endif
00015 }
00016
00017 Semaphore::Semaphore( const int guid )
00018 {
00019 #ifdef WIN32
00020 char name[ 256 ] = "";
00021 sprintf( name, "%x", guid );
00022 this->name = new char[ strlen( name ) + 1 ];
00023 strcpy( this->name, name );
00024
00025 this->semaphore = new CSemaphore( 1, 1, name, NULL );
00026 singleLock = new CSingleLock( semaphore );
00027 #endif
00028 }
00029
00030 Semaphore::~Semaphore()
00031 {
00032 #ifdef WIN32
00033 delete singleLock;
00034 delete semaphore;
00035 delete [] name;
00036 #endif
00037 }
00038
00039
00040 void Semaphore::Lock()
00041 {
00042 #ifdef WIN32
00043 if( !singleLock->IsLocked() )
00044 {
00045 while( singleLock->Lock( 500 ) == false )
00046 {
00047
00048
00049 }
00050 }
00051 else
00052 {
00053 assert( false );
00054 }
00055 #endif
00056 }
00057
00058
00059 void Semaphore::Unlock()
00060 {
00061 #ifdef WIN32
00062 singleLock->Unlock();
00063 #endif
00064 }