1 /* 2 * Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef KERNEL_SCHEDULER_H 7 #define KERNEL_SCHEDULER_H 8 9 10 #include <SupportDefs.h> 11 12 13 struct scheduling_analysis; 14 struct thread; 15 struct SchedulerListener; 16 17 18 struct scheduler_ops { 19 bool (*enqueue_in_run_queue)(struct thread* thread); 20 void (*reschedule)(void); 21 void (*set_thread_priority)(struct thread* thread, int32 priority); 22 // called when the thread structure is first created - 23 // initialization of per-thread housekeeping data structures should 24 // be done here 25 void (*on_thread_create)(struct thread* thread); 26 // called when a thread structure is initialized and made ready for 27 // use - should be used to reset the housekeeping data structures 28 // if needed 29 void (*on_thread_init)(struct thread* thread); 30 // called when a thread structure is freed - freeing up any allocated 31 // mem on the scheduler's part should be done here 32 void (*on_thread_destroy)(struct thread* thread); 33 34 void (*start)(void); 35 }; 36 37 extern struct scheduler_ops* gScheduler; 38 39 #define scheduler_enqueue_in_run_queue(thread) \ 40 gScheduler->enqueue_in_run_queue(thread) 41 #define scheduler_set_thread_priority(thread, priority) \ 42 gScheduler->set_thread_priority(thread, priority) 43 #define scheduler_reschedule() gScheduler->reschedule() 44 #define scheduler_start() gScheduler->start() 45 #define scheduler_on_thread_create(thread) \ 46 gScheduler->on_thread_create(thread) 47 #define scheduler_on_thread_init(thread) \ 48 gScheduler->on_thread_init(thread) 49 #define scheduler_on_thread_destroy(thread) \ 50 gScheduler->on_thread_destroy(thread) 51 52 #ifdef __cplusplus 53 extern "C" { 54 #endif 55 56 void scheduler_add_listener(struct SchedulerListener* listener); 57 void scheduler_remove_listener(struct SchedulerListener* listener); 58 59 void scheduler_init(void); 60 61 status_t _user_analyze_scheduling(bigtime_t from, bigtime_t until, void* buffer, 62 size_t size, struct scheduling_analysis* analysis); 63 64 #ifdef __cplusplus 65 } 66 #endif 67 68 #endif /* KERNEL_SCHEDULER_H */ 69