Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Mutex_WIN32.h
Go to the documentation of this file.
1//
2// Mutex_WIN32.h
3//
4// Library: Foundation
5// Package: Threading
6// Module: Mutex
7//
8// Definition of the MutexImpl and FastMutexImpl classes for WIN32.
9//
10// Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_Mutex_WIN32_INCLUDED
18#define Foundation_Mutex_WIN32_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/Exception.h"
23#include "Poco/UnWindows.h"
24
25
26namespace Poco {
27
28
30{
31protected:
34 void lockImpl();
35 bool tryLockImpl();
36 bool tryLockImpl(long milliseconds);
37 void unlockImpl();
38
39private:
40 CRITICAL_SECTION _cs;
41};
42
43
45
46
47//
48// inlines
49//
50inline void MutexImpl::lockImpl()
51{
52 try
53 {
54 EnterCriticalSection(&_cs);
55 }
56 catch (...)
57 {
58 throw SystemException("cannot lock mutex");
59 }
60}
61
62
63inline bool MutexImpl::tryLockImpl()
64{
65 try
66 {
67 return TryEnterCriticalSection(&_cs) != 0;
68 }
69 catch (...)
70 {
71 }
72 throw SystemException("cannot lock mutex");
73}
74
75
76inline void MutexImpl::unlockImpl()
77{
78 LeaveCriticalSection(&_cs);
79}
80
81
82} // namespace Poco
83
84
85#endif // Foundation_Mutex_WIN32_INCLUDED
#define Foundation_API
Definition Foundation.h:60
bool tryLockImpl(long milliseconds)
CRITICAL_SECTION _cs
Definition Mutex_WIN32.h:40
MutexImpl FastMutexImpl
Definition Mutex_WIN32.h:44