blob: 2accdde64dcafe40c87f55f71e80572723589351 (
plain)
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
|
// file : cult/sched/spin.ixx
// author : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2005-2010 Boris Kolpackov
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#include <cult/sched/exception.hxx>
namespace Cult
{
namespace Sched
{
inline
Void Spin::
lock ()
{
if (Int e = pthread_spin_lock (&spin_))
throw Implementation (e);
}
inline
Boolean Spin::
try_lock ()
{
Int e (pthread_spin_trylock (&spin_));
switch (e)
{
case 0: return true;
case EBUSY: return false;
default: throw Implementation (e);
}
}
inline
Void Spin::
unlock ()
{
if (Int e = pthread_spin_unlock (&spin_))
throw Implementation (e);
}
}
}
|