# mutex.h

Go to the documentation of this file.

    00001 /*
    00002  * mutex.h
    00003  *
    00004  * Mutual exclusion thread synchonisation class.
    00005  *
    00006  * Portable Windows Library
    00007  *
    00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
    00009  *
    00010  * The contents of this file are subject to the Mozilla Public License
    00011  * Version 1.0 (the "License"); you may not use this file except in
    00012  * compliance with the License. You may obtain a copy of the License at
    00013  * http://www.mozilla.org/MPL/
    00014  *
    00015  * Software distributed under the License is distributed on an "AS IS"
    00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
    00017  * the License for the specific language governing rights and limitations
    00018  * under the License.
    00019  *
    00020  * The Original Code is Portable Windows Library.
    00021  *
    00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
    00023  *
    00024  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
    00025  * All Rights Reserved.
    00026  *
    00027  * Contributor(s): ______________________________________.
    00028  *
    00029  * $Revision: 24177 $
    00030  * $Author: rjongbloed $
    00031  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
    00032  */
    00033
    00034 #ifndef PTLIB_MUTEX_H
    00035 #define PTLIB_MUTEX_H
    00036
    00037 #ifdef P_USE_PRAGMA
    00038 #pragma interface
    00039 #endif
    00040
    00041 #include <ptlib/critsec.h>
    00042 #include <ptlib/semaphor.h>
    00043
    00065 /*
    00066  * On Windows, It is convenient for PTimedMutex to be an ancestor of PSemaphore
    00067  * But that is the only platform where it is - every other platform (i.e. Unix)
    00068  * uses different constructs for these objects, so there is no need for a PTimedMute
    00069  * to carry around all of the PSemaphore members
    00070  */
    00071
    00072 #ifdef _WIN32
    00073 class PTimedMutex : public PSemaphore
    00074 {
    00075   PCLASSINFO(PTimedMutex, PSemaphore);
    00076 #else
    00077 class PTimedMutex : public PSync
    00078 {
    00079   PCLASSINFO(PTimedMutex, PSync)
    00080 #endif
    00081
    00082   public:
    00083     /* Create a new mutex.
    00084        Initially the mutex will not be "set", so the first call to Wait() will
    00085        never wait.
    00086      */
    00087     PTimedMutex();
    00088     PTimedMutex(const PTimedMutex & mutex);
    00089
    00093     PINLINE bool Try() { return Wait(0); }
    00094
    00095 // Include platform dependent part of class
    00096 #ifdef _WIN32
    00097 #include "msos/ptlib/mutex.h"
    00098 #else
    00099 #include "unix/ptlib/mutex.h"
    00100 #endif
    00101 };
    00102
    00103 // On Windows, critical sections are recursive and so we can use them for mutexes
    00104 // The only Posix mutex that is recursive is pthread_mutex, so we have to use that
    00105 #ifdef _WIN32
    00106
    00109 typedef PCriticalSection PMutex;
    00110 #else
    00111
    00114 typedef PTimedMutex PMutex;
    00115 #define PCriticalSection PTimedMutex
    00116 #endif
    00117
    00118
    00119 #endif // PTLIB_MUTEX_H
    00120
    00121
    00122 // End Of File ///////////////////////////////////////////////////////////////