MT#63171 AmSessionProcessorThread: replace runcond

Use AmMutex facilities to protect members dictating whether to run or
not. Replaces `runcond`, `process_sessions_mut`, and ::on_stop().

Remove redundant wake-up.

Change-Id: I75c5c4ff2be2b66b36c7354c1e127bc4f5d9993c
mr13.5
Richard Fuchs 1 year ago
parent f9b93e343a
commit cbb5a3a3bf

@ -85,7 +85,7 @@ void AmSessionProcessor::stopThreads()
AmSessionProcessorThread::AmSessionProcessorThread()
: events(this), runcond(false)
: events(this)
{
}
@ -93,27 +93,27 @@ AmSessionProcessorThread::~AmSessionProcessorThread() {
}
void AmSessionProcessorThread::notify(AmEventQueue* sender) {
process_sessions_mut.lock();
runcond.set(true);
run_mut.lock();
process_sessions.insert(sender);
process_sessions_mut.unlock();
run_mut.unlock();
run_cond.notify_all();
}
void AmSessionProcessorThread::run() {
std::unique_lock<std::mutex> _l(run_mut);
while (!stop_requested()) {
while (!stop_requested_unlocked()) {
runcond.wait_for();
if (process_sessions.empty())
run_cond.wait(_l);
DBG("running processing loop\n");
process_sessions_mut.lock();
runcond.set(false);
// get the list of session s that need processing
std::set<AmEventQueue*> pending_process_sessions
= process_sessions;
process_sessions.clear();
process_sessions_mut.unlock();
_l.unlock();
// process control events (AmSessionProcessorThreadAddEvent)
events.processEvents();
@ -166,11 +166,9 @@ void AmSessionProcessorThread::run() {
(*it)->finalize();
}
}
}
}
void AmSessionProcessorThread::on_stop() {
runcond.set(true);
_l.lock();
}
}
// AmEventHandler interface
@ -195,9 +193,6 @@ void AmSessionProcessorThread::startSession(AmSession* s) {
// trigger processing of events already in queue at startup
notify(s);
// wakeup the thread
runcond.set(true);
}
#endif

@ -70,9 +70,7 @@ class AmSessionProcessorThread
std::list<AmSession*> sessions;
std::vector<AmSession*> startup_sessions;
AmCondition runcond;
std::set<AmEventQueue*> process_sessions;
AmMutex process_sessions_mut;
// AmEventHandler interface
void process(AmEvent* e);
@ -83,7 +81,6 @@ class AmSessionProcessorThread
// AmThread interface
void run();
void on_stop();
// AmEventNotificationSink interface
void notify(AmEventQueue* sender);

Loading…
Cancel
Save