The Pedigree Project  0.1
RoundRobinCoreAllocator.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 #include "pedigree/kernel/process/RoundRobinCoreAllocator.h"
21 #include "pedigree/kernel/Log.h"
22 #include "pedigree/kernel/utilities/Iterator.h"
23 #include "pedigree/kernel/utilities/utility.h"
24 
26 class Thread;
27 
28 RoundRobinCoreAllocator::RoundRobinCoreAllocator() : m_ProcMap(), m_pNext(0)
29 {
30 }
31 
32 RoundRobinCoreAllocator::~RoundRobinCoreAllocator()
33 {
34 }
35 
36 bool RoundRobinCoreAllocator::initialise(
38 {
40  PerProcessorScheduler *pFirst = m_pNext = *it;
41  it++;
42 
43  // 1 CPU?
44  if (it == procList.end())
45  {
46  NOTICE("Quitting, only one CPU was present.");
47  m_ProcMap.insert(pFirst, pFirst);
48  return true;
49  }
50 
51  for (; it != procList.end(); it++)
52  {
53  m_ProcMap.insert(pFirst, *it);
54  pFirst = *it;
55  }
56 
57  // Loop.
58  m_ProcMap.insert(pFirst, m_pNext);
59 
60  return true;
61 }
62 
63 PerProcessorScheduler *RoundRobinCoreAllocator::allocateThread(Thread *pThread)
64 {
65  PerProcessorScheduler *pReturn = m_ProcMap.lookup(m_pNext);
66  m_pNext = pReturn;
67  return pReturn;
68 }
Definition: List.h:64
#define NOTICE(text)
Definition: Log.h:74
::Iterator< T, node_t > Iterator
Definition: List.h:71
Iterator begin()
Definition: List.h:123
Definition: Thread.h:54
Iterator end()
Definition: List.h:135