Skip to content

Commit

Permalink
Bug fix #5: Do not exit from the event loop when there are there are …
Browse files Browse the repository at this point in the history
…post operations in EventLoopImpl::m_post_operations in event_loop_apple_cf.cpp
  • Loading branch information
kspangsege committed May 23, 2016
1 parent 23820db commit 9b2bfdc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/realm/util/event_loop_apple_cf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class DeadlineTimerImpl;

class EventLoopImpl: public EventLoop {
public:
// Number of asynchronous operations in progress (connect, read, write,
// wait)
int_fast64_t num_operations_in_progress = 0;

EventLoopImpl();
Expand Down Expand Up @@ -271,9 +273,19 @@ class EventLoopImpl: public EventLoop {
while (std::unique_ptr<Oper> op = m_completed_operations.pop_front())
op->execute(); // Throws

// Stop event loop if there are no asynchronous operations in progress
// and no post handlers waiting to be transferred from m_post_handlers
// to m_completed_operations
if (num_operations_in_progress == 0) {
CFRunLoopStop(m_cf_run_loop); // Out of work
m_returning = true;
bool no_pending_post_handlers;
{
LockGuard lg(m_mutex);
no_pending_post_handlers = m_completed_operations.empty();
}
if (no_pending_post_handlers) {
CFRunLoopStop(m_cf_run_loop); // Out of work
m_returning = true;
}
}
}

Expand Down

0 comments on commit 9b2bfdc

Please sign in to comment.