blob: 90ea6956d88846d991e651206c33fe8e97c1220c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
//
// Mutex_WINCE.cpp
//
// Library: Foundation
// Package: Threading
// Module: Mutex
//
// Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Mutex_WINCE.h"
namespace Poco {
MutexImpl::MutexImpl()
{
_mutex = CreateMutexW(NULL, FALSE, NULL);
if (!_mutex) throw SystemException("cannot create mutex");
}
MutexImpl::~MutexImpl()
{
CloseHandle(_mutex);
}
void MutexImpl::lockImpl()
{
switch (WaitForSingleObject(_mutex, INFINITE))
{
case WAIT_OBJECT_0:
return;
default:
throw SystemException("cannot lock mutex");
}
}
bool MutexImpl::tryLockImpl()
{
switch (WaitForSingleObject(_mutex, 0))
{
case WAIT_TIMEOUT:
return false;
case WAIT_OBJECT_0:
return true;
default:
throw SystemException("cannot lock mutex");
}
}
bool MutexImpl::tryLockImpl(long milliseconds)
{
switch (WaitForSingleObject(_mutex, milliseconds + 1))
{
case WAIT_TIMEOUT:
return false;
case WAIT_OBJECT_0:
return true;
default:
throw SystemException("cannot lock mutex");
}
}
void MutexImpl::unlockImpl()
{
ReleaseMutex(_mutex);
}
} // namespace Poco
|