00001 /* 00002 * synergy -- mouse and keyboard sharing utility 00003 * Copyright (C) 2002 Chris Schoeneman 00004 * 00005 * This package is free software you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * found in the file COPYING that should have accompanied this file. 00008 * 00009 * This package is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 */ 00014 00015 #include "CArchSleepWindows.h" 00016 #include "CArch.h" 00017 #include "CArchMultithreadWindows.h" 00018 00019 // 00020 // CArchSleepWindows 00021 // 00022 00023 CArchSleepWindows::CArchSleepWindows() 00024 { 00025 // do nothing 00026 } 00027 00028 CArchSleepWindows::~CArchSleepWindows() 00029 { 00030 // do nothing 00031 } 00032 00033 void 00034 CArchSleepWindows::sleep(double timeout) 00035 { 00036 ARCH->testCancelThread(); 00037 if (timeout < 0.0) { 00038 return; 00039 } 00040 00041 // get the cancel event from the current thread. this only 00042 // works if we're using the windows multithread object but 00043 // this is windows so that's pretty certain; we'll get a 00044 // link error if we're not, though. 00045 CArchMultithreadWindows* mt = CArchMultithreadWindows::getInstance(); 00046 if (mt != NULL) { 00047 HANDLE cancelEvent = mt->getCancelEventForCurrentThread(); 00048 WaitForSingleObject(cancelEvent, (DWORD)(1000.0 * timeout)); 00049 if (timeout == 0.0) { 00050 Sleep(0); 00051 } 00052 } 00053 else { 00054 Sleep((DWORD)(1000.0 * timeout)); 00055 } 00056 ARCH->testCancelThread(); 00057 }