additional/synchronization/semaphore.cpp

Go to the documentation of this file.
00001 #include <assert.h>
00002 #include "semaphore.h"
00003 
00004 
00005 //constructor
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 //locks the semaphore
00040 void Semaphore::Lock()
00041 {
00042 #ifdef WIN32
00043     if( !singleLock->IsLocked() )
00044     {
00045         while( singleLock->Lock( 500 ) == false )
00046         {
00047             //assert( false );
00048             //return;
00049         }
00050     }
00051     else
00052     {
00053         assert( false );
00054     }
00055 #endif
00056 }
00057 
00058 //unlocks the semaphore
00059 void Semaphore::Unlock()
00060 {
00061 #ifdef WIN32
00062     singleLock->Unlock();
00063 #endif
00064 }

Generated on Sat Apr 1 21:30:30 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO