SemaphoreImplWin32.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 //----------------------------------------------------------------------
00008 //----------------------------------------------------------------------
00009 #include "SemaphoreImplWin32.h"
00010 
00011 #include "Common.h"
00012 
00013 namespace icl_core {
00014 namespace thread {
00015 
00016 SemaphoreImplWin32::SemaphoreImplWin32(size_t initial_value)
00017   : m_semaphore(0)
00018 {
00019   m_semaphore = CreateSemaphore(NULL, LONG(initial_value), LONG_MAX, NULL);
00020 }
00021 
00022 SemaphoreImplWin32::~SemaphoreImplWin32()
00023 {
00024   CloseHandle(m_semaphore);
00025 }
00026 
00027 void SemaphoreImplWin32::post()
00028 {
00029   ReleaseSemaphore(m_semaphore, 1, NULL);
00030 }
00031 
00032 bool SemaphoreImplWin32::tryWait()
00033 {
00034   DWORD res = WaitForSingleObject(m_semaphore, 0);
00035   return res == WAIT_OBJECT_0;
00036 }
00037 
00038 bool SemaphoreImplWin32::wait()
00039 {
00040   DWORD res = WaitForSingleObject(m_semaphore, INFINITE);
00041   return res == WAIT_OBJECT_0;
00042 }
00043 
00044 bool SemaphoreImplWin32::wait(const TimeSpan& timeout)
00045 {
00046   DWORD res = WaitForSingleObject(m_semaphore, DWORD(timeout.toMSec()));
00047   return res == WAIT_OBJECT_0;
00048 }
00049 
00050 bool SemaphoreImplWin32::wait(const TimeStamp& timeout)
00051 {
00052   return wait(impl::getRelativeTimeout(timeout));
00053 }
00054 
00055 }
00056 }


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19