The Pedigree Project  0.1
Scheduler.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 SCHEDULER_H
21 #define SCHEDULER_H
22 
23 #include "pedigree/kernel/Atomic.h"
24 #include "pedigree/kernel/Spinlock.h"
25 #include "pedigree/kernel/compiler.h"
26 #include "pedigree/kernel/processor/types.h"
27 #include "pedigree/kernel/utilities/List.h"
28 #include "pedigree/kernel/utilities/Tree.h"
29 #include "pedigree/kernel/utilities/new"
30 
31 class Thread;
32 class Process;
34 
45 {
46  public:
48  static Scheduler &instance()
49  {
50  return m_Instance;
51  }
52 
53 #ifdef THREADS
54 
55  bool initialise(Process *pKernelProcess);
56 
60  void addThread(Thread *pThread, PerProcessorScheduler &PPSched);
62  void removeThread(Thread *pThread);
63 
65  bool threadInSchedule(Thread *pThread);
66 
70  size_t addProcess(Process *pProcess);
73  void removeProcess(Process *pProcess);
74 #endif // THREADS
75 
77  void yield();
78 
80  size_t getNumProcesses();
81 
82 #ifdef THREADS
83 
84  Process *getProcess(size_t n);
85 
86  void threadStatusChanged(Thread *pThread);
87 
88  Process *getKernelProcess() const
89  {
90  return m_pKernelProcess;
91  }
92 
93  PerProcessorScheduler *getBootstrapProcessorScheduler() const
94  {
95  return m_pBspScheduler;
96  }
97 #endif // THREADS
98 
99  private:
100  Scheduler();
101  NOT_COPYABLE_OR_ASSIGNABLE(Scheduler);
102 
105 
106 #ifdef THREADS
107 
109 
112 
115 
118 
121 
130 
133 #endif // THREADS
134 };
135 
136 #endif // SCHEDULER_H
PerProcessorScheduler * m_pBspScheduler
Definition: Scheduler.h:129
Process * m_pKernelProcess
Definition: Scheduler.h:120
This class manages how processes and threads are scheduled across processors.
Definition: Scheduler.h:44
Tree< PerProcessorScheduler *, List< Thread * > * > m_PTMap
Definition: Scheduler.h:114
static Scheduler m_Instance
Definition: Scheduler.h:104
Atomic< size_t > m_NextPid
Definition: Scheduler.h:111
A key/value dictionary.
Definition: Tree.h:33
static Scheduler & instance()
Definition: Scheduler.h:48
Tree< Thread *, PerProcessorScheduler * > m_TPMap
Definition: Scheduler.h:117
Definition: Thread.h:54
Spinlock m_SchedulerLock
Definition: Scheduler.h:132
List< Process *, 0 > m_Processes
Definition: Scheduler.h:108