The Pedigree Project  0.1
initialiseMultitasking.cc
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 #if defined(THREADS)
21 
22 #include "pedigree/kernel/process/initialiseMultitasking.h"
23 #include "pedigree/kernel/process/PerProcessorScheduler.h"
24 #include "pedigree/kernel/process/Process.h"
25 #include "pedigree/kernel/process/Scheduler.h"
26 #include "pedigree/kernel/process/Thread.h"
27 #include "pedigree/kernel/processor/Processor.h"
28 #include "pedigree/kernel/processor/ProcessorInformation.h"
29 #include "pedigree/kernel/utilities/StaticString.h"
30 #include "pedigree/kernel/utilities/new"
31 
32 void initialiseMultitasking()
33 {
34  // Create the kernel idle process.
35  Process *pProcess = new Process();
36  pProcess->resetCounts();
37  pProcess->description() += "Kernel Process";
38 
39 #ifdef MULTIPROCESSOR
40  pProcess->description() += " - Processor #";
41  pProcess->description() += Processor::id();
42 #endif
43 
44  // Create the main kernel thread.
45  Thread *pThread = new Thread(pProcess);
46  pThread->detach();
47 
48  // Initialise the scheduler.
49  Scheduler::instance().initialise(pProcess);
50 
51  // Initialise the per-process scheduler.
52  Processor::information().getScheduler().initialise(pThread);
53 }
54 
55 void shutdownMultitasking()
56 {
59 }
60 
61 #ifdef MULTIPROCESSOR
62 void initialiseMultitaskingPerProcessor()
63 {
64  // Create the kernel idle process.
65  Process *pProcess = new Process();
66  pProcess->description() += "Kernel Process";
67 
68  pProcess->description() += " - Processor #";
69  pProcess->description() += Processor::id();
70 
71  // Create the kernel idle thread.
72  Thread *pThread = new Thread(pProcess);
73  pThread->detach();
74  Processor::information().getScheduler().initialise(pThread);
75 }
76 #endif
77 
78 #endif
static ProcessorInformation & information()
Definition: Processor.cc:45
static Scheduler & instance()
Definition: Scheduler.h:48
static ProcessorId id()
Definition: Processor.cc:40
Definition: Thread.h:54
LargeStaticString & description()
Definition: Process.h:114
bool detach()
Definition: Thread.cc:885
bool initialise(Process *pKernelProcess)
Definition: Scheduler.cc:51