#include <PsnPthreadSemaphore.h>
Inheritance diagram for PsnPthreadSemaphore:


Public Methods | |
| PsnPthreadSemaphore (const int valeurInitiale) | |
| Constructor. | |
| virtual | ~PsnPthreadSemaphore () |
| Destructor. | |
| virtual int | V () |
| V Increments the semphore value and signals the change to blocked threads. | |
| virtual int | P () |
| P decrement the sempaphore value and block the calling thread if this value is negative. | |
Private Attributes | |
| pthread_cond_t | _cond |
| pthread_mutex_t | _mutex |
| int | _v |
Semaphores for multithreading using pthreads.
Definition at line 29 of file PsnPthreadSemaphore.h.
|
|
Constructor.
Definition at line 21 of file PsnPthreadSemaphore.cxx. References _cond, _mutex, and _v.
00021 : PsnSemaphore(valeurInitiale){ 00022 int ret; 00023 _v=valeurInitiale; 00024 ret=pthread_mutex_init(&_mutex,NULL); 00025 if(ret) { 00026 perror("PsnPthreadSemaphore : impossible d'initialiser le mutex"); 00027 } 00028 ret=pthread_cond_init(&_cond,NULL); 00029 if(ret) { 00030 perror("PsnPthreadSemaphore : impossible d'initialiser le cond"); 00031 } 00032 } |
|
|
Destructor.
Definition at line 34 of file PsnPthreadSemaphore.cxx.
|
|
|
P decrement the sempaphore value and block the calling thread if this value is negative.
Implements PsnSemaphore. Definition at line 58 of file PsnPthreadSemaphore.cxx. References _cond, _mutex, and _v.
00058 {
00059 int retval,ret;
00060 ret=pthread_mutex_lock(&_mutex);
00061 if(ret) {
00062 perror("PsnPthreadSemaphore : P a echoue au niveau du mutex lock");
00063 }
00064 _v--;
00065 while(_v<0) {
00066 ret=pthread_cond_wait(&_cond,&_mutex);
00067 if(ret) {
00068 perror("PsnPthreadSemaphore : P a echoue au niveau du cond");
00069 }
00070 }
00071 retval=_v;
00072 ret=pthread_mutex_unlock(&_mutex);
00073 if(ret) {
00074 perror("PsnPthreadSemaphore : P a echoue au niveau du mutex unlock");
00075 }
00076 return (retval);
00077 }
|
|
|
V Increments the semphore value and signals the change to blocked threads.
Implements PsnSemaphore. Definition at line 39 of file PsnPthreadSemaphore.cxx. References _cond, _mutex, and _v.
00039 {
00040 int retval,ret;
00041 ret=pthread_mutex_lock(&_mutex);
00042 if(ret) {
00043 perror("PsnPthreadSemaphore : V a echoue au niveau du mutex lock");
00044 }
00045 _v++;
00046 retval=_v;
00047 ret=pthread_mutex_unlock(&_mutex);
00048 if(ret) {
00049 perror("PsnPthreadSemaphore : V a echoue au niveau du mutex unlock");
00050 }
00051 ret=pthread_cond_signal(&_cond);
00052 if(ret) {
00053 perror("PsnPthreadSemaphore : V a echoue au niveau du cond");
00054 }
00055 return(retval);
00056 }
|
|
|
Definition at line 57 of file PsnPthreadSemaphore.h. Referenced by P(), PsnPthreadSemaphore(), V(), and ~PsnPthreadSemaphore(). |
|
|
Definition at line 58 of file PsnPthreadSemaphore.h. Referenced by P(), PsnPthreadSemaphore(), V(), and ~PsnPthreadSemaphore(). |
|
|
Definition at line 59 of file PsnPthreadSemaphore.h. Referenced by P(), PsnPthreadSemaphore(), and V(). |
| Documentation generated on Mon Nov 25 15:26:20 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |