00001 #ifndef SEMAPHORE_CLASS 00002 #define SEMAPHORE_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : semaphore * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 1998-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "mechanisms_dll.h" 00019 00020 #include <basis/object_base.h> 00021 00023 00030 class MECHANISMS_CLASS_STYLE semaphore : public synchronizer_base 00031 { 00032 public: 00033 semaphore(int concurrent_locks, int initial_locks_available); 00035 00043 virtual ~semaphore(); 00045 00046 IMPLEMENT_CLASS_NAME("semaphore"); 00047 00048 void wait(); 00050 00055 void signal(); 00057 00060 // synonyms for wait and signal from the dawn of operating systems. 00061 inline void P() { wait(); } 00063 inline void V() { signal(); } 00064 // synonym for signal(); V stands for "verhogen", meaning to increment. 00065 00066 // these implement the synchronizer_base virtual methods. 00067 virtual void establish_lock(); 00068 virtual void repeal_lock(); 00069 00070 private: 00071 int _max_users; 00072 int _locks_available; 00073 mutex *_wait_guard; 00074 mutex *_signal_guard; 00075 int _current_state; 00077 }; 00078 00079 #endif 00080
1.5.1