deskflow/src/lib/mt/Mutex.h

70 lines
1.6 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2012 - 2016 Synergy App Ltd
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
2012-06-10 16:50:54 +00:00
*/
#pragma once
2012-06-10 16:50:54 +00:00
#include "arch/IArchMultithread.h"
2012-06-10 16:50:54 +00:00
//! 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.
*/
class Mutex
{
2012-06-10 16:50:54 +00:00
public:
Mutex();
//! Equivalent to default c'tor
/*!
Copy c'tor doesn't copy anything. It just makes it possible to
copy objects that contain a mutex.
*/
Mutex(const Mutex &);
~Mutex();
2012-06-10 16:50:54 +00:00
//! @name manipulators
//@{
2012-06-10 16:50:54 +00:00
//! Does nothing
/*!
This does nothing. It just makes it possible to assign objects
that contain a mutex.
*/
Mutex &operator=(const Mutex &);
2012-06-10 16:50:54 +00:00
//@}
//! @name accessors
//@{
2012-06-10 16:50:54 +00: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.
2012-06-10 16:50:54 +00:00
(cancellation point)
*/
void lock() const;
2012-06-10 16:50:54 +00:00
//! Unlock the mutex
/*!
Unlocks the mutex, which must have been previously locked by the
calling thread.
*/
void unlock() const;
2012-06-10 16:50:54 +00:00
//@}
2012-06-10 16:50:54 +00:00
private:
friend class CondVarBase;
ArchMutex m_mutex;
2012-06-10 16:50:54 +00:00
};