Mark3 Realtime Kernel
atomic.h
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 #pragma once
22 
23 #include "kerneltypes.h"
24 #include "mark3cfg.h"
25 #include "ithreadport.h"
26 #include "kerneldebug.h"
27 
28 namespace Mark3
29 {
38 namespace Atomic
39 {
47  template <typename T> T Set(T* pSource_, T val_)
48  {
49  KERNEL_ASSERT(nullptr != pSource_);
50 
51  const auto cs = CriticalGuard{};
52  auto ret = *pSource_;
53  *pSource_ = val_;
54  return ret;
55  }
56 
64  template <typename T> T Add(T* pSource_, T val_)
65  {
66  KERNEL_ASSERT(nullptr != pSource_);
67 
68  const auto cs = CriticalGuard{};
69  auto ret = *pSource_;
70  *pSource_ += val_;
71  return ret;
72  }
73 
81  template <typename T> T Sub(T* pSource_, T val_)
82  {
83  KERNEL_ASSERT(nullptr != pSource_);
84 
85  const auto cs = CriticalGuard{};
86  auto ret = *pSource_;
87  *pSource_ -= val_;
88  return ret;
89  }
90 
106  bool TestAndSet(bool* pbLock);
107 } // namespace Atomic
108 } // namespace Mark3
Basic data type primatives used throughout the OS.
Thread porting interface.
T Set(T *pSource_, T val_)
Set Set a variable to a given value in an uninterruptable operation.
Definition: atomic.h:47
#define KERNEL_ASSERT(x)
Definition: kerneldebug.h:36
Definition: atomic.cpp:23
Mark3 Kernel Configuration This file is used to configure the kernel for your specific application in...
Macros and functions used for assertions, kernel traces, etc.
bool TestAndSet(bool *pbLock)
TestAndSet Test to see if a variable is set, and set it if is not already set. This is an uninterrupt...
Definition: atomic.cpp:26
The CriticalGuard class. This class provides an implemention of RAII for critical sections...
Definition: criticalguard.h:38
T Sub(T *pSource_, T val_)
Sub Subtract a value from a variable in an uninterruptable operation.
Definition: atomic.h:81
T Add(T *pSource_, T val_)
Add Add a value to a variable in an uninterruptable operation.
Definition: atomic.h:64