Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
safeflag.h
Go to the documentation of this file.
1
#pragma once
2
//------------------------------------------------------------------------------
12
#include "
threading/interlocked.h
"
13
14
//------------------------------------------------------------------------------
15
namespace
Threading
16
{
17
class
SafeFlag
18
{
19
public
:
21
SafeFlag
();
23
void
Set
();
25
void
Clear
();
27
bool
Test
()
const
;
29
bool
TestAndClearIfSet
();
30
31
private
:
32
int
volatile
flag
;
33
};
34
35
//------------------------------------------------------------------------------
38
inline
39
SafeFlag::SafeFlag
() :
40
flag
(0)
41
{
42
// empty
43
}
44
45
//------------------------------------------------------------------------------
48
inline
void
49
SafeFlag::Set
()
50
{
51
Interlocked::Exchange
(&this->
flag
, 1);
52
}
53
54
//------------------------------------------------------------------------------
57
inline
void
58
SafeFlag::Clear
()
59
{
60
Interlocked::Exchange
(&this->
flag
, 0);
61
}
62
63
//------------------------------------------------------------------------------
66
inline
bool
67
SafeFlag::Test
()
const
68
{
69
return
(0 != this->
flag
);
70
}
71
72
//------------------------------------------------------------------------------
75
inline
bool
76
SafeFlag::TestAndClearIfSet
()
77
{
78
return
(1 ==
Interlocked::CompareExchange
(&this->
flag
, 0, 1));
79
}
80
81
}
// namespace Threading
82
//------------------------------------------------------------------------------
Threading::SafeFlag::SafeFlag
SafeFlag()
constructor
Definition
safeflag.h:39
Threading::SafeFlag::Set
void Set()
set the flag
Definition
safeflag.h:49
Threading::SafeFlag::flag
int volatile flag
Definition
safeflag.h:32
Threading::SafeFlag::Test
bool Test() const
test if the flag is set
Definition
safeflag.h:67
Threading::SafeFlag::Clear
void Clear()
clear the flag
Definition
safeflag.h:58
Threading::SafeFlag::TestAndClearIfSet
bool TestAndClearIfSet()
test if flag is set, if yes, clear flag
Definition
safeflag.h:76
interlocked.h
Threading::Interlocked::Exchange
int Exchange(int volatile *dest, int value)
interlocked exchange
Definition
gccinterlocked.cc:94
Threading::Interlocked::CompareExchange
int CompareExchange(int volatile *dest, int exchange, int comparand)
interlocked compare-exchange
Definition
gccinterlocked.cc:112
Threading
The Jobs2 system provides a set of threads and a pool of jobs from which threads can pickup work.
Definition
jobs2.h:16
code
foundation
threading
safeflag.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.