1414
1515#include < api/ImportExport.h>
1616
17+ #include < atomic>
1718#include < functional>
1819#include < list>
1920
21+ class CBackgroundPersisterTest ;
2022
2123namespace ml
2224{
@@ -89,19 +91,11 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
8991 // ! \return true if the function was added; false if not.
9092 bool addPersistFunc (core::CDataAdder::TPersistFunc persistFunc);
9193
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-
10294 // ! Set the first processor persist function, which is used to start the
10395 // ! chain of background persistence. This will be rejected if a
10496 // ! background persistence is currently in progress.
97+ // ! This should be set once before startBackgroundPersistIfAppropriate is
98+ // ! called.
10599 bool firstProcessorPeriodicPersistFunc (const TFirstProcessorPeriodicPersistFunc &firstProcessorPeriodicPersistFunc);
106100
107101 // ! Check whether a background persist is appropriate now, and if it is
@@ -126,6 +120,17 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
126120 CBackgroundPersister &m_Owner;
127121 };
128122
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+
129134 private:
130135 // ! How frequently should background persistence be attempted?
131136 core_t ::TTime m_PeriodicPersistInterval;
@@ -148,10 +153,10 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
148153 core::CFastMutex m_Mutex;
149154
150155 // ! Is the background thread currently busy persisting data?
151- volatile bool m_IsBusy;
156+ std::atomic_bool m_IsBusy;
152157
153158 // ! Have we been told to shut down?
154- volatile bool m_IsShutdown;
159+ std::atomic_bool m_IsShutdown;
155160
156161 using TPersistFuncList = std::list<core::CDataAdder::TPersistFunc>;
157162
@@ -164,6 +169,9 @@ class API_EXPORT CBackgroundPersister : private core::CNonCopyable
164169 // Allow the background thread to access the member variables of the owning
165170 // object
166171 friend class CBackgroundThread ;
172+
173+ // For testing
174+ friend class ::CBackgroundPersisterTest;
167175};
168176
169177
0 commit comments