kernel: Remove gSchedulerLock

* Thread::scheduler_lock protects thread state, priority, etc.
 * sThreadCreationLock protects thread creation and removal and list of
   threads in team.
 * Team::signal_lock and Team::time_lock protect list of threads in team
   as well.
 * Scheduler uses its own internal locking.
This commit is contained in:
Pawel Dziepak
2013-11-08 02:41:26 +01:00
parent 72addc62e0
commit 03fb2d8868
21 changed files with 182 additions and 178 deletions
+10 -17
View File
@@ -56,19 +56,13 @@ public:
void Publish(const void* object,
const char* objectType);
void Unpublish(bool schedulerLocked = false);
void Unpublish();
inline void NotifyOne(bool schedulerLocked = false,
status_t result = B_OK);
inline void NotifyAll(bool schedulerLocked = false,
status_t result = B_OK);
inline void NotifyOne(status_t result = B_OK);
inline void NotifyAll(status_t result = B_OK);
static void NotifyOne(const void* object,
bool schedulerLocked = false,
status_t result = B_OK);
static void NotifyAll(const void* object,
bool schedulerLocked = false,
status_t result = B_OK);
static void NotifyOne(const void* object, status_t result);
static void NotifyAll(const void* object, status_t result);
// (both methods) caller must ensure that
// the variable is not unpublished
// concurrently
@@ -86,8 +80,7 @@ public:
void Dump() const;
private:
void _Notify(bool all, bool schedulerLocked,
status_t result);
void _Notify(bool all, status_t result);
void _NotifyLocked(bool all, status_t result);
protected:
@@ -124,16 +117,16 @@ ConditionVariableEntry::~ConditionVariableEntry()
inline void
ConditionVariable::NotifyOne(bool schedulerLocked, status_t result)
ConditionVariable::NotifyOne(status_t result)
{
_Notify(false, schedulerLocked, result);
_Notify(false, result);
}
inline void
ConditionVariable::NotifyAll(bool schedulerLocked, status_t result)
ConditionVariable::NotifyAll(status_t result)
{
_Notify(true, schedulerLocked, result);
_Notify(true, result);
}
+8 -11
View File
@@ -24,15 +24,13 @@ typedef enum scheduler_mode {
SCHEDULER_MODE_COUNT
} scheduler_mode;
extern spinlock gSchedulerLock;
#ifdef __cplusplus
extern "C" {
#endif
/*! Enqueues the thread in the ready-to-run queue.
The caller must hold the scheduler lock (with disabled interrupts).
The caller must hold the enqueued thread \c scheduler_lock.
*/
void scheduler_enqueue_in_run_queue(Thread* thread);
@@ -42,15 +40,14 @@ void scheduler_enqueue_in_run_queue(Thread* thread);
If it's the same thread, the thread will just continue to run.
In either case, unless the thread is dead or is sleeping/waiting
indefinitely, the function will eventually return.
The caller must hold the scheduler lock (with disabled interrupts).
The caller must hold the current thread \c scheduler_lock.
*/
void scheduler_reschedule(void);
/*! Sets the given thread's priority.
The thread may be running or may be in the ready-to-run queue.
The caller must hold the scheduler lock (with disabled interrupts).
*/
void scheduler_set_thread_priority(Thread* thread, int32 priority);
int32 scheduler_set_thread_priority(Thread* thread, int32 priority);
/*! Called when the Thread structure is first created.
Per-thread housekeeping resources can be allocated.
@@ -61,7 +58,6 @@ status_t scheduler_on_thread_create(Thread* thread, bool idleThread);
/*! Called when a Thread structure is initialized and made ready for
use.
The per-thread housekeeping data structures are reset, if needed.
The caller must hold the scheduler lock (with disabled interrupts).
*/
void scheduler_on_thread_init(Thread* thread);
@@ -75,8 +71,6 @@ void scheduler_on_thread_destroy(Thread* thread);
/*! Called in the early boot process to start thread scheduling on the
current CPU.
The function is called once for each CPU.
Interrupts must be disabled, but the caller must not hold the scheduler
lock.
*/
void scheduler_start(void);
@@ -122,11 +116,14 @@ scheduler_reschedule_if_necessary()
{
if (are_interrupts_enabled()) {
cpu_status state = disable_interrupts();
acquire_spinlock(&gSchedulerLock);
Thread* thread = get_cpu_struct()->running_thread;
acquire_spinlock(&thread->scheduler_lock);
scheduler_reschedule_if_necessary_locked();
release_spinlock(&gSchedulerLock);
release_spinlock(&thread->scheduler_lock);
restore_interrupts(state);
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ struct SchedulerListener : DoublyLinkedListLinkImpl<SchedulerListener> {
typedef DoublyLinkedList<SchedulerListener> SchedulerListenerList;
extern SchedulerListenerList gSchedulerListeners;
// guarded by the thread spinlock
extern spinlock gSchedulerListenersLock;
template<typename Parameter1>
+1 -1
View File
@@ -46,7 +46,7 @@ thread_id load_image_etc(int32 argCount, const char* const* args,
const char* const* env, int32 priority, team_id parentID, uint32 flags);
void team_set_job_control_state(Team* team, job_control_state newState,
Signal* signal, bool threadsLocked);
Signal* signal);
void team_set_controlling_tty(int32 index);
int32 team_get_controlling_tty();
status_t team_set_foreground_process_group(int32 ttyIndex, pid_t processGroup);
+3
View File
@@ -69,6 +69,9 @@ public:
using BKernel::ThreadCreationAttributes;
extern spinlock gThreadCreationLock;
#ifdef __cplusplus
extern "C" {
#endif
+5 -5
View File
@@ -243,10 +243,10 @@ struct Team : TeamThreadIteratorEntry<team_id>, KernelReferenceable,
struct job_control_entry* job_control_entry;
VMAddressSpace *address_space;
Thread *main_thread; // protected by fLock and the scheduler
// lock (and the thread's lock), immutable
Thread *main_thread; // protected by fLock, immutable
// after first set
Thread *thread_list; // protected by fLock and the scheduler lock
Thread *thread_list; // protected by fLock, signal_lock and
// gThreadCreationLock
struct team_loading_info *loading_info; // protected by fLock
struct list image_list; // protected by sImageMutex
struct list watcher_list;
@@ -270,8 +270,7 @@ struct Team : TeamThreadIteratorEntry<team_id>, KernelReferenceable,
bigtime_t cpu_clock_offset;
spinlock time_lock;
// user group information; protected by fLock, the *_uid/*_gid fields also
// by the scheduler lock
// user group information; protected by fLock
uid_t saved_set_uid;
uid_t real_uid;
uid_t effective_uid;
@@ -430,6 +429,7 @@ struct Thread : TeamThreadIteratorEntry<thread_id>, KernelReferenceable,
struct cpu_ent *previous_cpu; // protected by scheduler lock
int32 pinned_to_cpu; // only accessed by this thread or in the
// scheduler, when thread is not running
spinlock scheduler_lock;
sigset_t sig_block_mask; // protected by team->signal_lock,
// only modified by the thread itself