MutexImplWin32.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00021 //----------------------------------------------------------------------
00022 
00023 #include "icl_core_thread/Common.h"
00024 #include "icl_core_thread/MutexImplWin32.h"
00025 
00026 namespace icl_core {
00027 namespace thread {
00028 
00029 MutexImplWin32::MutexImplWin32()
00030 {
00031   m_mutex = ::CreateMutex(NULL, false, NULL);
00032 }
00033 
00034 MutexImplWin32::~MutexImplWin32()
00035 {
00036   if (m_mutex != 0)
00037   {
00038     ::CloseHandle(m_mutex);
00039   }
00040 }
00041 
00042 bool MutexImplWin32::lock()
00043 {
00044   return ::WaitForSingleObject(m_mutex, INFINITE) == WAIT_OBJECT_0;
00045 }
00046 
00047 bool MutexImplWin32::lock(const TimeStamp& timeout)
00048 {
00049   return lock(impl::getRelativeTimeout(timeout));
00050 }
00051 
00052 bool MutexImplWin32::lock(const TimeSpan& timeout)
00053 {
00054   return ::WaitForSingleObject(m_mutex, DWORD(timeout.toMSec())) == WAIT_OBJECT_0;
00055 }
00056 
00057 bool MutexImplWin32::tryLock()
00058 {
00059   return ::WaitForSingleObject(m_mutex, 0) == WAIT_OBJECT_0;
00060 }
00061 
00062 void MutexImplWin32::unlock()
00063 {
00064   ::ReleaseMutex(m_mutex);
00065 }
00066 
00067 }
00068 }


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24