Don't delete the waiter until we have finished accessing the dispatcher

implementation, just in case the waiter's handler owns the dispatcher.
This commit is contained in:
chris 2004-03-23 02:29:55 +00:00
parent 2383eb2407
commit ff4d9aa0df

View File

@ -141,18 +141,35 @@ public:
void operator()() void operator()()
{ {
do_upcall(); do_upcall();
detail::mutex::scoped_lock lock(impl_.mutex_); detail::mutex::scoped_lock lock(impl_.mutex_);
waiter_base* tmp = impl_.first_waiter_; waiter_base* tmp = impl_.first_waiter_;
impl_.first_waiter_ = impl_.first_waiter_->next_; impl_.first_waiter_ = impl_.first_waiter_->next_;
delete tmp;
if (impl_.first_waiter_) if (impl_.first_waiter_)
{ {
lock.unlock(); lock.unlock();
// Ensure the waiter is not deleted until after we have finished
// accessing the dispatcher, since the waiter might indirectly own
// the dispatcher and so destroying the waiter will cause the
// dispatcher to be destroyed.
delete tmp;
// There is more work to do, so post this handler again.
demuxer_.post(*this); demuxer_.post(*this);
} }
else else
{ {
impl_.last_waiter_ = 0; impl_.last_waiter_ = 0;
lock.unlock();
// Ensure the waiter is not deleted until after we have finished
// accessing the dispatcher, since the waiter might indirectly own
// the dispatcher and so destroying the waiter will cause the
// dispatcher to be destroyed.
delete tmp;
} }
} }