From e7dba861fd89792538442cc1b01584f7dabbd4a9 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Tue, 5 Nov 2013 20:28:25 +0100 Subject: [PATCH] kernel: User{Event, Timer}: Use atomic access where necessary --- src/system/kernel/UserEvent.cpp | 19 ++++++++----------- src/system/kernel/UserTimer.cpp | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/system/kernel/UserEvent.cpp b/src/system/kernel/UserEvent.cpp index 16f5aec482..097ea2b07c 100644 --- a/src/system/kernel/UserEvent.cpp +++ b/src/system/kernel/UserEvent.cpp @@ -38,16 +38,13 @@ struct SignalEvent::EventSignal : Signal { void SetUnused() { - fInUse = 0; + // mark not-in-use + atomic_set(&fInUse, 0); } virtual void Handled() { - // mark not-in-use - { - InterruptsSpinLocker _(gSchedulerLock); - fInUse = 0; - } + SetUnused(); Signal::Handled(); } @@ -121,11 +118,12 @@ TeamSignalEvent::Fire() InterruptsSpinLocker locker(gSchedulerLock); status_t error = send_signal_to_team_locked(fTeam, fSignal->Number(), fSignal, B_DO_NOT_RESCHEDULE); + locker.Unlock(); + // There are situations (for certain signals), in which // send_signal_to_team_locked() succeeds without queuing the signal. if (error != B_OK || !fSignal->IsPending()) fSignal->SetUnused(); - locker.Unlock(); return error; } @@ -166,8 +164,6 @@ ThreadSignalEvent::Create(Thread* thread, uint32 signalNumber, int32 signalCode, status_t ThreadSignalEvent::Fire() { - dprintf("THREAD\n"); - if (fSignal->MarkUsed()) return B_BUSY; @@ -177,11 +173,12 @@ ThreadSignalEvent::Fire() InterruptsSpinLocker locker(gSchedulerLock); status_t error = send_signal_to_thread_locked(fThread, fSignal->Number(), fSignal, B_DO_NOT_RESCHEDULE); + locker.Unlock(); + // There are situations (for certain signals), in which // send_signal_to_team_locked() succeeds without queuing the signal. if (error != B_OK || !fSignal->IsPending()) fSignal->SetUnused(); - locker.Unlock(); return error; } @@ -233,7 +230,7 @@ void CreateThreadEvent::DoDPC(DPCQueue* queue) { // We're no longer queued in the DPC queue, so we can be reused. - fPendingDPC = 0; + atomic_set(&fPendingDPC, 0); // create the thread thread_id threadID = thread_create_thread(fCreationAttributes, false); diff --git a/src/system/kernel/UserTimer.cpp b/src/system/kernel/UserTimer.cpp index 05208cf1f8..6c04125774 100644 --- a/src/system/kernel/UserTimer.cpp +++ b/src/system/kernel/UserTimer.cpp @@ -287,9 +287,9 @@ UserTimer::CancelTimer() { ASSERT(fScheduled); - fSkip = 1; + atomic_set(&fSkip, 1); cancel_timer(&fTimer); - fSkip = 0; + atomic_set(&fSkip, 0); }