semaphor.h
Go to the documentation of this file.
/*
* semaphor.h
*
* Thread synchronisation semaphore class.
*
* Portable Tools 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_SEMAPHORE_H
#define PTLIB_SEMAPHORE_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptlib/psync.h>
#include <limits.h>
#include <ptlib/critsec.h>
class PSemaphore : public PSync
{
PCLASSINFO(PSemaphore, PSync);
public:
PSemaphore(
unsigned initial,
unsigned maximum
);
PSemaphore(const PSemaphore &);
~PSemaphore();
virtual void Wait();
virtual PBoolean Wait(
const PTimeInterval & timeout // Amount of time to wait for semaphore.
);
virtual void Signal();
virtual PBoolean WillBlock() const;
private:
PSemaphore & operator=(const PSemaphore &) { return *this; }
// Include platform dependent part of class
#ifdef _WIN32
#include "msos/ptlib/semaphor.h"
#else
#include "unix/ptlib/semaphor.h"
#endif
};
#endif // PTLIB_SEMAPHORE_H
// End Of File ///////////////////////////////////////////////////////////////
PSemaphore
This class defines a thread synchronisation object.
Definition: semaphor.h:78
PTimeInterval
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
PSync
Definition: psync.h:45
PSemaphore::Signal
virtual void Signal()
If there are waiting (blocked) threads then unblock the first one that was blocked.
PBoolean
BOOL PBoolean
Definition: object.h:102
PSemaphore::Wait
virtual void Wait()
If the semaphore count is > 0, decrement the semaphore and return.
PSemaphore::~PSemaphore
~PSemaphore()
Destroy the semaphore.
PSemaphore::PSemaphore
PSemaphore(unsigned initial, unsigned maximum)
Create a new semaphore with maximum count and initial value specified.
psync.h
PSemaphore::WillBlock
virtual PBoolean WillBlock() const
Determine if the semaphore would block if the Wait() function were called.
critsec.h