Use the platform independent primitives instead.
#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>
_next = conf->head;
conf->head = this;
+
+ mutex = new os::Mutex();
}
VoidParameter::~VoidParameter() {
+ delete mutex;
}
const char*
#include <rfb/util.h>
+namespace os { class Mutex; }
+
namespace rfb {
class VoidParameter;
struct ParameterIterator;
bool immutable;
const char* name;
const char* description;
+
+ os::Mutex* mutex;
};
class AliasParameter : public VoidParameter {
*/
#include <stdio.h>
+
+#include <os/Mutex.h>
+
#include <rfb/KeyRemapper.h>
#include <rfb/Configuration.h>
#include <rfb/LogWriter.h>
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;
}
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;
#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;
};
};
#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);
#include <time.h>
#include <rfb/Logger.h>
+namespace os { class Mutex; }
+
namespace rfb {
class Logger_File : public Logger {
char* m_filename;
FILE* m_file;
time_t m_lastLogTime;
+ os::Mutex* mutex;
};
bool initFileLogger(const char* filename);
#include <rfb/util.h>
#include <rfb/Logger_syslog.h>
#include <rfb/LogWriter.h>
-#include <rfb/Threading.h>
using namespace rfb;
+++ /dev/null
-/* 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__
SInput.cxx
SocketManager.cxx
TCharArray.cxx
- Threading.cxx
TsSessions.cxx
Win32Util.cxx
WMCursor.cxx
#define __RFB_WIN32_CLIPBOARD_H__
#include <rfb/SDesktop.h>
-#include <rfb/Threading.h>
#include <rfb_win32/MsgWindow.h>
#include <rfb_win32/DeviceFrameBuffer.h>
}
-RegConfigThread::RegConfigThread() : Thread("RegConfigThread"), config(&eventMgr) {
+RegConfigThread::RegConfigThread() : config(&eventMgr), thread_id(-1) {
}
RegConfigThread::~RegConfigThread() {
- join();
+ PostThreadMessage(thread_id, WM_QUIT, 0, 0);
+ wait();
}
bool RegConfigThread::start(const HKEY rootKey, const TCHAR* keyname) {
if (config.setKey(rootKey, keyname)) {
Thread::start();
+ while (thread_id == (DWORD)-1)
+ Sleep(0);
return true;
}
return false;
}
-void RegConfigThread::run() {
+void RegConfigThread::worker() {
DWORD result = 0;
MSG msg;
+ thread_id = GetCurrentThreadId();
while ((result = eventMgr.getMessage(&msg, 0, 0, 0)) > 0) {}
if (result < 0)
throw rdr::SystemException("RegConfigThread failed", GetLastError());
}
-
-Thread* RegConfigThread::join() {
- PostThreadMessage(getThreadId(), WM_QUIT, 0, 0);
- return Thread::join();
-}
#ifndef __RFB_WIN32_REG_CONFIG_H__
#define __RFB_WIN32_REG_CONFIG_H__
-#include <rfb/Threading.h>
+#include <os/Thread.h>
+
#include <rfb/Configuration.h>
#include <rfb_win32/Registry.h>
#include <rfb_win32/EventManager.h>
RegKey key;
};
- class RegConfigThread : Thread {
+ class RegConfigThread : os::Thread {
public:
RegConfigThread();
~RegConfigThread();
// Start the thread, reading from the specified key
bool start(const HKEY rootkey, const TCHAR* keyname);
protected:
- void run();
- Thread* join();
+ virtual void worker();
EventManager eventMgr;
RegConfig config;
+ DWORD thread_id;
};
};
#include <rfb_win32/MsgWindow.h>
#include <rfb_win32/ModuleFileName.h>
#include <rfb_win32/Registry.h>
-#include <rfb/Threading.h>
+#include <rfb_win32/Handle.h>
#include <logmessages/messages.h>
#include <rdr/Exception.h>
#include <rfb/LogWriter.h>
+++ /dev/null
-/* 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.cxx
-// Win32 Threading interface implementation
-
-#include <malloc.h>
-
-#include <rdr/Exception.h>
-#include <rfb/LogWriter.h>
-#include <rfb/util.h>
-#include <rfb_win32/Threading.h>
-
-using namespace rfb;
-
-static LogWriter vlog("Threading");
-
-static DWORD threadStorage = TlsAlloc();
-
-
-inline void logAction(Thread* t, const char* action) {
- vlog.debug("%-16.16s %s(%p)", action, t->getName(), t);
-}
-
-inline void logError(Thread* t, const char* err) {
- vlog.error("%-16.16s %s(%p):%s", "failed", t->getName(), t, err);
-}
-
-
-DWORD WINAPI
-Thread::threadProc(LPVOID lpParameter) {
- Thread* thread = (Thread*) lpParameter;
- TlsSetValue(threadStorage, thread);
- logAction(thread, "started");
- try {
- thread->run();
- logAction(thread, "stopped");
- } catch (rdr::Exception& e) {
- logError(thread, e.str());
- }
- bool deleteThread = false;
- {
- Lock l(thread->mutex);
- thread->state = ThreadStopped;
- thread->sig->signal();
- deleteThread = thread->deleteAfterRun;
- }
- if (deleteThread)
- delete thread;
- return 0;
-}
-
-Thread::Thread(const char* name_) : name(strDup(name_ ? name_ : "Unnamed")), sig(0), deleteAfterRun(false) {
- sig = new Condition(mutex);
- cond_event.h = CreateEvent(NULL, TRUE, FALSE, NULL);
- thread.h = CreateThread(NULL, 0, threadProc, this, CREATE_SUSPENDED, &thread_id);
- state = ThreadCreated;
- logAction(this, "created");
-}
-
-Thread::Thread(HANDLE thread_, DWORD thread_id_) :
- thread(thread_), thread_id(thread_id_), name(strDup("Native")), sig(0), deleteAfterRun(false) {
- cond_event.h = CreateEvent(NULL, TRUE, FALSE, NULL);
- state = ThreadNative;
- logAction(this, "created");
-}
-
-Thread::~Thread() {
- logAction(this, "destroying");
- if (!deleteAfterRun && state != ThreadNative)
- this->join();
- if (sig)
- delete sig;
- logAction(this, "destroyed");
-}
-
-void
-Thread::run() {
-}
-
-void
-Thread::start() {
- Lock l(mutex);
- if (state == ThreadCreated) {
- state = ThreadStarted;
- sig->signal();
- ResumeThread(thread);
- }
-}
-
-Thread*
-Thread::join() {
- if (deleteAfterRun)
- throw rdr::Exception("attempt to join() with deleteAfterRun thread");
- Lock l(mutex);
- if (state == ThreadJoined) {
- logAction(this, "already joined");
- } else {
- logAction(this, "joining");
- while (state == ThreadStarted) {
- sig->wait();
- logAction(this, "checking");
- }
- state = ThreadJoined;
- logAction(this, "joined");
- }
- return this;
-}
-
-const char*
-Thread::getName() const {
- return name.buf;
-}
-
-ThreadState
-Thread::getState() const {
- return state;
-}
-
-unsigned long
-Thread::getThreadId() const {
- return thread_id;
-}
-
-
-Thread*
-Thread::self() {
- Thread* thread = (Thread*) TlsGetValue(threadStorage);
- if (!thread) {
- // *** memory leak - could use GetExitCodeThread to lazily detect when
- // to clean up native thread objects
- thread = new Thread(GetCurrentThread(), GetCurrentThreadId());
- TlsSetValue(threadStorage, thread);
- }
- return thread;
-}
+++ /dev/null
-/* 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_win32.h
-// Win32 Threading interface implementation
-
-#ifndef __RFB_THREADING_IMPL_WIN32
-#define __RFB_THREADING_IMPL_WIN32
-
-#define __RFB_THREADING_IMPL WIN32
-
-#include <rfb_win32/Handle.h>
-#include <rfb/util.h>
-#include <rdr/Exception.h>
-//#include <stdio.h>
-
-
-namespace rfb {
- class Condition;
-
- class Mutex {
- public:
- Mutex() {
- InitializeCriticalSection(&crit);
- }
- ~Mutex() {
- DeleteCriticalSection(&crit);
- }
- friend class Lock;
- friend class Condition;
- protected:
- void enter() {EnterCriticalSection(&crit);}
- void exit() {LeaveCriticalSection(&crit);}
- CRITICAL_SECTION crit;
- };
-
- class Lock {
- public:
- Lock(Mutex& m) : mutex(m) {m.enter();}
- ~Lock() {mutex.exit();}
- protected:
- Mutex& mutex;
- };
-
- enum ThreadState {ThreadCreated, ThreadStarted, ThreadStopped, ThreadJoined, ThreadNative};
-
- class Thread {
- public:
- Thread(const char* name_=0);
- virtual ~Thread();
-
- virtual void run();
-
- virtual void start();
- virtual Thread* join();
-
- const char* getName() const;
- ThreadState getState() const;
-
- // Determines whether the thread should delete itself when run() returns
- // If you set this, you must NEVER call join()!
- void setDeleteAfterRun() {deleteAfterRun = true;};
-
- unsigned long getThreadId() const;
-
- static Thread* self();
-
- friend class Condition;
-
- protected:
- Thread(HANDLE thread_, DWORD thread_id_);
- static DWORD WINAPI threadProc(LPVOID lpParameter);
-
- win32::Handle thread;
- DWORD thread_id;
- CharArray name;
- ThreadState state;
- Condition* sig;
- Mutex mutex;
-
- win32::Handle cond_event;
- Thread* cond_next;
-
- bool deleteAfterRun;
- };
-
- class Condition {
- public:
- Condition(Mutex& m) : mutex(m), waiting(0) {
- }
- ~Condition() {
- }
-
- // Wake up the specified number of threads that are waiting
- // on this Condition, or all of them if -1 is specified.
- void signal(int howMany=1) {
- Lock l(cond_lock);
- while (waiting && howMany!=0) {
- SetEvent(waiting->cond_event);
- waiting = waiting->cond_next;
- if (howMany>0) --howMany;
- }
- }
-
- // NB: Must hold "mutex" to call wait()
- // Wait until either the Condition is signalled or the timeout
- // expires.
- void wait(DWORD timeout=INFINITE) {
- Thread* self = Thread::self();
- ResetEvent(self->cond_event);
- { Lock l(cond_lock);
- self->cond_next = waiting;
- waiting = self;
- }
- mutex.exit();
- DWORD result = WaitForSingleObject(self->cond_event, timeout);
- mutex.enter();
- if (result == WAIT_TIMEOUT) {
- Lock l(cond_lock);
- // Remove this thread from the Condition
- for (Thread** removeFrom = &waiting; *removeFrom; removeFrom = &(*removeFrom)->cond_next) {
- if (*removeFrom == self) {
- *removeFrom = self->cond_next;
- break;
- }
- }
- } else if (result == WAIT_FAILED) {
- throw rdr::SystemException("failed to wait on Condition", GetLastError());
- }
- }
-
- protected:
- Mutex& mutex;
- Mutex cond_lock;
- Thread* waiting;
- };
-
-};
-
-#endif // __RFB_THREADING_IMPL
// -=- WMHooks.cxx
+#include <os/Mutex.h>
+#include <os/Thread.h>
+
#include <rfb_win32/WMHooks.h>
#include <rfb_win32/Service.h>
#include <rfb_win32/MsgWindow.h>
#include <rfb_win32/IntervalTimer.h>
-#include <rfb/Threading.h>
#include <rfb/LogWriter.h>
#include <list>
}
-class WMHooksThread : public Thread {
+class WMHooksThread : public os::Thread {
public:
- WMHooksThread() : Thread("WMHookThread"),
- active(true) {
- }
- virtual void run();
- virtual Thread* join();
+ WMHooksThread() : active(true), thread_id(-1) { }
+ void stop();
+ DWORD getThreadId() { return thread_id; }
+protected:
+ virtual void worker();
protected:
bool active;
+ DWORD thread_id;
};
static WMHooksThread* hook_mgr = 0;
static std::list<WMHooks*> hooks;
-static Mutex hook_mgr_lock;
+static os::Mutex hook_mgr_lock;
static bool StartHookThread() {
return false;
vlog.debug("creating thread");
hook_mgr = new WMHooksThread();
+ hook_mgr->start();
+ while (hook_mgr->getThreadId() == (DWORD)-1)
+ Sleep(0);
vlog.debug("installing hooks");
if (!WM_Hooks_Install(hook_mgr->getThreadId(), 0)) {
vlog.error("failed to initialise hooks");
- delete hook_mgr->join();
+ hook_mgr->stop();
+ delete hook_mgr;
hook_mgr = 0;
return false;
}
- vlog.debug("starting thread");
- hook_mgr->start();
return true;
}
if (!hooks.empty())
return;
vlog.debug("closing thread");
- delete hook_mgr->join();
+ hook_mgr->stop();
+ delete hook_mgr;
hook_mgr = 0;
}
static bool AddHook(WMHooks* hook) {
vlog.debug("adding hook");
- Lock l(hook_mgr_lock);
+ os::AutoMutex a(&hook_mgr_lock);
if (!StartHookThread())
return false;
hooks.push_back(hook);
static bool RemHook(WMHooks* hook) {
{
vlog.debug("removing hook");
- Lock l(hook_mgr_lock);
+ os::AutoMutex a(&hook_mgr_lock);
hooks.remove(hook);
}
StopHookThread();
}
static void NotifyHooksRegion(const Region& r) {
- Lock l(hook_mgr_lock);
+ os::AutoMutex a(&hook_mgr_lock);
std::list<WMHooks*>::iterator i;
for (i=hooks.begin(); i!=hooks.end(); i++)
(*i)->NotifyHooksRegion(r);
void
-WMHooksThread::run() {
+WMHooksThread::worker() {
// Obtain message ids for all supported hook messages
UINT windowMsg = WM_Hooks_WindowChanged();
UINT clientAreaMsg = WM_Hooks_WindowClientAreaChanged();
vlog.debug("starting hook thread");
+ thread_id = GetCurrentThreadId();
+
while (active && GetMessage(&msg, NULL, 0, 0)) {
count++;
WM_Hooks_Remove(getThreadId());
}
-Thread*
-WMHooksThread::join() {
+void
+WMHooksThread::stop() {
vlog.debug("stopping WMHooks thread");
active = false;
PostThreadMessage(thread_id, WM_QUIT, 0, 0);
- vlog.debug("joining WMHooks thread");
- return Thread::join();
+ vlog.debug("waiting for WMHooks thread");
+ wait();
}
// -=- WMHooks class
bool rfb::win32::WMHooks::getUpdates(UpdateTracker* ut) {
if (!updatesReady) return false;
- Lock l(hook_mgr_lock);
+ os::AutoMutex a(&hook_mgr_lock);
updates.copyTo(ut);
updates.clear();
updatesReady = false;
return block_ == blocking;
}
-Mutex blockMutex;
-int blockCount = 0;
+static os::Mutex blockMutex;
+static int blockCount = 0;
bool rfb::win32::WMBlockInput::blockInputs(bool on) {
if (active == on) return true;
- Lock l(blockMutex);
+ os::AutoMutex a(&blockMutex);
int newCount = on ? blockCount+1 : blockCount-1;
if (!blockRealInputs(newCount > 0))
return false;
#define __RFB_WIN32_NOTIFIER_H__
#include <rfb/SDesktop.h>
-#include <rfb/Threading.h>
#include <rfb_win32/MsgWindow.h>
#include <rfb_win32/DeviceFrameBuffer.h>
#include <rfb_win32/SInput.h>
QueryConnectDialog::QueryConnectDialog(network::Socket* sock_,
const char* userName_,
VNCServerWin32* s)
-: Thread("QueryConnectDialog"), Dialog(GetModuleHandle(0)),
+: Dialog(GetModuleHandle(0)),
sock(sock_), approve(false), server(s) {
peerIp.buf = sock->getPeerAddress();
userName.buf = strDup(userName_);
// - Thread overrides
-void QueryConnectDialog::run() {
+void QueryConnectDialog::worker() {
countdown = timeout;
try {
if (desktopChangeRequired() && !changeDesktop())
#ifndef __WINVNC_QUERY_CONNECT_DIALOG_H__
#define __WINVNC_QUERY_CONNECT_DIALOG_H__
-#include <rfb/Threading.h>
#include <rfb_win32/Dialog.h>
#include <rfb/util.h>
+namespace os { class Thread; }
+
namespace network { class Socket; }
namespace winvnc {
class VNCServerWin32;
- class QueryConnectDialog : public rfb::Thread, rfb::win32::Dialog {
+ class QueryConnectDialog : public os::Thread, rfb::win32::Dialog {
public:
QueryConnectDialog(network::Socket* sock, const char* userName, VNCServerWin32* s);
virtual void startDialog();
- virtual void run();
network::Socket* getSock() {return sock;}
bool isAccepted() const {return approve;}
protected:
+ // Thread methods
+ virtual void worker();
// Dialog methods (protected)
virtual void initDialog();
#include <winvnc/VNCServerService.h>
#include <winvnc/resource.h>
+#include <os/Mutex.h>
+#include <os/Thread.h>
+
#include <rfb/LogWriter.h>
#include <rfb/Configuration.h>
+
#include <rfb_win32/LaunchProcess.h>
#include <rfb_win32/TrayIcon.h>
#include <rfb_win32/AboutDialog.h>
#include <rfb_win32/MsgBox.h>
#include <rfb_win32/Service.h>
#include <rfb_win32/CurrentUser.h>
+
#include <winvnc/ControlPanel.h>
using namespace rfb;
case WM_SET_TOOLTIP:
{
- rfb::Lock l(thread.lock);
+ os::AutoMutex a(thread.lock);
if (thread.toolTip.buf)
setToolTip(thread.toolTip.buf);
}
STrayIconThread::STrayIconThread(VNCServerWin32& sm, UINT inactiveIcon_, UINT activeIcon_,
UINT dis_inactiveIcon_, UINT dis_activeIcon_, UINT menu_)
-: Thread("TrayIcon"), windowHandle(0), server(sm),
+: thread_id(-1), windowHandle(0), server(sm),
inactiveIcon(inactiveIcon_), activeIcon(activeIcon_),
dis_inactiveIcon(dis_inactiveIcon_), dis_activeIcon(dis_activeIcon_),
menu(menu_), runTrayIcon(true) {
+ lock = new os::Mutex;
start();
+ while (thread_id == (DWORD)-1)
+ Sleep(0);
}
+STrayIconThread::~STrayIconThread() {
+ runTrayIcon = false;
+ PostThreadMessage(thread_id, WM_QUIT, 0, 0);
+ delete lock;
+}
-void STrayIconThread::run() {
+void STrayIconThread::worker() {
+ thread_id = GetCurrentThreadId();
while (runTrayIcon) {
if (rfb::win32::desktopChangeRequired() &&
!rfb::win32::changeDesktop())
void STrayIconThread::setToolTip(const TCHAR* text) {
if (!windowHandle) return;
- Lock l(lock);
+ os::AutoMutex a(lock);
delete [] toolTip.buf;
toolTip.buf = tstrDup(text);
PostMessage(windowHandle, WM_SET_TOOLTIP, 0, 0);
#include <winvnc/VNCServerWin32.h>
#include <rfb_win32/TCharArray.h>
#include <rfb/Configuration.h>
-#include <rfb/Threading.h>
+
+namespace os {
+ class Mutex;
+ class Thread;
+}
namespace winvnc {
- class STrayIconThread : rfb::Thread {
+ class STrayIconThread : os::Thread {
public:
STrayIconThread(VNCServerWin32& sm, UINT inactiveIcon,
UINT activeIcon, UINT dis_inactiveIcon, UINT dis_activeIcon, UINT menu);
- virtual ~STrayIconThread() {
- runTrayIcon = false;
- PostThreadMessage(getThreadId(), WM_QUIT, 0, 0);
- }
-
- virtual void run();
+ virtual ~STrayIconThread();
void setToolTip(const TCHAR* text);
friend class STrayIcon;
protected:
- rfb::Mutex lock;
+ virtual void worker();
+
+ os::Mutex* lock;
+ DWORD thread_id;
HWND windowHandle;
rfb::TCharArray toolTip;
VNCServerWin32& server;
#include <winvnc/VNCServerWin32.h>
#include <winvnc/resource.h>
#include <winvnc/STrayIcon.h>
+
+#include <os/Mutex.h>
+
#include <rfb_win32/ComputerName.h>
#include <rfb_win32/CurrentUser.h>
#include <rfb_win32/Service.h>
+
#include <rfb/Hostname.h>
#include <rfb/LogWriter.h>
VNCServerWin32::VNCServerWin32()
- : command(NoCommand), commandSig(commandLock),
+ : command(NoCommand),
commandEvent(CreateEvent(0, TRUE, FALSE, 0)),
sessionEvent(isServiceProcess() ?
CreateEvent(0, FALSE, FALSE, "Global\\SessionEventTigerVNC") : 0),
vncServer(CStr(ComputerName().buf), &desktop),
- hostThread(0), runServer(false), isDesktopStarted(false),
+ thread_id(-1), runServer(false), isDesktopStarted(false),
httpServer(&vncServer), config(&sockMgr),
rfbSock(&sockMgr), httpSock(&sockMgr), trayIcon(0),
queryConnectDialog(0)
{
+ commandLock = new os::Mutex;
+ commandSig = new os::Condition(commandLock);
+
+ runLock = new os::Mutex;
+
// Initialise the desktop
desktop.setStatusLocation(&isDesktopStarted);
desktop.setStatusLocation(0);
// Join the Accept/Reject dialog thread
- if (queryConnectDialog)
- delete queryConnectDialog->join();
+ if (queryConnectDialog) {
+ queryConnectDialog->wait();
+ delete queryConnectDialog;
+ }
+
+ delete runLock;
+
+ delete commandSig;
+ delete commandLock;
}
int VNCServerWin32::run() {
- { Lock l(runLock);
- hostThread = Thread::self();
+ {
+ os::AutoMutex a(runLock);
+ thread_id = GetCurrentThreadId();
runServer = true;
}
vlog.error("%s", e.str());
}
- { Lock l(runLock);
+ {
+ os::AutoMutex a(runLock);
runServer = false;
- hostThread = 0;
+ thread_id = (DWORD)-1;
}
return result;
}
void VNCServerWin32::stop() {
- Lock l(runLock);
+ os::AutoMutex a(runLock);
runServer = false;
- if (hostThread)
- PostThreadMessage(hostThread->getThreadId(), WM_QUIT, 0, 0);
+ if (thread_id != (DWORD)-1)
+ PostThreadMessage(thread_id, WM_QUIT, 0, 0);
}
bool VNCServerWin32::queueCommand(Command cmd, const void* data, int len, bool wait) {
- Lock l(commandLock);
+ os::AutoMutex a(commandLock);
while (command != NoCommand)
- commandSig.wait();
+ commandSig->wait();
command = cmd;
commandData = data;
commandDataLen = len;
SetEvent(commandEvent);
if (wait) {
while (command != NoCommand)
- commandSig.wait();
- commandSig.signal();
+ commandSig->wait();
+ commandSig->signal();
}
return true;
}
if (event_ == commandEvent.h) {
// If there is no command queued then return immediately
{
- Lock l(commandLock);
+ os::AutoMutex a(commandLock);
if (command == NoCommand)
return;
}
vncServer.approveConnection(queryConnectDialog->getSock(),
queryConnectDialog->isAccepted(),
"Connection rejected by user");
- delete queryConnectDialog->join();
+ queryConnectDialog->wait();
+ delete queryConnectDialog;
queryConnectDialog = 0;
break;
// Clear the command and signal completion
{
- Lock l(commandLock);
+ os::AutoMutex a(commandLock);
command = NoCommand;
- commandSig.signal();
+ commandSig->signal();
}
} else if (event_ == sessionEvent.h) {
stop();
#include <winvnc/JavaViewer.h>
#include <winvnc/ManagedListener.h>
+namespace os {
+ class Mutex;
+ class Condition;
+ class Thread;
+}
+
namespace winvnc {
class STrayIconThread;
Command command;
const void* commandData;
int commandDataLen;
- rfb::Mutex commandLock;
- rfb::Condition commandSig;
+ os::Mutex* commandLock;
+ os::Condition* commandSig;
rfb::win32::Handle commandEvent;
rfb::win32::Handle sessionEvent;
// VNCServerWin32 Server-internal state
rfb::win32::SDisplay desktop;
rfb::VNCServerST vncServer;
- rfb::Mutex runLock;
- rfb::Thread* hostThread;
+ os::Mutex* runLock;
+ DWORD thread_id;
bool runServer;
bool isDesktopStarted;
JavaViewerServer httpServer;