barrier/lib/mt/CMutex.h

79 lines
1.9 KiB
C
Raw Normal View History

2002-08-02 23:57:46 +04:00
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2002 Chris Schoeneman
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
2001-10-06 18:13:28 +04:00
#ifndef CMUTEX_H
#define CMUTEX_H
#include "IArchMultithread.h"
//! Mutual exclusion
/*!
A non-recursive mutual exclusion object. Only one thread at a time can
hold a lock on a mutex. Any thread that attempts to lock a locked mutex
will block until the mutex is unlocked. At that time, if any threads are
blocked, exactly one waiting thread will acquire the lock and continue
running. A thread may not lock a mutex it already owns the lock on; if
it tries it will deadlock itself.
*/
2001-10-06 18:13:28 +04:00
class CMutex {
2002-04-29 18:40:01 +04:00
public:
2001-10-06 18:13:28 +04:00
CMutex();
//! Equivalent to default c'tor
/*!
Copy c'tor doesn't copy anything. It just makes it possible to
copy objects that contain a mutex.
*/
2001-10-06 18:13:28 +04:00
CMutex(const CMutex&);
~CMutex();
//! @name manipulators
//@{
2001-10-06 18:13:28 +04:00
//! Does nothing
/*!
This does nothing. It just makes it possible to assign objects
that contain a mutex.
*/
2002-04-29 18:40:01 +04:00
CMutex& operator=(const CMutex&);
2001-10-06 18:13:28 +04:00
//@}
//! @name accessors
//@{
2001-10-06 18:13:28 +04:00
//! Lock the mutex
/*!
Locks the mutex, which must not have been previously locked by the
calling thread. This blocks if the mutex is already locked by another
thread.
(cancellation point)
*/
void lock() const;
//! Unlock the mutex
/*!
Unlocks the mutex, which must have been previously locked by the
calling thread.
*/
void unlock() const;
2001-10-06 18:13:28 +04:00
//@}
2002-04-29 18:40:01 +04:00
private:
2001-10-06 18:13:28 +04:00
friend class CCondVarBase;
CArchMutex m_mutex;
2001-10-06 18:13:28 +04:00
};
#endif