The Pedigree Project  0.1
PerProcessorScheduler.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef PERPROCESSORSCHEDULER_H
21 #define PERPROCESSORSCHEDULER_H
22 
23 #ifdef THREADS
24 
25 #include "pedigree/kernel/compiler.h"
26 #include "pedigree/kernel/machine/TimerHandler.h"
27 #include "pedigree/kernel/process/ConditionVariable.h"
28 #include "pedigree/kernel/process/Mutex.h"
29 #include "pedigree/kernel/process/Thread.h"
30 #include "pedigree/kernel/processor/state_forward.h"
31 #include "pedigree/kernel/processor/types.h"
32 #include "pedigree/kernel/utilities/List.h"
33 
35 class Spinlock;
36 
38 {
39  public:
43 
45 
47  void initialise(Thread *pThread);
48 
55  void schedule(
56  Thread::Status nextStatus = Thread::Ready, Thread *pNewThread = 0,
57  Spinlock *pLock = 0);
58 
62  void checkEventState(uintptr_t userStack);
63 
66  void eventHandlerReturned() NORETURN;
67 
74  void addThread(
75  Thread *pThread, Thread::ThreadStartFunc pStartFunction, void *pParam,
76  bool bUsermode, void *pStack);
77 
81  void addThread(Thread *pThread, SyscallState &state);
82 
85  void killCurrentThread(Spinlock *pLock = 0) NORETURN;
86 
92  void sleep(Spinlock *pLock = 0);
93 
95  void timer(uint64_t delta, InterruptState &state);
96 
97  void removeThread(Thread *pThread);
98 
99  void threadStatusChanged(Thread *pThread);
100 
101  void setIdle(Thread *pThread);
102 
103  private:
109  PerProcessorScheduler &operator=(const PerProcessorScheduler &);
110 
115  static void deleteThreadThenRestoreState(
116  Thread *pThread, SchedulerState &newState,
117  volatile uintptr_t *pLock = 0) NORETURN;
118 
119  static void deleteThread(Thread *pThread);
120 
123 
124  Mutex m_NewThreadDataLock;
125  ConditionVariable m_NewThreadDataCondition;
126 
127  List<void *> m_NewThreadData;
128 
129  static int processorAddThread(void *instance) NORETURN;
130 
131  Thread *m_pIdleThread;
132 
133 #ifdef ARM_BEAGLE
134  size_t m_TickCount;
135 #endif
136 };
137 
138 #endif
139 
140 #endif
Definition: Mutex.h:58
Status
Definition: Thread.h:62
virtual void timer(uint64_t delta, InterruptState &state)=0
Definition: Thread.h:54
int(* ThreadStartFunc)(void *)
Definition: Thread.h:93
SchedulingAlgorithm * m_pSchedulingAlgorithm