Mark3 Realtime Kernel
blocking.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 ===========================================================================*/
21 #include "mark3.h"
22 
23 namespace Mark3
24 {
25 //---------------------------------------------------------------------------
26 void BlockingObject::Block(Thread* pclThread_)
27 {
28  KERNEL_ASSERT(nullptr != pclThread_);
29 
30  // Remove the thread from its current thread list (the "owner" list)
31  // ... And add the thread to this object's block list
32  Scheduler::Remove(pclThread_);
33  m_clBlockList.Add(pclThread_);
34 
35  // Set the "current" list location to the blocklist for this thread
36  pclThread_->SetCurrent(&m_clBlockList);
37  pclThread_->SetState(ThreadState::Blocked);
38 }
39 
40 //---------------------------------------------------------------------------
42 {
43  KERNEL_ASSERT(nullptr != pclThread_);
44 
45  // Remove the thread from its current thread list (the "owner" list)
46  // ... And add the thread to this object's block list
47  Scheduler::Remove(pclThread_);
48  m_clBlockList.AddPriority(pclThread_);
49 
50  // Set the "current" list location to the blocklist for this thread
51  pclThread_->SetCurrent(&m_clBlockList);
52  pclThread_->SetState(ThreadState::Blocked);
53 }
54 
55 //---------------------------------------------------------------------------
57 {
58  KERNEL_ASSERT(nullptr != pclThread_);
59 
60  // Remove the thread from its current thread list (the "owner" list)
61  pclThread_->GetCurrent()->Remove(pclThread_);
62 
63  // Put the thread back in its active owner's list. This is usually
64  // the ready-queue at the thread's original priority.
65  Scheduler::Add(pclThread_);
66 
67  // Tag the thread's current list location to its owner
68  pclThread_->SetCurrent(pclThread_->GetOwner());
69  pclThread_->SetState(ThreadState::Ready);
70 }
71 } // namespace Mark3
static void Add(Thread *pclThread_)
Add Add a thread to the scheduler at its current priority level.
Definition: scheduler.cpp:59
ThreadList * GetOwner(void)
GetOwner Return the ThreadList where the thread belongs when it's in the active/ready state in the sc...
Definition: thread.h:159
void UnBlock(Thread *pclThread_)
UnBlock Unblock a thread that is already blocked on this object, returning it to the "ready" state by...
Definition: blocking.cpp:56
void SetState(ThreadState eState_)
SetState Set the thread's state to a new value. This is only to be used by code within the kernel...
Definition: thread.h:397
#define KERNEL_ASSERT(x)
Definition: kerneldebug.h:36
void BlockPriority(Thread *pclThread_)
BlockPriority Same as Block(), but ensures that threads are added to the block-list in priority-order...
Definition: blocking.cpp:41
void Block(Thread *pclThread_)
Block Blocks a thread on this object. This is the fundamental operation performed by any sort of bloc...
Definition: blocking.cpp:26
void Remove(Thread *node_)
Remove Remove the specified thread from the threadlist.
Definition: threadlist.cpp:111
Definition: atomic.cpp:23
Single include file given to users of the Mark3 Kernel API.
The Thread Class. This object providing the fundamental thread control data structures and functions ...
Definition: thread.h:64
void SetCurrent(ThreadList *pclNewList_)
SetCurrent. Set the thread's current to the specified thread list.
Definition: thread.h:206
void AddPriority(Thread *node_)
AddPriority Add a thread to the list such that threads are ordered from highest to lowest priority fr...
Definition: threadlist.cpp:66
void Add(Thread *node_)
Add Add a thread to the threadlist.
Definition: threadlist.cpp:47
ThreadList * GetCurrent(void)
GetCurrent Return the ThreadList where the thread is currently located.
Definition: thread.h:166
ThreadList m_clBlockList
Definition: blocking.h:133
static void Remove(Thread *pclThread_)
Remove Remove a thread from the scheduler at its current priority level.
Definition: scheduler.cpp:67