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: 22375 $
00031  * $Author: rjongbloed $
00032  * $Date: 2009-04-06 21:47:23 -0500 (Mon, 06 Apr 2009) $
00033  */
00034 
00035 #ifndef PTLIB_SYNC_H
00036 #define PTLIB_SYNC_H
00037 
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041 
00042 #include <ptlib/contain.h>
00043 #include <ptlib/object.h>
00044 
00045 class PSync : public PObject
00046 {
00047   public:
00052     virtual void Wait() = 0;
00053 
00056     virtual void Signal() = 0;
00058 
00059 #ifdef P_PTHREADS
00060     PSync()
00061       : lockerId(pthread_t(-1)) { }
00062   protected:
00063     pthread_t lockerId;
00064 #endif
00065 };
00066 
00067 class PSyncNULL : public PSync
00068 {
00069   public:
00070     virtual void Wait() { }
00071     virtual void Signal() { }
00072 };
00073 
00093 class PWaitAndSignal {
00094   public:
00099     inline PWaitAndSignal(
00100       const PSync & sem,   
00101       PBoolean wait = PTrue    
00102     ) : sync((PSync &)sem)
00103     { if (wait) sync.Wait(); }
00104 
00109     ~PWaitAndSignal()
00110     { sync.Signal(); }
00111 
00112   protected:
00113     PSync & sync;
00114 };
00115 
00116 
00117 #endif // PTLIB_SYNC_H
00118 
00119 
00120 // End Of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:48 2010 for PTLib by  doxygen 1.4.7