Mark3 Realtime Kernel
quantum.cpp
Go to the documentation of this file.
1 /*===========================================================================
2  _____ _____ _____ _____
3  ___| _|__ __|_ |__ __|__ |__ __| __ |__ ______
4 | \ / | || \ || | || |/ / ||___ |
5 | \/ | || \ || \ || \ ||___ |
6 |__/\__/|__|_||__|\__\ __||__|\__\ __||__|\__\ __||______|
7  |_____| |_____| |_____| |_____|
8 
9 --[Mark3 Realtime Platform]--------------------------------------------------
10 
11 Copyright (c) 2012 - 2019 m0slevin, all rights reserved.
12 See license.txt for more information
13 ===========================================================================*/
22 #include "mark3.h"
23 
24 #if KERNEL_ROUND_ROBIN
25 namespace Mark3
26 {
27 //---------------------------------------------------------------------------
32 
33 //---------------------------------------------------------------------------
35 {
36  const auto cs = CriticalGuard{};
37  m_bInTimer = true;
38 
39  // Timer is active
40  if (m_u16TicksRemain) {
42  }
43 }
44 
45 //---------------------------------------------------------------------------
47 {
48  const auto cs = CriticalGuard{};
49  m_bInTimer = false;
50 
51  // Timer expired - Pivot the thread list.
53  auto* pclThreadList = m_pclActiveThread->GetCurrent();
54  if (pclThreadList->GetHead() != pclThreadList->GetTail()) {
55  pclThreadList->PivotForward();
56  }
57  m_pclActiveThread = nullptr;
58  }
59 }
60 
61 //---------------------------------------------------------------------------
62 void Quantum::Update(Thread* pclTargetThread_)
63 {
64  // Don't cancel the current RR interval if we're being interrupted by
65  // the timer thread, or are in the middle of running the timer thread.
66  // OR if the thread list only has one thread
67  auto* pclThreadList = pclTargetThread_->GetCurrent();
68  if ((pclThreadList->GetHead() == pclThreadList->GetTail()) || (pclTargetThread_ == m_pclTimerThread)
69  || (pclTargetThread_ == m_pclActiveThread) || m_bInTimer) {
70  return;
71  }
72 
73  // Update with a new thread and timeout.
74  m_pclActiveThread = pclTargetThread_;
75  m_u16TicksRemain = pclTargetThread_->GetQuantum();
76 }
77 
78 //---------------------------------------------------------------------------
79 void Quantum::Cancel()
80 {
81  m_pclActiveThread = nullptr;
82  m_u16TicksRemain = 0;
83 }
84 } // namespace Mark3
85 #endif // #if KERNEL_ROUND_ROBIN
static void Update(Thread *pclTargetThread_)
Update Update the current thread being tracked for round-robing scheduling. Note - this has no effect...
static Thread * m_pclTimerThread
Definition: quantum.h:88
Definition: atomic.cpp:23
static void SetInTimer()
SetInTimer Set a flag to indicate that the CPU is currently running within the timer-callback routine...
static uint16_t m_u16TicksRemain
Definition: quantum.h:89
Single include file given to users of the Mark3 Kernel API.
static void ClearInTimer()
ClearInTimer Clear the flag once the timer callback function has been completed.
static void Cancel()
static bool m_bInTimer
Definition: quantum.h:90
ThreadList * GetCurrent(void)
GetCurrent Return the ThreadList where the thread is currently located.
Definition: thread.h:166
static Thread * m_pclActiveThread
Definition: quantum.h:87