@@ -189,11 +189,14 @@ inline FutureBase::CompletionCallbackHandle Future<ResultType>::AddOnCompletion(
189189
190190#endif // defined(INTERNAL_EXPERIMENTAL)
191191
192- inline FutureBase::FutureBase () : api_(NULL ), handle_(0 ) {} // NOLINT
192+ inline FutureBase::FutureBase ()
193+ : mutex_(Mutex::Mode::kModeNonRecursive ),
194+ api_(NULL ),
195+ handle_(0 ) {} // NOLINT
193196
194197inline FutureBase::FutureBase (detail::FutureApiInterface* api,
195198 const FutureHandle& handle)
196- : api_(api), handle_(handle) {
199+ : mutex_(Mutex::Mode:: kModeNonRecursive ), api_(api), handle_(handle) {
197200 api_->ReferenceFuture (handle_);
198201 // Once the FutureBase has reference, we don't need extra handle reference.
199202 handle_.Detach ();
@@ -203,7 +206,8 @@ inline FutureBase::FutureBase(detail::FutureApiInterface* api,
203206inline FutureBase::~FutureBase () { Release (); }
204207
205208inline FutureBase::FutureBase (const FutureBase& rhs)
206- : api_(NULL ) // NOLINT
209+ : mutex_(Mutex::Mode::kModeNonRecursive ),
210+ api_(NULL ) // NOLINT
207211{ // NOLINT
208212 *this = rhs;
209213}
@@ -214,13 +218,13 @@ inline FutureBase& FutureBase::operator=(const FutureBase& rhs) {
214218 detail::FutureApiInterface* new_api;
215219 FutureHandle new_handle;
216220 {
217- std::lock_guard<std::mutex> lock (rhs.mutex_ );
221+ MutexLock lock (rhs.mutex_ );
218222 new_api = rhs.api_ ;
219223 new_handle = rhs.handle_ ;
220224 }
221225
222226 {
223- std::lock_guard<std::mutex> lock (mutex_);
227+ MutexLock lock (mutex_);
224228 api_ = new_api;
225229 handle_ = new_handle;
226230
@@ -235,7 +239,8 @@ inline FutureBase& FutureBase::operator=(const FutureBase& rhs) {
235239
236240#if defined(FIREBASE_USE_MOVE_OPERATORS)
237241inline FutureBase::FutureBase (FutureBase&& rhs) noexcept
238- : api_(NULL ) // NOLINT
242+ : mutex_(Mutex::Mode::kModeNonRecursive ),
243+ api_(NULL ) // NOLINT
239244{
240245 *this = std::move (rhs);
241246}
@@ -246,14 +251,14 @@ inline FutureBase& FutureBase::operator=(FutureBase&& rhs) noexcept {
246251 detail::FutureApiInterface* new_api;
247252 FutureHandle new_handle;
248253 {
249- std::lock_guard<std::mutex> lock (rhs.mutex_ );
254+ MutexLock lock (rhs.mutex_ );
250255 detail::UnregisterForCleanup (rhs.api_ , &rhs);
251256 new_api = rhs.api_ ;
252257 new_handle = rhs.handle_ ;
253258 rhs.api_ = NULL ; // NOLINT
254259 }
255260
256- std::lock_guard<std::mutex> lock (mutex_);
261+ MutexLock lock (mutex_);
257262 api_ = new_api;
258263 handle_ = new_handle;
259264 detail::RegisterForCleanup (api_, this );
@@ -262,7 +267,7 @@ inline FutureBase& FutureBase::operator=(FutureBase&& rhs) noexcept {
262267#endif // defined(FIREBASE_USE_MOVE_OPERATORS)
263268
264269inline void FutureBase::Release () {
265- std::lock_guard<std::mutex> lock (mutex_);
270+ MutexLock lock (mutex_);
266271 if (api_ != NULL ) { // NOLINT
267272 detail::UnregisterForCleanup (api_, this );
268273 api_->ReleaseFuture (handle_);
@@ -271,30 +276,30 @@ inline void FutureBase::Release() {
271276}
272277
273278inline FutureStatus FutureBase::status () const {
274- std::lock_guard<std::mutex> lock (mutex_);
279+ MutexLock lock (mutex_);
275280 return api_ == NULL ? // NOLINT
276281 kFutureStatusInvalid
277282 : api_->GetFutureStatus (handle_);
278283}
279284
280285inline int FutureBase::error () const {
281- std::lock_guard<std::mutex> lock (mutex_);
286+ MutexLock lock (mutex_);
282287 return api_ == NULL ? -1 : api_->GetFutureError (handle_); // NOLINT
283288}
284289
285290inline const char * FutureBase::error_message () const {
286- std::lock_guard<std::mutex> lock (mutex_);
291+ MutexLock lock (mutex_);
287292 return api_ == NULL ? NULL : api_->GetFutureErrorMessage (handle_); // NOLINT
288293}
289294
290295inline const void * FutureBase::result_void () const {
291- std::lock_guard<std::mutex> lock (mutex_);
296+ MutexLock lock (mutex_);
292297 return api_ == NULL ? NULL : api_->GetFutureResult (handle_); // NOLINT
293298}
294299
295300inline void FutureBase::OnCompletion (CompletionCallback callback,
296301 void * user_data) const {
297- std::lock_guard<std::mutex> lock (mutex_);
302+ MutexLock lock (mutex_);
298303 if (api_ != NULL ) { // NOLINT
299304 api_->AddCompletionCallback (handle_, callback, user_data, nullptr ,
300305 /* clear_existing_callbacks=*/ true );
@@ -304,7 +309,7 @@ inline void FutureBase::OnCompletion(CompletionCallback callback,
304309#if defined(INTERNAL_EXPERIMENTAL)
305310inline FutureBase::CompletionCallbackHandle FutureBase::AddOnCompletion (
306311 CompletionCallback callback, void * user_data) const {
307- std::lock_guard<std::mutex> lock (mutex_);
312+ MutexLock lock (mutex_);
308313 if (api_ != NULL ) { // NOLINT
309314 return api_->AddCompletionCallback (handle_, callback, user_data, nullptr ,
310315 /* clear_existing_callbacks=*/ false );
@@ -314,7 +319,7 @@ inline FutureBase::CompletionCallbackHandle FutureBase::AddOnCompletion(
314319
315320inline void FutureBase::RemoveOnCompletion (
316321 CompletionCallbackHandle completion_handle) const {
317- std::lock_guard<std::mutex> lock (mutex_);
322+ MutexLock lock (mutex_);
318323 if (api_ != NULL ) { // NOLINT
319324 api_->RemoveCompletionCallback (handle_, completion_handle);
320325 }
@@ -324,7 +329,7 @@ inline void FutureBase::RemoveOnCompletion(
324329#if defined(FIREBASE_USE_STD_FUNCTION)
325330inline void FutureBase::OnCompletion (
326331 std::function<void (const FutureBase&)> callback) const {
327- std::lock_guard<std::mutex> lock (mutex_);
332+ MutexLock lock (mutex_);
328333 if (api_ != NULL ) { // NOLINT
329334 api_->AddCompletionCallbackLambda (handle_, callback,
330335 /* clear_existing_callbacks=*/ true );
@@ -334,7 +339,7 @@ inline void FutureBase::OnCompletion(
334339#if defined(INTERNAL_EXPERIMENTAL)
335340inline FutureBase::CompletionCallbackHandle FutureBase::AddOnCompletion (
336341 std::function<void (const FutureBase&)> callback) const {
337- std::lock_guard<std::mutex> lock (mutex_);
342+ MutexLock lock (mutex_);
338343 if (api_ != NULL ) { // NOLINT
339344 return api_->AddCompletionCallbackLambda (
340345 handle_, callback,
0 commit comments