14
14
15
15
#include < api/ImportExport.h>
16
16
17
+ #include < atomic>
17
18
#include < functional>
18
19
#include < list>
19
20
21
+ class CBackgroundPersisterTest ;
20
22
21
23
namespace ml
22
24
{
@@ -89,19 +91,11 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
89
91
// ! \return true if the function was added; false if not.
90
92
bool addPersistFunc (core::CDataAdder::TPersistFunc persistFunc);
91
93
92
- // ! When this function is called a background persistence will be
93
- // ! triggered unless there is already one in progress.
94
- bool startPersist (void );
95
-
96
- // ! Clear any persistence functions that have been added but not yet
97
- // ! invoked. This will be rejected if a background persistence is
98
- // ! currently in progress.
99
- // ! \return true if the list of functions is clear; false if not.
100
- bool clear (void );
101
-
102
94
// ! Set the first processor persist function, which is used to start the
103
95
// ! chain of background persistence. This will be rejected if a
104
96
// ! background persistence is currently in progress.
97
+ // ! This should be set once before startBackgroundPersistIfAppropriate is
98
+ // ! called.
105
99
bool firstProcessorPeriodicPersistFunc (const TFirstProcessorPeriodicPersistFunc &firstProcessorPeriodicPersistFunc);
106
100
107
101
// ! Check whether a background persist is appropriate now, and if it is
@@ -126,6 +120,17 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
126
120
CBackgroundPersister &m_Owner;
127
121
};
128
122
123
+ private:
124
+ // ! When this function is called a background persistence will be
125
+ // ! triggered unless there is already one in progress.
126
+ bool startPersist (void );
127
+
128
+ // ! Clear any persistence functions that have been added but not yet
129
+ // ! invoked. This will be rejected if a background persistence is
130
+ // ! currently in progress.
131
+ // ! \return true if the list of functions is clear; false if not.
132
+ bool clear (void );
133
+
129
134
private:
130
135
// ! How frequently should background persistence be attempted?
131
136
core_t ::TTime m_PeriodicPersistInterval;
@@ -148,10 +153,10 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
148
153
core::CFastMutex m_Mutex;
149
154
150
155
// ! Is the background thread currently busy persisting data?
151
- volatile bool m_IsBusy;
156
+ std::atomic_bool m_IsBusy;
152
157
153
158
// ! Have we been told to shut down?
154
- volatile bool m_IsShutdown;
159
+ std::atomic_bool m_IsShutdown;
155
160
156
161
using TPersistFuncList = std::list<core::CDataAdder::TPersistFunc>;
157
162
@@ -164,6 +169,9 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
164
169
// Allow the background thread to access the member variables of the owning
165
170
// object
166
171
friend class CBackgroundThread ;
172
+
173
+ // For testing
174
+ friend class ::CBackgroundPersisterTest;
167
175
};
168
176
169
177
0 commit comments