mutex.h
Go to the documentation of this file.
/*
* mutex.h
*
* Mutual exclusion thread synchonisation class.
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_MUTEX_H
#define PTLIB_MUTEX_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptlib/critsec.h>
#include <ptlib/semaphor.h>
/*
* On Windows, It is convenient for PTimedMutex to be an ancestor of PSemaphore
* But that is the only platform where it is - every other platform (i.e. Unix)
* uses different constructs for these objects, so there is no need for a PTimedMute
* to carry around all of the PSemaphore members
*/
#ifdef _WIN32
class PTimedMutex : public PSemaphore
{
PCLASSINFO(PTimedMutex, PSemaphore);
#else
class PTimedMutex : public PSync
{
PCLASSINFO(PTimedMutex, PSync)
#endif
public:
/* Create a new mutex.
Initially the mutex will not be "set", so the first call to Wait() will
never wait.
*/
PTimedMutex();
PTimedMutex(const PTimedMutex & mutex);
PINLINE bool Try() { return Wait(0); }
// Include platform dependent part of class
#ifdef _WIN32
#include "msos/ptlib/mutex.h"
#else
#include "unix/ptlib/mutex.h"
#endif
};
// On Windows, critical sections are recursive and so we can use them for mutexes
// The only Posix mutex that is recursive is pthread_mutex, so we have to use that
#ifdef _WIN32
typedef PCriticalSection PMutex;
#else
typedef PTimedMutex PMutex;
#define PCriticalSection PTimedMutex
#endif
#endif // PTLIB_MUTEX_H
// End Of File ///////////////////////////////////////////////////////////////
PSemaphore
This class defines a thread synchronisation object.
Definition: semaphor.h:78
PSync::Wait
virtual void Wait()=0
Block until the synchronisation object is available.
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
semaphor.h
PINLINE
#define PINLINE
Definition: object.h:127
PSync
Definition: psync.h:45
PTimedMutex::PTimedMutex
PTimedMutex()
PTimedMutex
This class defines a thread mutual exclusion object.
Definition: mutex.h:77
PCriticalSection
#define PCriticalSection
Definition: mutex.h:115
critsec.h
PTimedMutex::Try
PINLINE bool Try()
Try to enter the critical section for exlusive access.
Definition: mutex.h:93
PMutex
PTimedMutex PMutex
Definition: mutex.h:114