psync.h

Go to the documentation of this file.
00001 /*
00002  * psync.h
00003  *
00004  * Abstract synchronisation semaphore class.
00005  *
00006  * Portable Tools Library
00007  *
00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
00009  * Copyright (c) 2005 Post Increment
00010  *
00011  * The contents of this file are subject to the Mozilla Public License
00012  * Version 1.0 (the "License"); you may not use this file except in
00013  * compliance with the License. You may obtain a copy of the License at
00014  * http://www.mozilla.org/MPL/
00015  *
00016  * Software distributed under the License is distributed on an "AS IS"
00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00018  * the License for the specific language governing rights and limitations
00019  * under the License.
00020  *
00021  * The Original Code is Portable Windows Library.
00022  *
00023  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00024  *
00025  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
00026  * All Rights Reserved.
00027  *
00028  * Contributor(s): ______________________________________.
00029  *
00030  * $Revision: 20986 $
00031  * $Author: rjongbloed $
00032  * $Date: 2008-09-15 12:01:50 +0000 (Mon, 15 Sep 2008) $
00033  */
00034 
00035 #ifndef _PSYNC
00036 #define _PSYNC
00037 
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041 
00042 #include <ptlib/contain.h>
00043 
00044 class PSync : public PObject
00045 {
00046   public:
00051     virtual void Wait() = 0;
00052 
00055     virtual void Signal() = 0;
00057 
00058 #ifdef P_PTHREADS
00059     PSync()
00060       : lockerId(pthread_t(-1)) { }
00061   protected:
00062     pthread_t lockerId;
00063 #endif
00064 };
00065 
00066 class PSyncNULL : public PSync
00067 {
00068   public:
00069     virtual void Wait() { }
00070     virtual void Signal() { }
00071 };
00072 
00092 class PWaitAndSignal {
00093   public:
00098     inline PWaitAndSignal(
00099       const PSync & sem,   
00100       PBoolean wait = PTrue    
00101     ) : sync((PSync &)sem)
00102     { if (wait) sync.Wait(); }
00103 
00108     ~PWaitAndSignal()
00109     { sync.Signal(); }
00110 
00111   protected:
00112     PSync & sync;
00113 };
00114 
00115 #endif // _PSYNC
00116 

Generated on Mon Feb 23 01:57:54 2009 for PTLib by  doxygen 1.5.1