Skip to content

Commit

Permalink
Addin SetDynamicNice for highest performance on threads
Browse files Browse the repository at this point in the history
  • Loading branch information
solariun committed Jan 30, 2022
1 parent b244da0 commit 950908d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AtomicX

Version 1.2.0 release
Version 1.2.1 release

![image](https://user-images.githubusercontent.com/1805792/125191254-6591cf80-e239-11eb-9e89-d7500e793cd4.png)

Expand All @@ -10,6 +10,10 @@ What is AtomicX? AtomicX is a general purpose **cooperative** thread lib for emb

## Implementations from Work on progress

## Version 1.2.1

* Adding Dynamic Nice, now it is possible to let the kernel set the best performance for your thread, for this `SetNice(*initial nice*)` and than `SetDynamicNice(true)` in the constructor of your thread. The kernel will be able to always adjust your thread for Best performance, but, it will leave no room for sleeps between threads, increasing power consumption, it is powerful but use it carefully.

* Added `YieldNow()` the higher priority context change, it will allow other threads to work, but will, also return faster than others

* **`smartSemaphore`**, Used to compliance with RII, once used in the thread context, it takes a semaphore to be initialized and expose the same methods, although it manages the local context, and ones it it gets out of context, due to leaving {} or a functions, for example the semaphore shared context is released if ever taken during the smartSemaphore instantiated object life cycle. The same is available for `mutex`, called `smartMutex`, follows the same principle.
Expand All @@ -18,7 +22,7 @@ What is AtomicX? AtomicX is a general purpose **cooperative** thread lib for emb

* Introducing `atomicx::Timeout`, this will help tracking a timeout over time, using methods `IsTimedout` and `GetRemaining` and `GetDurationSince`. Special use case, if the timeout value is zero, IsTimedout will always return false.

* **IMPORTAT NOTIFICATION** `atomicx::lock` has been renamed to `atomicx::mutex` for consistency, all methods are the same.
* **IMPORTANT NOTIFICATION** `atomicx::lock` has been renamed to `atomicx::mutex` for consistency, all methods are the same.

* **Improvement** Added a contructor for self-manager start to define a start size and increase pace. For example: a thread starts with 150 bytes and increase pace of 10, but used stack was 200, the kernel will do 200 + 10 (increase pace) to give it room to work. The default value is (1)
```cpp
Expand Down
22 changes: 22 additions & 0 deletions atomicx/atomicx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ namespace thread

ms_pCurrent->m_aStatus = aTypes::running;

if (ms_pCurrent->m_flags.dynamicNice == true)
{
ms_pCurrent->m_nice = ((ms_pCurrent->m_LastUserExecTime) + ms_pCurrent->m_nice) / 2;
}

return true;
}

Expand Down Expand Up @@ -442,8 +447,16 @@ namespace thread
}
}

void atomicx::SetDefaultParameters ()
{
m_flags.autoStack = false;
m_flags.dynamicNice = false;
}

atomicx::atomicx(size_t nStackSize, int nStackIncreasePace) : m_context{}, m_stackSize(nStackSize), m_stackIncreasePace(nStackIncreasePace), m_stack(nullptr)
{
SetDefaultParameters ();

m_flags.autoStack = true;

AddThisThread();
Expand Down Expand Up @@ -840,4 +853,13 @@ namespace thread
return m_stackIncreasePace;
}

void atomicx::SetDynamicNice(bool status)
{
m_flags.dynamicNice = status;
}

bool atomicx::IsDynamicNiceOn()
{
return m_flags.dynamicNice;
}
}
25 changes: 23 additions & 2 deletions atomicx/atomicx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <setjmp.h>

/* Official version */
#define ATOMICX_VERSION "1.2.0"
#define ATOMICX_VERSION "1.2.1"
#define ATOMIC_VERSION_LABEL "AtomicX v" ATOMICX_VERSION " built at " __TIMESTAMP__

using atomicx_time = uint32_t;
Expand Down Expand Up @@ -917,7 +917,7 @@ namespace thread
*/
template<typename T, size_t N> atomicx(T (&stack)[N]) : m_context{}, m_stackSize{N}, m_stack((volatile uint8_t*) stack)
{
m_flags.autoStack = false;
SetDefaultParameters();

AddThisThread();
}
Expand Down Expand Up @@ -985,11 +985,31 @@ namespace thread
*/
void YieldNow (void);

/**
* @brief Set the Dynamic Nice on and off
*
* @param status True for on otherwsize off
*/
void SetDynamicNice(bool status);

/**
* @brief Get Dynamic Nice status
*
* @return true if dynamic nice is on otherwise off
*/
bool IsDynamicNiceOn();

/**
* SPECIAL PRIVATE SECTION FOR HELPER METHODS USED BY PROCTED METHODS
*/
private:

/**
* @brief Set the Default Parameters for constructors
*
*/
void SetDefaultParameters ();

template<typename T> void SetWaitParammeters (T& refVar, size_t nTag=0, aSubTypes asubType = aSubTypes::wait)
{
m_TopicId = 0;
Expand Down Expand Up @@ -1642,6 +1662,7 @@ namespace thread
struct
{
bool autoStack : 1;
bool dynamicNice : 1;
} m_flags = {};
};
}
Expand Down
6 changes: 5 additions & 1 deletion examples/Arduino/ThermalCameraDemo/ThermalCameraDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,11 @@ public:
TextScroller (atomicx_time nNice) : atomicx(m_stack), nNumberDigits (MAX_LED_MATRIX), nOffset (0), nSpeed (2)
{
nIndex = (nSpeed == 0) ? nNumberDigits * (-1) : 0;

SetNice (nNice);

SetDynamicNice(true);

strMatrixText.concat (F("Welcome to AtomicX Thermal Camera demo."));
}

Expand Down Expand Up @@ -438,7 +441,7 @@ protected:
{
vt100::ResetColor ();
Serial.flush ();
Yield (1);
Yield ();
vt100::SetLocation (12-((i) / 8), 1);
Serial.print (F("\e[K"));
Serial.flush ();
Expand Down Expand Up @@ -510,6 +513,7 @@ public:
Serial.flush ();

SetNice (nNice);
SetDynamicNice (true);
}

char* GetName()
Expand Down
1 change: 1 addition & 0 deletions examples/Arduino/simple/simple.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public:
Consumer(uint32_t nNice) : atomicx (::GetStackSize(10), 10)
{
SetNice(nNice);
SetDynamicNice(true);
}

const char* GetName () override
Expand Down

0 comments on commit 950908d

Please sign in to comment.