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: 27923 $
00031  * $Author: rjongbloed $
00032  * $Date: 2012-06-27 22:28:36 -0500 (Wed, 27 Jun 2012) $
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 
00060 class PSyncNULL : public PSync
00061 {
00062   public:
00063     virtual void Wait() { }
00064     virtual void Signal() { }
00065 };
00066 
00086 class PWaitAndSignal {
00087   public:
00092     inline PWaitAndSignal(
00093       const PSync & sem,   
00094       PBoolean wait = true    
00095     ) : sync((PSync &)sem)
00096     { if (wait) sync.Wait(); }
00097 
00102     ~PWaitAndSignal()
00103     { sync.Signal(); }
00104 
00105   protected:
00106     PSync & sync;
00107 };
00108 
00109 
00110 #endif // PTLIB_SYNC_H
00111 
00112 
00113 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Feb 15 20:58:31 2013 for PTLib by  doxygen 1.4.7