From 338e73aef8dcd3e7e43e4337071ea9d77568c18b Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 7 Jul 2016 15:35:13 +0200 Subject: Replace Windows specific thread handling Use the platform independent primitives instead. --- common/rfb/Configuration.cxx | 19 ++++++------------- common/rfb/Configuration.h | 4 ++++ common/rfb/KeyRemapper.cxx | 27 ++++++++++++++++++--------- common/rfb/KeyRemapper.h | 6 +++++- common/rfb/Logger_file.cxx | 18 ++++++------------ common/rfb/Logger_file.h | 3 +++ common/rfb/Logger_syslog.cxx | 1 - common/rfb/Threading.h | 31 ------------------------------- 8 files changed, 42 insertions(+), 67 deletions(-) delete mode 100644 common/rfb/Threading.h (limited to 'common/rfb') diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx index 8e1ea6e9..a5c23028 100644 --- a/common/rfb/Configuration.cxx +++ b/common/rfb/Configuration.cxx @@ -23,24 +23,14 @@ #include #include +#include + #include #include #include #include -#include -#ifdef __RFB_THREADING_IMPL -// On platforms that support Threading, we use Locks to make getData safe -#define LOCK_CONFIG Lock l(*configLock()) -rfb::Mutex* configLock_ = 0; -static rfb::Mutex* configLock() { - if (!configLock_) - configLock_ = new rfb::Mutex; - return configLock_; -} -#else -#define LOCK_CONFIG -#endif +#define LOCK_CONFIG os::AutoMutex a(mutex) #include #include @@ -195,9 +185,12 @@ VoidParameter::VoidParameter(const char* name_, const char* desc_, _next = conf->head; conf->head = this; + + mutex = new os::Mutex(); } VoidParameter::~VoidParameter() { + delete mutex; } const char* diff --git a/common/rfb/Configuration.h b/common/rfb/Configuration.h index da93fddf..fbf161db 100644 --- a/common/rfb/Configuration.h +++ b/common/rfb/Configuration.h @@ -45,6 +45,8 @@ #include +namespace os { class Mutex; } + namespace rfb { class VoidParameter; struct ParameterIterator; @@ -174,6 +176,8 @@ namespace rfb { bool immutable; const char* name; const char* description; + + os::Mutex* mutex; }; class AliasParameter : public VoidParameter { diff --git a/common/rfb/KeyRemapper.cxx b/common/rfb/KeyRemapper.cxx index d33f0a45..b4c2793c 100644 --- a/common/rfb/KeyRemapper.cxx +++ b/common/rfb/KeyRemapper.cxx @@ -17,6 +17,9 @@ */ #include + +#include + #include #include #include @@ -27,14 +30,21 @@ static LogWriter vlog("KeyRemapper"); KeyRemapper KeyRemapper::defInstance; -#ifdef __RFB_THREADING_IMPL -static Mutex mappingLock; -#endif +KeyRemapper::KeyRemapper(const char* m) +{ + mutex = new os::Mutex; + + setMapping(m); +} + +KeyRemapper::~KeyRemapper() +{ + delete mutex; +} void KeyRemapper::setMapping(const char* m) { -#ifdef __RFB_THREADING_IMPL - Lock l(mappingLock); -#endif + os::AutoMutex a(mutex); + mapping.clear(); while (m[0]) { int from, to; @@ -59,9 +69,8 @@ void KeyRemapper::setMapping(const char* m) { } rdr::U32 KeyRemapper::remapKey(rdr::U32 key) const { -#ifdef __RFB_THREADING_IMPL - Lock l(mappingLock); -#endif + os::AutoMutex a(mutex); + std::map::const_iterator i = mapping.find(key); if (i != mapping.end()) return i->second; diff --git a/common/rfb/KeyRemapper.h b/common/rfb/KeyRemapper.h index a4b7aa01..1406bad2 100644 --- a/common/rfb/KeyRemapper.h +++ b/common/rfb/KeyRemapper.h @@ -22,16 +22,20 @@ #include #include +namespace os { class Mutex; } + namespace rfb { class KeyRemapper { public: - KeyRemapper(const char* m="") { setMapping(m); } + KeyRemapper(const char* m=""); + ~KeyRemapper(); void setMapping(const char* m); rdr::U32 remapKey(rdr::U32 key) const; static KeyRemapper defInstance; private: std::map mapping; + os::Mutex* mutex; }; }; diff --git a/common/rfb/Logger_file.cxx b/common/rfb/Logger_file.cxx index ebe15d52..149ad404 100644 --- a/common/rfb/Logger_file.cxx +++ b/common/rfb/Logger_file.cxx @@ -21,36 +21,30 @@ #include #include +#include + #include #include -#include using namespace rfb; - -// If threading is available then protect the write() operation -// from concurrent accesses -#ifdef __RFB_THREADING_IMPL -static Mutex logLock; -#endif - - Logger_File::Logger_File(const char* loggerName) : Logger(loggerName), indent(13), width(79), m_filename(0), m_file(0), m_lastLogTime(0) { + mutex = new os::Mutex(); } Logger_File::~Logger_File() { closeFile(); + delete mutex; } void Logger_File::write(int level, const char *logname, const char *message) { -#ifdef __RFB_THREADING_IMPL - Lock l(logLock); -#endif + os::AutoMutex a(mutex); + if (!m_file) { if (!m_filename) return; CharArray bakFilename(strlen(m_filename) + 1 + 4); diff --git a/common/rfb/Logger_file.h b/common/rfb/Logger_file.h index 5e0c917b..5b5c34e1 100644 --- a/common/rfb/Logger_file.h +++ b/common/rfb/Logger_file.h @@ -24,6 +24,8 @@ #include #include +namespace os { class Mutex; } + namespace rfb { class Logger_File : public Logger { @@ -43,6 +45,7 @@ namespace rfb { char* m_filename; FILE* m_file; time_t m_lastLogTime; + os::Mutex* mutex; }; bool initFileLogger(const char* filename); diff --git a/common/rfb/Logger_syslog.cxx b/common/rfb/Logger_syslog.cxx index 291d36cd..dc1d0c1a 100644 --- a/common/rfb/Logger_syslog.cxx +++ b/common/rfb/Logger_syslog.cxx @@ -25,7 +25,6 @@ #include #include #include -#include using namespace rfb; diff --git a/common/rfb/Threading.h b/common/rfb/Threading.h deleted file mode 100644 index 66b3aa0f..00000000 --- a/common/rfb/Threading.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This software 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 software; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ - -// -=- Threading.h -// General purpose threading interface. -// If the current platform supports threading then __RFB_THREADING_IMPL -// will be defined after this header has been included. - -#ifndef __RFB_THREADING_H__ -#define __RFB_THREADING_H__ - -#ifdef WIN32 -#include -#endif - -#endif // __RFB_THREADING_H__ -- cgit v1.2.3