00001 /* 00002 * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #include <PsnPthreadSemaphore.h> 00019 #include <stdio.h> 00020 00021 PsnPthreadSemaphore::PsnPthreadSemaphore(const int valeurInitiale) : 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 } 00033 00034 PsnPthreadSemaphore::~PsnPthreadSemaphore() { 00035 pthread_mutex_destroy(&_mutex); 00036 pthread_cond_destroy(&_cond); 00037 } 00038 00039 int PsnPthreadSemaphore::V() { 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 } 00057 00058 int PsnPthreadSemaphore::P() { 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 }
| Documentation generated on Mon Nov 25 15:25:01 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |