From b376b3ae6877974073d7e1ae514148ad0968f301 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Wed, 3 Nov 2021 02:58:43 +0200 Subject: [PATCH] Remove no longer used mutex implementation --- src/lib/arch/Arch.h | 20 -- src/lib/arch/IArchMultithread.cpp | 7 - src/lib/arch/IArchMultithread.h | 47 ---- src/lib/barrier/ClientTaskBarReceiver.cpp | 1 - src/lib/barrier/PortableTaskBarReceiver.cpp | 1 - src/lib/barrier/ServerTaskBarReceiver.cpp | 1 - src/lib/base/EventQueue.h | 1 - src/lib/client/Client.h | 1 - src/lib/mt/CondVar.cpp | 92 -------- src/lib/mt/CondVar.h | 225 -------------------- src/lib/mt/Lock.cpp | 42 ---- src/lib/mt/Lock.h | 49 ----- src/lib/mt/Mutex.cpp | 58 ----- src/lib/mt/Mutex.h | 79 ------- src/lib/net/SocketMultiplexer.cpp | 1 - src/lib/net/TCPSocket.h | 1 - src/lib/platform/MSWindowsScreen.h | 1 - src/lib/platform/OSXScreen.mm | 1 - 18 files changed, 628 deletions(-) delete mode 100644 src/lib/mt/CondVar.cpp delete mode 100644 src/lib/mt/CondVar.h delete mode 100644 src/lib/mt/Lock.cpp delete mode 100644 src/lib/mt/Lock.h delete mode 100644 src/lib/mt/Mutex.cpp delete mode 100644 src/lib/mt/Mutex.h diff --git a/src/lib/arch/Arch.h b/src/lib/arch/Arch.h index 17088ab6..614a1fcf 100644 --- a/src/lib/arch/Arch.h +++ b/src/lib/arch/Arch.h @@ -123,23 +123,3 @@ private: static Arch* s_instance; 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 lock; -private: - bool adopted_ = false; -}; diff --git a/src/lib/arch/IArchMultithread.cpp b/src/lib/arch/IArchMultithread.cpp index ba4dfe22..8bf661f0 100644 --- a/src/lib/arch/IArchMultithread.cpp +++ b/src/lib/arch/IArchMultithread.cpp @@ -17,13 +17,6 @@ */ #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, std::unique_lock& lock, double timeout) diff --git a/src/lib/arch/IArchMultithread.h b/src/lib/arch/IArchMultithread.h index 514d5fbe..d978d926 100644 --- a/src/lib/arch/IArchMultithread.h +++ b/src/lib/arch/IArchMultithread.h @@ -23,16 +23,12 @@ #include #include -using ArchCond = std::condition_variable*; -using ArchMutex = std::mutex*; - /*! \class ArchThreadImpl \brief Internal thread data. An architecture dependent type holding the necessary data for a thread. */ class ArchThreadImpl; -class ArchMutexLock; /*! \var ArchThread @@ -79,24 +75,6 @@ public: // 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 conditation variable for up to \c timeout seconds. @@ -108,34 +86,9 @@ public: (Cancellation point) */ - bool waitCondVar(ArchCond cv, ArchMutexLock& lock, double timeout); - bool wait_cond_var(std::condition_variable& cv, std::unique_lock& lock, 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 // diff --git a/src/lib/barrier/ClientTaskBarReceiver.cpp b/src/lib/barrier/ClientTaskBarReceiver.cpp index ea29f3d0..1fed61ca 100644 --- a/src/lib/barrier/ClientTaskBarReceiver.cpp +++ b/src/lib/barrier/ClientTaskBarReceiver.cpp @@ -18,7 +18,6 @@ #include "barrier/ClientTaskBarReceiver.h" #include "client/Client.h" -#include "mt/Lock.h" #include "base/String.h" #include "base/IEventQueue.h" #include "arch/Arch.h" diff --git a/src/lib/barrier/PortableTaskBarReceiver.cpp b/src/lib/barrier/PortableTaskBarReceiver.cpp index e9a5f401..e0c73ad2 100644 --- a/src/lib/barrier/PortableTaskBarReceiver.cpp +++ b/src/lib/barrier/PortableTaskBarReceiver.cpp @@ -17,7 +17,6 @@ */ #include "barrier/PortableTaskBarReceiver.h" -#include "mt/Lock.h" #include "base/String.h" #include "base/IEventQueue.h" #include "arch/Arch.h" diff --git a/src/lib/barrier/ServerTaskBarReceiver.cpp b/src/lib/barrier/ServerTaskBarReceiver.cpp index c3ba7cf7..22f20b01 100644 --- a/src/lib/barrier/ServerTaskBarReceiver.cpp +++ b/src/lib/barrier/ServerTaskBarReceiver.cpp @@ -18,7 +18,6 @@ #include "barrier/ServerTaskBarReceiver.h" #include "server/Server.h" -#include "mt/Lock.h" #include "base/String.h" #include "base/IEventQueue.h" #include "arch/Arch.h" diff --git a/src/lib/base/EventQueue.h b/src/lib/base/EventQueue.h index 6383b6d7..7831cd3f 100644 --- a/src/lib/base/EventQueue.h +++ b/src/lib/base/EventQueue.h @@ -18,7 +18,6 @@ #pragma once -#include "mt/CondVar.h" #include "arch/IArchMultithread.h" #include "base/IEventQueue.h" #include "base/Event.h" diff --git a/src/lib/client/Client.h b/src/lib/client/Client.h index c172af22..39f42e8c 100644 --- a/src/lib/client/Client.h +++ b/src/lib/client/Client.h @@ -26,7 +26,6 @@ #include "barrier/ClientArgs.h" #include "net/NetworkAddress.h" #include "base/EventTypes.h" -#include "mt/CondVar.h" class EventQueueTimer; namespace barrier { class Screen; } diff --git a/src/lib/mt/CondVar.cpp b/src/lib/mt/CondVar.cpp deleted file mode 100644 index 89d7ba40..00000000 --- a/src/lib/mt/CondVar.cpp +++ /dev/null @@ -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 . - */ - -#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; -} diff --git a/src/lib/mt/CondVar.h b/src/lib/mt/CondVar.h deleted file mode 100644 index fc187487..00000000 --- a/src/lib/mt/CondVar.h +++ /dev/null @@ -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 . - */ - -#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 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 -inline -CondVar::CondVar( - Mutex* mutex, - const T& data) : - CondVarBase(mutex), - m_data(data) -{ - // do nothing -} - -template -inline -CondVar::CondVar( - const CondVar& cv) : - CondVarBase(cv.getMutex()), - m_data(cv.m_data) -{ - // do nothing -} - -template -inline -CondVar::~CondVar() -{ - // do nothing -} - -template -inline -CondVar& -CondVar::operator=(const CondVar& cv) -{ - m_data = cv.m_data; - return *this; -} - -template -inline -CondVar& -CondVar::operator=(const T& data) -{ - m_data = data; - return *this; -} - -template -inline -CondVar::operator const volatile T&() const -{ - return m_data; -} diff --git a/src/lib/mt/Lock.cpp b/src/lib/mt/Lock.cpp deleted file mode 100644 index 66148583..00000000 --- a/src/lib/mt/Lock.cpp +++ /dev/null @@ -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 . - */ - -#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(); -} diff --git a/src/lib/mt/Lock.h b/src/lib/mt/Lock.h deleted file mode 100644 index e4bbacf5..00000000 --- a/src/lib/mt/Lock.h +++ /dev/null @@ -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 . - */ - -#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; -}; diff --git a/src/lib/mt/Mutex.cpp b/src/lib/mt/Mutex.cpp deleted file mode 100644 index 02d34c96..00000000 --- a/src/lib/mt/Mutex.cpp +++ /dev/null @@ -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 . - */ - -#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); -} diff --git a/src/lib/mt/Mutex.h b/src/lib/mt/Mutex.h deleted file mode 100644 index 53b8f459..00000000 --- a/src/lib/mt/Mutex.h +++ /dev/null @@ -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 . - */ - -#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; -}; diff --git a/src/lib/net/SocketMultiplexer.cpp b/src/lib/net/SocketMultiplexer.cpp index bd8edce9..a8b8d64b 100644 --- a/src/lib/net/SocketMultiplexer.cpp +++ b/src/lib/net/SocketMultiplexer.cpp @@ -19,7 +19,6 @@ #include "net/SocketMultiplexer.h" #include "net/ISocketMultiplexerJob.h" -#include "mt/CondVar.h" #include "mt/Thread.h" #include "arch/Arch.h" #include "arch/XArch.h" diff --git a/src/lib/net/TCPSocket.h b/src/lib/net/TCPSocket.h index 0076cfe8..d642d4df 100644 --- a/src/lib/net/TCPSocket.h +++ b/src/lib/net/TCPSocket.h @@ -21,7 +21,6 @@ #include "net/IDataSocket.h" #include "net/ISocketMultiplexerJob.h" #include "io/StreamBuffer.h" -#include "mt/CondVar.h" #include "arch/IArchNetwork.h" #include #include diff --git a/src/lib/platform/MSWindowsScreen.h b/src/lib/platform/MSWindowsScreen.h index 6eb68cd5..47d04c8f 100644 --- a/src/lib/platform/MSWindowsScreen.h +++ b/src/lib/platform/MSWindowsScreen.h @@ -23,7 +23,6 @@ #include "barrier/PlatformScreen.h" #include "barrier/DragInformation.h" #include "platform/synwinhk.h" -#include "mt/CondVar.h" #include #define WIN32_LEAN_AND_MEAN diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index 0a699c6a..1ca6839d 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -30,7 +30,6 @@ #include "barrier/Clipboard.h" #include "barrier/KeyMap.h" #include "barrier/ClientApp.h" -#include "mt/CondVar.h" #include "mt/Thread.h" #include "arch/XArch.h" #include "base/Log.h"