Remove no longer used mutex implementation
This commit is contained in:
parent
734588827f
commit
b376b3ae68
|
@ -123,23 +123,3 @@ private:
|
||||||
static Arch* s_instance;
|
static Arch* s_instance;
|
||||||
ARCH_INTERNET m_internet;
|
ARCH_INTERNET m_internet;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Convenience object to lock/unlock an arch mutex
|
|
||||||
class ArchMutexLock {
|
|
||||||
public:
|
|
||||||
ArchMutexLock(ArchMutex mutex) : lock{*mutex} {}
|
|
||||||
ArchMutexLock(ArchMutex mutex, std::adopt_lock_t) :
|
|
||||||
lock{*mutex, std::adopt_lock}, adopted_{true}
|
|
||||||
{}
|
|
||||||
|
|
||||||
~ArchMutexLock()
|
|
||||||
{
|
|
||||||
if (adopted_) {
|
|
||||||
lock.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock;
|
|
||||||
private:
|
|
||||||
bool adopted_ = false;
|
|
||||||
};
|
|
||||||
|
|
|
@ -17,13 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "IArchMultithread.h"
|
#include "IArchMultithread.h"
|
||||||
#include "arch/Arch.h"
|
|
||||||
|
|
||||||
bool IArchMultithread::waitCondVar(ArchCond cond, ArchMutexLock& lock,
|
|
||||||
double timeout)
|
|
||||||
{
|
|
||||||
return wait_cond_var(*cond, lock.lock, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IArchMultithread::wait_cond_var(std::condition_variable& cv,
|
bool IArchMultithread::wait_cond_var(std::condition_variable& cv,
|
||||||
std::unique_lock<std::mutex>& lock, double timeout)
|
std::unique_lock<std::mutex>& lock, double timeout)
|
||||||
|
|
|
@ -23,16 +23,12 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
|
||||||
using ArchCond = std::condition_variable*;
|
|
||||||
using ArchMutex = std::mutex*;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class ArchThreadImpl
|
\class ArchThreadImpl
|
||||||
\brief Internal thread data.
|
\brief Internal thread data.
|
||||||
An architecture dependent type holding the necessary data for a thread.
|
An architecture dependent type holding the necessary data for a thread.
|
||||||
*/
|
*/
|
||||||
class ArchThreadImpl;
|
class ArchThreadImpl;
|
||||||
class ArchMutexLock;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\var ArchThread
|
\var ArchThread
|
||||||
|
@ -79,24 +75,6 @@ public:
|
||||||
// condition variable methods
|
// condition variable methods
|
||||||
//
|
//
|
||||||
|
|
||||||
//! Create a condition variable
|
|
||||||
ArchCond newCondVar() { return new std::condition_variable; }
|
|
||||||
|
|
||||||
//! Destroy a condition variable
|
|
||||||
void closeCondVar(ArchCond cv) { delete cv; }
|
|
||||||
|
|
||||||
//! Signal a condition variable
|
|
||||||
/*!
|
|
||||||
Signalling a condition variable releases one waiting thread.
|
|
||||||
*/
|
|
||||||
void signalCondVar(ArchCond cv) { cv->notify_one(); }
|
|
||||||
|
|
||||||
//! Broadcast a condition variable
|
|
||||||
/*!
|
|
||||||
Broadcasting a condition variable releases all waiting threads.
|
|
||||||
*/
|
|
||||||
void broadcastCondVar(ArchCond cv) { cv->notify_all(); }
|
|
||||||
|
|
||||||
//! Wait on a condition variable
|
//! Wait on a condition variable
|
||||||
/*!
|
/*!
|
||||||
Wait on a conditation variable for up to \c timeout seconds.
|
Wait on a conditation variable for up to \c timeout seconds.
|
||||||
|
@ -108,34 +86,9 @@ public:
|
||||||
|
|
||||||
(Cancellation point)
|
(Cancellation point)
|
||||||
*/
|
*/
|
||||||
bool waitCondVar(ArchCond cv, ArchMutexLock& lock, double timeout);
|
|
||||||
|
|
||||||
bool wait_cond_var(std::condition_variable& cv, std::unique_lock<std::mutex>& lock,
|
bool wait_cond_var(std::condition_variable& cv, std::unique_lock<std::mutex>& lock,
|
||||||
double timeout);
|
double timeout);
|
||||||
|
|
||||||
//
|
|
||||||
// mutex methods
|
|
||||||
//
|
|
||||||
|
|
||||||
//! Create a recursive mutex
|
|
||||||
/*!
|
|
||||||
Creates mutex. A thread may lock a recursive mutex
|
|
||||||
when it already holds a lock on that mutex. The mutex is an
|
|
||||||
opaque data type.
|
|
||||||
|
|
||||||
WARNING: this is recursive mutex on Windows and some code likely depends on it.
|
|
||||||
*/
|
|
||||||
ArchMutex newMutex() { return new std::mutex; }
|
|
||||||
|
|
||||||
//! Destroy a mutex
|
|
||||||
void closeMutex(ArchMutex mutex) { delete mutex; }
|
|
||||||
|
|
||||||
//! Lock a mutex
|
|
||||||
void lockMutex(ArchMutex mutex) { mutex->lock(); }
|
|
||||||
|
|
||||||
//! Unlock a mutex
|
|
||||||
void unlockMutex(ArchMutex mutex) { mutex->unlock(); }
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// thread methods
|
// thread methods
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include "barrier/ClientTaskBarReceiver.h"
|
#include "barrier/ClientTaskBarReceiver.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
#include "mt/Lock.h"
|
|
||||||
#include "base/String.h"
|
#include "base/String.h"
|
||||||
#include "base/IEventQueue.h"
|
#include "base/IEventQueue.h"
|
||||||
#include "arch/Arch.h"
|
#include "arch/Arch.h"
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "barrier/PortableTaskBarReceiver.h"
|
#include "barrier/PortableTaskBarReceiver.h"
|
||||||
#include "mt/Lock.h"
|
|
||||||
#include "base/String.h"
|
#include "base/String.h"
|
||||||
#include "base/IEventQueue.h"
|
#include "base/IEventQueue.h"
|
||||||
#include "arch/Arch.h"
|
#include "arch/Arch.h"
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include "barrier/ServerTaskBarReceiver.h"
|
#include "barrier/ServerTaskBarReceiver.h"
|
||||||
#include "server/Server.h"
|
#include "server/Server.h"
|
||||||
#include "mt/Lock.h"
|
|
||||||
#include "base/String.h"
|
#include "base/String.h"
|
||||||
#include "base/IEventQueue.h"
|
#include "base/IEventQueue.h"
|
||||||
#include "arch/Arch.h"
|
#include "arch/Arch.h"
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "mt/CondVar.h"
|
|
||||||
#include "arch/IArchMultithread.h"
|
#include "arch/IArchMultithread.h"
|
||||||
#include "base/IEventQueue.h"
|
#include "base/IEventQueue.h"
|
||||||
#include "base/Event.h"
|
#include "base/Event.h"
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "barrier/ClientArgs.h"
|
#include "barrier/ClientArgs.h"
|
||||||
#include "net/NetworkAddress.h"
|
#include "net/NetworkAddress.h"
|
||||||
#include "base/EventTypes.h"
|
#include "base/EventTypes.h"
|
||||||
#include "mt/CondVar.h"
|
|
||||||
|
|
||||||
class EventQueueTimer;
|
class EventQueueTimer;
|
||||||
namespace barrier { class Screen; }
|
namespace barrier { class Screen; }
|
||||||
|
|
|
@ -1,92 +0,0 @@
|
||||||
/*
|
|
||||||
* barrier -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2012-2016 Symless Ltd.
|
|
||||||
* 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 LICENSE 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.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mt/CondVar.h"
|
|
||||||
#include "arch/Arch.h"
|
|
||||||
#include "base/Stopwatch.h"
|
|
||||||
|
|
||||||
//
|
|
||||||
// CondVarBase
|
|
||||||
//
|
|
||||||
|
|
||||||
CondVarBase::CondVarBase(Mutex* mutex) :
|
|
||||||
m_mutex(mutex)
|
|
||||||
{
|
|
||||||
assert(m_mutex != NULL);
|
|
||||||
m_cond = ARCH->newCondVar();
|
|
||||||
}
|
|
||||||
|
|
||||||
CondVarBase::~CondVarBase()
|
|
||||||
{
|
|
||||||
ARCH->closeCondVar(m_cond);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
CondVarBase::lock() const
|
|
||||||
{
|
|
||||||
m_mutex->lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
CondVarBase::unlock() const
|
|
||||||
{
|
|
||||||
m_mutex->unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
CondVarBase::signal()
|
|
||||||
{
|
|
||||||
ARCH->signalCondVar(m_cond);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
CondVarBase::broadcast()
|
|
||||||
{
|
|
||||||
ARCH->broadcastCondVar(m_cond);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
CondVarBase::wait(Stopwatch& timer, double timeout) const
|
|
||||||
{
|
|
||||||
double remain = timeout-timer.getTime();
|
|
||||||
// Some ARCH wait()s return prematurely, retry until really timed out
|
|
||||||
// In particular, ArchMultithreadPosix::waitCondVar() returns every 100ms
|
|
||||||
do {
|
|
||||||
// Always call wait at least once, even if remain is 0, to give
|
|
||||||
// other thread a chance to grab the mutex to avoid deadlocks on
|
|
||||||
// busy waiting.
|
|
||||||
if (remain<0.0) remain=0.0;
|
|
||||||
if (wait(remain))
|
|
||||||
return true;
|
|
||||||
remain = timeout - timer.getTime();
|
|
||||||
} while (remain >= 0.0);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
CondVarBase::wait(double timeout) const
|
|
||||||
{
|
|
||||||
ArchMutexLock lock{m_mutex->m_mutex, std::adopt_lock};
|
|
||||||
return ARCH->waitCondVar(m_cond, lock, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
Mutex*
|
|
||||||
CondVarBase::getMutex() const
|
|
||||||
{
|
|
||||||
return m_mutex;
|
|
||||||
}
|
|
|
@ -1,225 +0,0 @@
|
||||||
/*
|
|
||||||
* barrier -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2012-2016 Symless Ltd.
|
|
||||||
* 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 LICENSE 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.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "mt/Mutex.h"
|
|
||||||
#include "common/basic_types.h"
|
|
||||||
|
|
||||||
class Stopwatch;
|
|
||||||
|
|
||||||
//! Generic condition variable
|
|
||||||
/*!
|
|
||||||
This class provides functionality common to all condition variables
|
|
||||||
but doesn't provide the actual variable storage. A condition variable
|
|
||||||
is a multiprocessing primitive that can be waited on. Every condition
|
|
||||||
variable has an associated mutex.
|
|
||||||
*/
|
|
||||||
class CondVarBase {
|
|
||||||
public:
|
|
||||||
/*!
|
|
||||||
\c mutex must not be NULL. All condition variables have an
|
|
||||||
associated mutex. The mutex needn't be unique to one condition
|
|
||||||
variable.
|
|
||||||
*/
|
|
||||||
CondVarBase(Mutex* mutex);
|
|
||||||
~CondVarBase();
|
|
||||||
|
|
||||||
//! @name manipulators
|
|
||||||
//@{
|
|
||||||
|
|
||||||
//! Lock the condition variable's mutex
|
|
||||||
/*!
|
|
||||||
Lock the condition variable's mutex. The condition variable should
|
|
||||||
be locked before reading or writing it. It must be locked for a
|
|
||||||
call to wait(). Locks are not recursive; locking a locked mutex
|
|
||||||
will deadlock the thread.
|
|
||||||
*/
|
|
||||||
void lock() const;
|
|
||||||
|
|
||||||
//! Unlock the condition variable's mutex
|
|
||||||
void unlock() const;
|
|
||||||
|
|
||||||
//! Signal the condition variable
|
|
||||||
/*!
|
|
||||||
Wake up one waiting thread, if there are any. Which thread gets
|
|
||||||
woken is undefined.
|
|
||||||
*/
|
|
||||||
void signal();
|
|
||||||
|
|
||||||
//! Signal the condition variable
|
|
||||||
/*!
|
|
||||||
Wake up all waiting threads, if any.
|
|
||||||
*/
|
|
||||||
void broadcast();
|
|
||||||
|
|
||||||
//@}
|
|
||||||
//! @name accessors
|
|
||||||
//@{
|
|
||||||
|
|
||||||
//! Wait on the condition variable
|
|
||||||
/*!
|
|
||||||
Wait on the condition variable. If \c timeout < 0 then wait until
|
|
||||||
signalled, otherwise up to \c timeout seconds or until signalled,
|
|
||||||
whichever comes first. Returns true if the object was signalled
|
|
||||||
during the wait, false otherwise.
|
|
||||||
|
|
||||||
The proper way to wait for a condition is:
|
|
||||||
\code
|
|
||||||
cv.lock();
|
|
||||||
while (cv-expr) {
|
|
||||||
cv.wait();
|
|
||||||
}
|
|
||||||
cv.unlock();
|
|
||||||
\endcode
|
|
||||||
where \c cv-expr involves the value of \c cv and is false when the
|
|
||||||
condition is satisfied.
|
|
||||||
|
|
||||||
(cancellation point)
|
|
||||||
*/
|
|
||||||
bool wait(double timeout = -1.0) const;
|
|
||||||
|
|
||||||
//! Wait on the condition variable
|
|
||||||
/*!
|
|
||||||
Same as \c wait(double) but use \c timer to compare against \c timeout.
|
|
||||||
Since clients normally wait on condition variables in a loop, clients
|
|
||||||
can use this to avoid recalculating \c timeout on each iteration.
|
|
||||||
Passing a stopwatch with a negative \c timeout is pointless (it will
|
|
||||||
never time out) but permitted.
|
|
||||||
|
|
||||||
(cancellation point)
|
|
||||||
*/
|
|
||||||
bool wait(Stopwatch& timer, double timeout) const;
|
|
||||||
|
|
||||||
//! Get the mutex
|
|
||||||
/*!
|
|
||||||
Get the mutex passed to the c'tor.
|
|
||||||
*/
|
|
||||||
Mutex* getMutex() const;
|
|
||||||
|
|
||||||
//@}
|
|
||||||
|
|
||||||
private:
|
|
||||||
// not implemented
|
|
||||||
CondVarBase(const CondVarBase&);
|
|
||||||
CondVarBase& operator=(const CondVarBase&);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Mutex* m_mutex;
|
|
||||||
ArchCond m_cond;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Condition variable
|
|
||||||
/*!
|
|
||||||
A condition variable with storage for type \c T.
|
|
||||||
*/
|
|
||||||
template <class T>
|
|
||||||
class CondVar : public CondVarBase {
|
|
||||||
public:
|
|
||||||
//! Initialize using \c value
|
|
||||||
CondVar(Mutex* mutex, const T& value);
|
|
||||||
//! Initialize using another condition variable's value
|
|
||||||
CondVar(const CondVar&);
|
|
||||||
~CondVar();
|
|
||||||
|
|
||||||
//! @name manipulators
|
|
||||||
//@{
|
|
||||||
|
|
||||||
//! Assigns the value of \c cv to this
|
|
||||||
/*!
|
|
||||||
Set the variable's value. The condition variable should be locked
|
|
||||||
before calling this method.
|
|
||||||
*/
|
|
||||||
CondVar& operator=(const CondVar& cv);
|
|
||||||
|
|
||||||
//! Assigns \c value to this
|
|
||||||
/*!
|
|
||||||
Set the variable's value. The condition variable should be locked
|
|
||||||
before calling this method.
|
|
||||||
*/
|
|
||||||
CondVar& operator=(const T& v);
|
|
||||||
|
|
||||||
//@}
|
|
||||||
//! @name accessors
|
|
||||||
//@{
|
|
||||||
|
|
||||||
//! Get the variable's value
|
|
||||||
/*!
|
|
||||||
Get the variable's value. The condition variable should be locked
|
|
||||||
before calling this method.
|
|
||||||
*/
|
|
||||||
operator const volatile T&() const;
|
|
||||||
|
|
||||||
//@}
|
|
||||||
|
|
||||||
private:
|
|
||||||
volatile T m_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline
|
|
||||||
CondVar<T>::CondVar(
|
|
||||||
Mutex* mutex,
|
|
||||||
const T& data) :
|
|
||||||
CondVarBase(mutex),
|
|
||||||
m_data(data)
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline
|
|
||||||
CondVar<T>::CondVar(
|
|
||||||
const CondVar& cv) :
|
|
||||||
CondVarBase(cv.getMutex()),
|
|
||||||
m_data(cv.m_data)
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline
|
|
||||||
CondVar<T>::~CondVar()
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline
|
|
||||||
CondVar<T>&
|
|
||||||
CondVar<T>::operator=(const CondVar<T>& cv)
|
|
||||||
{
|
|
||||||
m_data = cv.m_data;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline
|
|
||||||
CondVar<T>&
|
|
||||||
CondVar<T>::operator=(const T& data)
|
|
||||||
{
|
|
||||||
m_data = data;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline
|
|
||||||
CondVar<T>::operator const volatile T&() const
|
|
||||||
{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* barrier -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2012-2016 Symless Ltd.
|
|
||||||
* 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 LICENSE 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.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mt/Lock.h"
|
|
||||||
#include "mt/CondVar.h"
|
|
||||||
#include "mt/Mutex.h"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Lock
|
|
||||||
//
|
|
||||||
|
|
||||||
Lock::Lock(const Mutex* mutex) :
|
|
||||||
m_mutex(mutex)
|
|
||||||
{
|
|
||||||
m_mutex->lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
Lock::Lock(const CondVarBase* cv) :
|
|
||||||
m_mutex(cv->getMutex())
|
|
||||||
{
|
|
||||||
m_mutex->lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
Lock::~Lock()
|
|
||||||
{
|
|
||||||
m_mutex->unlock();
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
/*
|
|
||||||
* barrier -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2012-2016 Symless Ltd.
|
|
||||||
* 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 LICENSE 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.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "common/common.h"
|
|
||||||
|
|
||||||
class Mutex;
|
|
||||||
class CondVarBase;
|
|
||||||
|
|
||||||
//! Mutual exclusion lock utility
|
|
||||||
/*!
|
|
||||||
This class locks a mutex or condition variable in the c'tor and unlocks
|
|
||||||
it in the d'tor. It's easier and safer than manually locking and
|
|
||||||
unlocking since unlocking must usually be done no matter how a function
|
|
||||||
exits (including by unwinding due to an exception).
|
|
||||||
*/
|
|
||||||
class Lock {
|
|
||||||
public:
|
|
||||||
//! Lock the mutex \c mutex
|
|
||||||
Lock(const Mutex* mutex);
|
|
||||||
//! Lock the condition variable \c cv
|
|
||||||
Lock(const CondVarBase* cv);
|
|
||||||
//! Unlock the mutex or condition variable
|
|
||||||
~Lock();
|
|
||||||
|
|
||||||
private:
|
|
||||||
// not implemented
|
|
||||||
Lock(const Lock&);
|
|
||||||
Lock& operator=(const Lock&);
|
|
||||||
|
|
||||||
private:
|
|
||||||
const Mutex* m_mutex;
|
|
||||||
};
|
|
|
@ -1,58 +0,0 @@
|
||||||
/*
|
|
||||||
* barrier -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2012-2016 Symless Ltd.
|
|
||||||
* 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 LICENSE 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.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mt/Mutex.h"
|
|
||||||
|
|
||||||
#include "arch/Arch.h"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Mutex
|
|
||||||
//
|
|
||||||
|
|
||||||
Mutex::Mutex()
|
|
||||||
{
|
|
||||||
m_mutex = ARCH->newMutex();
|
|
||||||
}
|
|
||||||
|
|
||||||
Mutex::Mutex(const Mutex&)
|
|
||||||
{
|
|
||||||
m_mutex = ARCH->newMutex();
|
|
||||||
}
|
|
||||||
|
|
||||||
Mutex::~Mutex()
|
|
||||||
{
|
|
||||||
ARCH->closeMutex(m_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
Mutex&
|
|
||||||
Mutex::operator=(const Mutex&)
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Mutex::lock() const
|
|
||||||
{
|
|
||||||
ARCH->lockMutex(m_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Mutex::unlock() const
|
|
||||||
{
|
|
||||||
ARCH->unlockMutex(m_mutex);
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
/*
|
|
||||||
* barrier -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2012-2016 Symless Ltd.
|
|
||||||
* 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 LICENSE 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.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "arch/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.
|
|
||||||
*/
|
|
||||||
class Mutex {
|
|
||||||
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();
|
|
||||||
|
|
||||||
//! @name manipulators
|
|
||||||
//@{
|
|
||||||
|
|
||||||
//! Does nothing
|
|
||||||
/*!
|
|
||||||
This does nothing. It just makes it possible to assign objects
|
|
||||||
that contain a mutex.
|
|
||||||
*/
|
|
||||||
Mutex& operator=(const Mutex&);
|
|
||||||
|
|
||||||
//@}
|
|
||||||
//! @name accessors
|
|
||||||
//@{
|
|
||||||
|
|
||||||
//! 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;
|
|
||||||
|
|
||||||
//@}
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class CondVarBase;
|
|
||||||
ArchMutex m_mutex;
|
|
||||||
};
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include "net/SocketMultiplexer.h"
|
#include "net/SocketMultiplexer.h"
|
||||||
|
|
||||||
#include "net/ISocketMultiplexerJob.h"
|
#include "net/ISocketMultiplexerJob.h"
|
||||||
#include "mt/CondVar.h"
|
|
||||||
#include "mt/Thread.h"
|
#include "mt/Thread.h"
|
||||||
#include "arch/Arch.h"
|
#include "arch/Arch.h"
|
||||||
#include "arch/XArch.h"
|
#include "arch/XArch.h"
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "net/IDataSocket.h"
|
#include "net/IDataSocket.h"
|
||||||
#include "net/ISocketMultiplexerJob.h"
|
#include "net/ISocketMultiplexerJob.h"
|
||||||
#include "io/StreamBuffer.h"
|
#include "io/StreamBuffer.h"
|
||||||
#include "mt/CondVar.h"
|
|
||||||
#include "arch/IArchNetwork.h"
|
#include "arch/IArchNetwork.h"
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "barrier/PlatformScreen.h"
|
#include "barrier/PlatformScreen.h"
|
||||||
#include "barrier/DragInformation.h"
|
#include "barrier/DragInformation.h"
|
||||||
#include "platform/synwinhk.h"
|
#include "platform/synwinhk.h"
|
||||||
#include "mt/CondVar.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include "barrier/Clipboard.h"
|
#include "barrier/Clipboard.h"
|
||||||
#include "barrier/KeyMap.h"
|
#include "barrier/KeyMap.h"
|
||||||
#include "barrier/ClientApp.h"
|
#include "barrier/ClientApp.h"
|
||||||
#include "mt/CondVar.h"
|
|
||||||
#include "mt/Thread.h"
|
#include "mt/Thread.h"
|
||||||
#include "arch/XArch.h"
|
#include "arch/XArch.h"
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
|
|
Loading…
Reference in New Issue