diff options
author | Pierre Ossman <ossman@cendio.se> | 2016-07-07 15:35:13 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2016-07-07 15:36:36 +0200 |
commit | 338e73aef8dcd3e7e43e4337071ea9d77568c18b (patch) | |
tree | f1981aeeb22eb65c79dd7e76372c02f7fd0f565a /common | |
parent | ff872614b507d0aa8bfbd09ef41550390cfe658a (diff) | |
download | tigervnc-338e73aef8dcd3e7e43e4337071ea9d77568c18b.tar.gz tigervnc-338e73aef8dcd3e7e43e4337071ea9d77568c18b.zip |
Replace Windows specific thread handling
Use the platform independent primitives instead.
Diffstat (limited to 'common')
-rw-r--r-- | common/rfb/Configuration.cxx | 19 | ||||
-rw-r--r-- | common/rfb/Configuration.h | 4 | ||||
-rw-r--r-- | common/rfb/KeyRemapper.cxx | 27 | ||||
-rw-r--r-- | common/rfb/KeyRemapper.h | 6 | ||||
-rw-r--r-- | common/rfb/Logger_file.cxx | 18 | ||||
-rw-r--r-- | common/rfb/Logger_file.h | 3 | ||||
-rw-r--r-- | common/rfb/Logger_syslog.cxx | 1 | ||||
-rw-r--r-- | common/rfb/Threading.h | 31 |
8 files changed, 42 insertions, 67 deletions
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 <ctype.h> #include <string.h> +#include <os/Mutex.h> + #include <rfb/util.h> #include <rfb/Configuration.h> #include <rfb/LogWriter.h> #include <rfb/Exception.h> -#include <rfb/Threading.h> -#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 <rdr/HexOutStream.h> #include <rdr/HexInStream.h> @@ -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 <rfb/util.h> +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 <stdio.h> + +#include <os/Mutex.h> + #include <rfb/KeyRemapper.h> #include <rfb/Configuration.h> #include <rfb/LogWriter.h> @@ -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<rdr::U32,rdr::U32>::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 <map> #include <rdr/types.h> +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<rdr::U32,rdr::U32> 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 <stdlib.h> #include <string.h> +#include <os/Mutex.h> + #include <rfb/util.h> #include <rfb/Logger_file.h> -#include <rfb/Threading.h> 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 <time.h> #include <rfb/Logger.h> +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 <rfb/util.h> #include <rfb/Logger_syslog.h> #include <rfb/LogWriter.h> -#include <rfb/Threading.h> 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 <rfb_win32/Threading.h> -#endif - -#endif // __RFB_THREADING_H__ |