• Main Page
  • Classes
  • Files
  • File List

CArchSleepWindows.cpp

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

Generated on Fri May 24 2013 00:00:03 for Synergy by  doxygen 1.7.1