ASAGI
1.0
a pArallel Server for Adaptive GeoInformation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
threads
once.h
Go to the documentation of this file.
1
38
#ifndef THREADS_ONCE_H
39
#define THREADS_ONCE_H
40
41
#include <mutex>
42
43
#include "mutex.h"
44
45
namespace
threads
46
{
47
51
class
Once
{
52
private
:
54
bool
m_state
;
55
57
Mutex
m_mutex
;
58
59
public
:
60
Once
()
61
:
m_state
(false)
62
{ }
63
69
template
<
class
T>
70
void
saveExec
(T &obj,
void
(T::*func)())
71
{
72
// Default case
73
if
(
m_state
)
74
return
;
75
76
// Lock the state and double check
77
std::lock_guard<Mutex> lock(
m_mutex
);
78
if
(
m_state
)
79
return
;
80
81
// Save execute:
82
// Execute the function before freeing the lock
83
(obj.*func)();
84
85
m_state
=
true
;
86
}
87
};
88
89
}
90
91
#endif // THREADS_ONCE_H
threads::Once
Definition:
once.h:51
threads::PthreadMutex
Definition:
pthreadmutex.h:53
threads::Once::m_mutex
Mutex m_mutex
Definition:
once.h:57
threads::Once::m_state
bool m_state
Definition:
once.h:54
threads::Once::saveExec
void saveExec(T &obj, void(T::*func)())
Definition:
once.h:70
Generated by
1.8.7