Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

semaphore.cc

Go to the documentation of this file.
00001 //**************************************************************************
00002 #include "semaphore.h"
00003 //**************************************************************************
00004 Semaphore::Semaphore()
00005 {
00006 pthread_mutex_init(&mutex, NULL);
00007 waitcount = postcount = 0;
00008 }
00009 //**************************************************************************
00010 Semaphore::~Semaphore()
00011 {
00012 pthread_mutex_destroy(&mutex);
00013 }
00014 //**************************************************************************
00015 bool Semaphore::isBusy()
00016 {
00017 int flag = false;
00018 int err = pthread_mutex_trylock(&mutex);
00019 if (err == EBUSY) flag = true;
00020 
00021 if (!err) Post();
00022 
00023 return flag;
00024 }
00025 //**************************************************************************
00026 int Semaphore::Wait()
00027 {
00028 ++waitcount;
00029 pthread_mutex_lock(&mutex);
00030 return 0;
00031 }
00032 //**************************************************************************
00033 int Semaphore::Post()
00034 {
00035 ++postcount;
00036 pthread_mutex_unlock(&mutex);
00037 return 0;
00038 }
00039 //**************************************************************************
00040 int Semaphore::WaitCount()
00041 {
00042 return waitcount;
00043 }
00044 //**************************************************************************
00045 int Semaphore::PostCount()
00046 {
00047 return postcount;
00048 }
00049 //**************************************************************************

Generated on Sun Jun 16 17:36:50 2002 for POSSE: Portable Object-oriented Scientific Steering Environment by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001