00001 /* --------------------------------------------------------------------------- 00002 Phission : 00003 Realtime Vision Processing System 00004 00005 Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu) 00006 University of Massachusetts at Lowell, 00007 Laboratory for Artificial Intelligence and Robotics 00008 00009 This file is part of Phission. 00010 00011 Phission is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU Lesser General Public License as published by 00013 the Free Software Foundation; either version 2 of the License, or 00014 (at your option) any later version. 00015 00016 Phission is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public License 00022 along with Phission; if not, write to the Free Software 00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 00025 ---------------------------------------------------------------------------*/ 00026 #ifndef _PHSEMAPHORE_H 00027 #define _PHSEMAPHORE_H 00028 00029 #include <phStandard.h> 00030 #include <phStdint.h> 00031 #include <phMutex.h> 00032 00038 /* ------------------------------------------------------------------------- */ 00043 #define phSemaphoreNOFLAG (0) 00044 00049 #define phSemaphoreNOWAIT (1<<0) 00050 00055 #define phSemaphoreWAIT (1<<1) /* default */ 00056 00058 #define phSemNOFLAG phSemaphoreNOFLAG 00059 00060 #define phSemNOWAIT phSemaphoreNOWAIT 00061 00062 #define phSemWAIT phSemaphoreWAIT 00063 00069 #define phSemaphoreNOTAKE 1 00070 00074 #define phSemaphoreTAKEN phSUCCESS 00075 00076 /* If on windows, this is likely not to be defined */ 00077 #ifndef SEM_VALUE_MAX 00078 00082 #define SEM_VALUE_MAX 2147483647 00083 #endif 00084 00091 #define phSemVALUEMAX SEM_VALUE_MAX 00092 00093 /* ------------------------------------------------------------------------- */ 00099 typedef struct ph_semaphore_info_t *ph_semaphore_info; 00100 00101 /* ------------------------------------------------------------------------- */ 00118 PHAPI(class) phSemaphore : protected phMutex 00119 { 00120 private: 00126 ph_semaphore_info m_info; 00127 00131 uint32_t m_count; 00139 uint32_t m_waiting; 00145 uint32_t m_max; 00146 00147 public: 00155 phSemaphore( uint32_t value = 0, uint32_t max = phSemVALUEMAX ); 00156 ~phSemaphore(); 00157 00161 int copy( phObject *copyto_obj ); 00165 int swap( phObject *obj ); 00166 00184 int post ( uint32_t value = 1 ); 00205 int postToWaiting ( uint32_t minimum = 1 ); 00215 int postMax (); 00216 00231 int take ( uint32_t flag = phSemaphoreWAIT ); 00236 int tryTake (); /* returns 1 if no semaphore */ 00237 00245 uint32_t getValue (); 00252 uint32_t getWaitingCount(); 00260 uint32_t getMax (); 00261 }; 00262 /* end \addtogroup ThreadSync */ 00264 00265 #endif /* _PHSEMAPHORE_H */
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |