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