2323
2424#include < api/ImportExport.h>
2525
26+ #include < atomic>
2627#include < functional>
2728#include < list>
2829
30+ class CBackgroundPersisterTest ;
2931
3032namespace ml
3133{
@@ -98,19 +100,11 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
98100 // ! \return true if the function was added; false if not.
99101 bool addPersistFunc (core::CDataAdder::TPersistFunc persistFunc);
100102
101- // ! When this function is called a background persistence will be
102- // ! triggered unless there is already one in progress.
103- bool startPersist (void );
104-
105- // ! Clear any persistence functions that have been added but not yet
106- // ! invoked. This will be rejected if a background persistence is
107- // ! currently in progress.
108- // ! \return true if the list of functions is clear; false if not.
109- bool clear (void );
110-
111103 // ! Set the first processor persist function, which is used to start the
112104 // ! chain of background persistence. This will be rejected if a
113105 // ! background persistence is currently in progress.
106+ // ! This should be set once before startBackgroundPersistIfAppropriate is
107+ // ! called.
114108 bool firstProcessorPeriodicPersistFunc (const TFirstProcessorPeriodicPersistFunc &firstProcessorPeriodicPersistFunc);
115109
116110 // ! Check whether a background persist is appropriate now, and if it is
@@ -135,6 +129,17 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
135129 CBackgroundPersister &m_Owner;
136130 };
137131
132+ private:
133+ // ! When this function is called a background persistence will be
134+ // ! triggered unless there is already one in progress.
135+ bool startPersist (void );
136+
137+ // ! Clear any persistence functions that have been added but not yet
138+ // ! invoked. This will be rejected if a background persistence is
139+ // ! currently in progress.
140+ // ! \return true if the list of functions is clear; false if not.
141+ bool clear (void );
142+
138143 private:
139144 // ! How frequently should background persistence be attempted?
140145 core_t ::TTime m_PeriodicPersistInterval;
@@ -157,10 +162,10 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
157162 core::CFastMutex m_Mutex;
158163
159164 // ! Is the background thread currently busy persisting data?
160- volatile bool m_IsBusy;
165+ std::atomic_bool m_IsBusy;
161166
162167 // ! Have we been told to shut down?
163- volatile bool m_IsShutdown;
168+ std::atomic_bool m_IsShutdown;
164169
165170 using TPersistFuncList = std::list<core::CDataAdder::TPersistFunc>;
166171
@@ -173,6 +178,9 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
173178 // Allow the background thread to access the member variables of the owning
174179 // object
175180 friend class CBackgroundThread ;
181+
182+ // For testing
183+ friend class ::CBackgroundPersisterTest;
176184};
177185
178186
0 commit comments