Skip to content

Commit 2c28251

Browse files
smilesa-maurice
authored andcommitted
Added option to shutdown Scheduler before destruction.
PiperOrigin-RevId: 248384183
1 parent 1573001 commit 2c28251

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/src/scheduler.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,14 @@ Scheduler::Scheduler()
7272
}
7373

7474
Scheduler::~Scheduler() {
75+
CancelAllAndShutdownWorkerThread();
76+
}
77+
78+
void Scheduler::CancelAllAndShutdownWorkerThread() {
7579
{
76-
// Notify the worker thread to stop processing anymore request
80+
// Notify the worker thread to stop processing anymore requests.
7781
MutexLock lock(request_mutex_);
82+
if (terminating_) return;
7883
terminating_ = true;
7984
}
8085

app/src/scheduler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class Scheduler {
123123
ScheduleTimeMs delay = 0, ScheduleTimeMs repeat = 0);
124124
#endif // FIREBASE_USE_STD_FUNCTION
125125

126+
// Cancel all scheduled callbacks and shut down the worker thread.
127+
void CancelAllAndShutdownWorkerThread();
128+
126129
private:
127130
typedef uint64_t RequestId;
128131
// The request data for all scheduled callback.

0 commit comments

Comments
 (0)