CorePartition
|
#include <setjmp.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | CpxMsgPayload |
struct | CpxSmartLock |
struct | CpxSubscriptions |
struct | CpxThread |
Macros | |
#define | Cpx_GetStaticContextSize(nStaticThreadSize) (nStaticThreadSize >= sizeof (CpxThread) ? (nStaticThreadSize - sizeof (CpxThread)) : 0) |
Return Context size (Stack Memory page) from a Static Memory size. More... | |
#define | Cpx_GetStaticThreadSize(nStackMaxSize) (sizeof (CpxThread) + nStackMaxSize) |
Return the full Static Thread context in bytes. More... | |
#define | Cpx_Sleep(nDelayTickTime) |
Will set the thread to a special sleep state. More... | |
#define | Cpx_GetStackSize() Cpx_GetStackSizeByID (Cpx_GetID ()) |
Get Current Thread Stack Size. More... | |
#define | Cpx_GetMaxStackSize() Cpx_GetMaxStackSizeByID (Cpx_GetID ()) |
Get Current Thread Total Stack context page size. More... | |
#define | Cpx_GetContexSize() (Cpx_GetContextSizeByID (Cpx_GetID ())) |
Return Full context size from current thread. More... | |
#define | Cpx_GetStatus() Cpx_GetStatusByID (Cpx_GetID ()) |
Get current Thread Status. More... | |
#define | Cpx_GetNice() Cpx_GetNiceByID (Cpx_GetID ()) |
Get Current Thread Nice. More... | |
#define | Cpx_GetLastMomentum() Cpx_GetLastMomentumByID (Cpx_GetID ()) |
Get current Thread Last Momentum. More... | |
#define | Cpx_GetLastDutyCycle() Cpx_GetLastDutyCycleByID (Cpx_GetID ()) |
Get Current Thread DutyCycle. More... | |
#define | Cpx_IsThreadStatic() Cpx_IsThreadStaticByID (Cpx_GetID ()) |
Return if the current thread was statically initiated. More... | |
#define | Cpx_IsBrokerStatic() Cpx_IsThreadStaticByID (Cpx_GetID ()) |
Return if the curremt Thread's Broker interface was statically initiated. More... | |
#define | Cpx_GetStaticBrokerSize(nMaxTopics) (sizeof (CpxSubscriptions) + (sizeof (uint32_t) * ((nMaxTopics <= 1) ? sizeof (uint32_t) : nMaxTopics - 1))) |
Return the size of a static Broker Context Size for a Thread. More... | |
#define | Cpx_GetStaticBrokerMaxTopics(nStaticSubsSize) (nStaticSubsSize <= sizeof (CpxSubscriptions) ? 0 : ((nStaticSubsSize - sizeof (CpxSubscriptions)) / sizeof (uint32_t)) + 1) |
#define | Cpx_NotifyVariableLockOne(nLockID, nStatus) Cpx_NotifyVariableLock (nLockID, nStatus, true) |
Notify one Variable lock waiting for notification. More... | |
#define | Cpx_NotifyVariableLockAll(nLockID, nStatus) Cpx_NotifyVariableLock (nLockID, nStatus, false) |
Notify all Variable lock waiting for notification. More... | |
Typedefs | |
typedef void(* | TopicCallback) (void *pContext, const char *pszTopic, size_t nSize, CpxMsgPayload payLoad) |
typedef struct CpxSubscriptions | CpxSubscriptions |
typedef uint8_t | CpxStaticThread |
typedef uint8_t | CpxStaticBroker |
Enumerations | |
enum | __THREADL_TYPES { THREADL_NONE = 0 , THREADL_STOPPED , THREADL_LOCK , THREADL_WAITTAG , THREADL_RUNNING = 100 , THREADL_START , THREADL_NOW , THREADL_SLEEP = 200 } |
Functions | |
uint32_t | Cpx_GetCurrentTick (void) |
void | Cpx_SleepTicks (uint32_t) |
void | Cpx_StackOverflowHandler (void) |
bool | Cpx_Start (size_t nThreadPartitions) |
Start CorePartition thread provisioning. More... | |
bool | Cpx_StaticStart (CpxThread **ppStaticThread, size_t nStaticThreadSize) |
Start CorePartition thread provisioning. More... | |
bool | Cpx_CreateThread (void(*pFunction)(void *), void *pValue, size_t nStackMaxSize, uint32_t nNice) |
Create a non-Isolated context Thread. More... | |
bool | Cpx_CreateStaticThread (void(*pFunction)(void *), void *pValue, CpxStaticThread *pStaticThread, size_t nStaticThreadSize, uint32_t nNice) |
Create a Thread using a static Context + virtual stack page. More... | |
void | Cpx_Join (void) |
This will start all the threads. More... | |
uint8_t | Cpx_Yield (void) |
Function to be called inside a thread to change context. More... | |
void | Cpx_SetSleep (uint32_t nDelayTickTime) |
Will set the thread sleep parameter before Yield. More... | |
size_t | Cpx_GetID (void) |
Get Current Thread ID. More... | |
size_t | Cpx_GetStackSizeByID (size_t nID) |
Get Current Thread ID. More... | |
size_t | Cpx_GetMaxStackSizeByID (size_t nID) |
Get total size of stack context page for a Thread ID. More... | |
size_t | Cpx_GetStructContextSize (void) |
Get Thread context size. More... | |
size_t | Cpx_GetContextSizeByID (size_t nID) |
Get Full context size (Contex + stack + Broker) More... | |
uint8_t | Cpx_GetStatusByID (size_t nID) |
Get a thread status for a thread ID. More... | |
uint32_t | Cpx_GetNiceByID (size_t nID) |
Current Thread Nice. More... | |
void | Cpx_SetNice (uint32_t nNice) |
Set Current Thread Nice. More... | |
uint32_t | Cpx_GetLastMomentumByID (size_t nID) |
Get Current Thread last momentum on switch back. More... | |
uint32_t | Cpx_GetLastDutyCycleByID (size_t nID) |
Last Duty Cycle of the current Thread. More... | |
size_t | Cpx_GetNumberOfActiveThreads (void) |
Get Number of total active Threads. More... | |
size_t | Cpx_GetNumberOfThreads (void) |
Get Number of assigned Threads. More... | |
size_t | Cpx_GetMaxNumberOfThreads (void) |
Get Max Number of total active Threads. More... | |
char | Cpx_IsSecureByID (size_t nID) |
Return the Secure Status for a thread ID. More... | |
bool | Cpx_IsCoreRunning (void) |
Report if there is any running thread. More... | |
bool | Cpx_IsThreadStaticByID (size_t nID) |
Return if a Threads was statically initiated. More... | |
bool | Cpx_IsBrokerStaticByID (size_t nID) |
Return if a Thread's Broker interface was statically initiated. More... | |
bool | Cpx_EnableBroker (void *pUserContext, uint16_t nMaxTopics, TopicCallback callback) |
Enable Broker for the current thread. More... | |
bool | Cpx_EnableStaticBroker (void *pUserContext, CpxStaticBroker *pStaticBroker, size_t nStaticBrokerSize, TopicCallback callback) |
Enable Broker for the current thread. More... | |
bool | Cpx_SubscribeTopic (const char *pszTopic, size_t length) |
Subscribe for a specific topic. More... | |
bool | Cpx_PublishTopic (const char *pszTopic, size_t length, size_t nAttribute, uint64_t nValue) |
Public a tuple Param and Value. More... | |
bool | Cpx_IsSubscribed (const char *pszTopic, size_t length) |
Check if the current thread already subscribe to a topic. More... | |
bool | Cpx_NotifyOne (const char *pszTag, size_t nTagLength) |
Notify ONE TAG assigned as waiting thread. More... | |
bool | Cpx_NotifyMessageOne (const char *pszTag, size_t nTagLength, size_t nAttribute, uint64_t nValue) |
Notify ONE TAGs assigned as waiting thread with a Message payload. More... | |
bool | Cpx_NotifyAll (const char *pszTag, size_t nTagLength) |
Notify ALL TAGs assigned as waiting thread. More... | |
bool | Cpx_NotifyMessageAll (const char *pszTag, size_t nTagLength, size_t nAttribute, uint64_t nValue) |
Notify ALL TAGs assigned as waiting thread with a Message payload. More... | |
bool | Cpx_Wait (const char *pszTag, size_t nTagLength) |
Wait for a specific notification from a given TAG. More... | |
bool | Cpx_WaitMessage (const char *pszTag, size_t nTagLength, CpxMsgPayload *payload) |
Wait for a specific notification from a given TAG and payload. More... | |
bool | Cpx_LockInit (CpxSmartLock *pLock) |
Init SmartLock variable. More... | |
bool | Cpx_Lock (CpxSmartLock *pLock) |
Do a exclusive Lock and set to Simple lock. More... | |
bool | Cpx_TryLock (CpxSmartLock *pLock) |
Like Lock() but only locks in case it is unlocked. More... | |
bool | Cpx_SharedLock (CpxSmartLock *pLock) |
Can act as multiple locks. More... | |
bool | Cpx_Unlock (CpxSmartLock *pLock) |
Unlock exclusive locks. More... | |
bool | Cpx_SharedUnlock (CpxSmartLock *pLock) |
Unlock shared locks. More... | |
bool | Cpx_WaitVariableLock (void *nLockID, size_t *pnStatus) |
Wait for a Variable Locks notification. More... | |
size_t | Cpx_WaitingVariableLock (void *nLockID) |
Return how much threads are locked waiting for a variable notification. More... | |
size_t | Cpx_NotifyVariableLock (void *nLockID, size_t nStatus, bool bOneOnly) |
Notify all/one Variable lock waiting for notification. More... | |
void * | Cpx_GetLockID (void) |
void * | Cpx_GetLockIDByID (size_t nID) |
#define Cpx_GetContexSize | ( | ) | (Cpx_GetContextSizeByID (Cpx_GetID ())) |
Return Full context size from current thread.
#define Cpx_GetLastDutyCycle | ( | ) | Cpx_GetLastDutyCycleByID (Cpx_GetID ()) |
Get Current Thread DutyCycle.
#define Cpx_GetLastMomentum | ( | ) | Cpx_GetLastMomentumByID (Cpx_GetID ()) |
Get current Thread Last Momentum.
#define Cpx_GetMaxStackSize | ( | ) | Cpx_GetMaxStackSizeByID (Cpx_GetID ()) |
Get Current Thread Total Stack context page size.
#define Cpx_GetNice | ( | ) | Cpx_GetNiceByID (Cpx_GetID ()) |
Get Current Thread Nice.
#define Cpx_GetStackSize | ( | ) | Cpx_GetStackSizeByID (Cpx_GetID ()) |
Get Current Thread Stack Size.
#define Cpx_GetStaticBrokerMaxTopics | ( | nStaticSubsSize | ) | (nStaticSubsSize <= sizeof (CpxSubscriptions) ? 0 : ((nStaticSubsSize - sizeof (CpxSubscriptions)) / sizeof (uint32_t)) + 1) |
#define Cpx_GetStaticBrokerSize | ( | nMaxTopics | ) | (sizeof (CpxSubscriptions) + (sizeof (uint32_t) * ((nMaxTopics <= 1) ? sizeof (uint32_t) : nMaxTopics - 1))) |
Return the size of a static Broker Context Size for a Thread.
nMaxTopics | Max number of Topics (minimal 1, smaller will be automatically set to 1) |
#define Cpx_GetStaticContextSize | ( | nStaticThreadSize | ) | (nStaticThreadSize >= sizeof (CpxThread) ? (nStaticThreadSize - sizeof (CpxThread)) : 0) |
Return Context size (Stack Memory page) from a Static Memory size.
nStaticThreadSize | The size (in bytes) of the stack memory |
#define Cpx_GetStaticThreadSize | ( | nStackMaxSize | ) | (sizeof (CpxThread) + nStackMaxSize) |
Return the full Static Thread context in bytes.
nStackMaxSize | Stack memory page size |
#define Cpx_GetStatus | ( | ) | Cpx_GetStatusByID (Cpx_GetID ()) |
Get current Thread Status.
#define Cpx_IsBrokerStatic | ( | ) | Cpx_IsThreadStaticByID (Cpx_GetID ()) |
Return if the curremt Thread's Broker interface was statically initiated.
nID | Thread ID |
#define Cpx_IsThreadStatic | ( | ) | Cpx_IsThreadStaticByID (Cpx_GetID ()) |
Return if the current thread was statically initiated.
nID | Thread ID |
#define Cpx_NotifyVariableLockAll | ( | nLockID, | |
nStatus | |||
) | Cpx_NotifyVariableLock (nLockID, nStatus, false) |
Notify all Variable lock waiting for notification.
nLockID | LockID size_t used to notify |
nStatus | Payload to be sent, a size_t |
bOneOnly | If true only one is notified |
#define Cpx_NotifyVariableLockOne | ( | nLockID, | |
nStatus | |||
) | Cpx_NotifyVariableLock (nLockID, nStatus, true) |
Notify one Variable lock waiting for notification.
nLockID | LockID size_t used to notify |
nStatus | Payload to be sent, a size_t |
bOneOnly | If true only one is notified |
#define Cpx_Sleep | ( | nDelayTickTime | ) |
Will set the thread to a special sleep state.
nDelayTickTime | How much ticks to sleep |
typedef uint8_t CpxStaticBroker |
typedef uint8_t CpxStaticThread |
typedef struct CpxSubscriptions CpxSubscriptions |
typedef void(* TopicCallback) (void *pContext, const char *pszTopic, size_t nSize, CpxMsgPayload payLoad) |
enum __THREADL_TYPES |
bool Cpx_CreateStaticThread | ( | void(*)(void *) | pFunction, |
void * | pValue, | ||
CpxStaticThread * | pStaticThread, | ||
size_t | nStaticThreadSize, | ||
uint32_t | nNice | ||
) |
Create a Thread using a static Context + virtual stack page.
pFunction | Function (void Function (void* dataPointer)) as thread main |
pValue | data that will be injected on Thread creation |
pStaticThread | The Static context + virtual stack pointer |
nStaticThreadSize | Size of the Static Thread in bytes |
nNice | When in time it is good to be used |
bool Cpx_CreateThread | ( | void(*)(void *) | pFunction, |
void * | pValue, | ||
size_t | nStackMaxSize, | ||
uint32_t | nNice | ||
) |
Create a non-Isolated context Thread.
pFunction | Function (void Function (void* dataPointer)) as thread main |
pValue | data that will be injected on Thread creation |
nStackMaxSize | Size of the Stack to be used |
nNice | When in time it is good to be used |
bool Cpx_EnableBroker | ( | void * | pUserContext, |
uint16_t | nMaxTopics, | ||
TopicCallback | callback | ||
) |
Enable Broker for the current thread.
pUserContext | The default context to be ejected if needed |
nMaxTopics | Max topics to be handled by the current thread |
callback | Call back to be used to process thread Synchronously |
bool Cpx_EnableStaticBroker | ( | void * | pUserContext, |
CpxStaticBroker * | pStaticBroker, | ||
size_t | nStaticBrokerSize, | ||
TopicCallback | callback | ||
) |
Enable Broker for the current thread.
pUserContext | The default context to be ejected if needed |
pStaticBroker | Static Broker CpxSubscriptions pointer |
nStaticBrokerSize | Static Broker CpxSubscriptions pointer size in bytes |
callback | Call back to be used to process thread Synchronously |
size_t Cpx_GetContextSizeByID | ( | size_t | nID | ) |
Get Full context size (Contex + stack + Broker)
uint32_t Cpx_GetCurrentTick | ( | void | ) |
size_t Cpx_GetID | ( | void | ) |
Get Current Thread ID.
uint32_t Cpx_GetLastDutyCycleByID | ( | size_t | nID | ) |
Last Duty Cycle of the current Thread.
nID | Thread ID |
uint32_t Cpx_GetLastMomentumByID | ( | size_t | nID | ) |
Get Current Thread last momentum on switch back.
nID | Thread ID |
void* Cpx_GetLockID | ( | void | ) |
void* Cpx_GetLockIDByID | ( | size_t | nID | ) |
size_t Cpx_GetMaxNumberOfThreads | ( | void | ) |
Get Max Number of total active Threads.
size_t Cpx_GetMaxStackSizeByID | ( | size_t | nID | ) |
Get total size of stack context page for a Thread ID.
nID | Thread ID |
uint32_t Cpx_GetNiceByID | ( | size_t | nID | ) |
Current Thread Nice.
nID | Thread ID |
size_t Cpx_GetNumberOfActiveThreads | ( | void | ) |
Get Number of total active Threads.
size_t Cpx_GetNumberOfThreads | ( | void | ) |
Get Number of assigned Threads.
size_t Cpx_GetStackSizeByID | ( | size_t | nID | ) |
Get Current Thread ID.
nID | A valid ID |
uint8_t Cpx_GetStatusByID | ( | size_t | nID | ) |
Get a thread status for a thread ID.
nID | Thread ID |
size_t Cpx_GetStructContextSize | ( | void | ) |
Get Thread context size.
bool Cpx_IsBrokerStaticByID | ( | size_t | nID | ) |
Return if a Thread's Broker interface was statically initiated.
nID | Thread ID |
bool Cpx_IsCoreRunning | ( | void | ) |
Report if there is any running thread.
char Cpx_IsSecureByID | ( | size_t | nID | ) |
Return the Secure Status for a thread ID.
nID | Thread ID |
bool Cpx_IsSubscribed | ( | const char * | pszTopic, |
size_t | length | ||
) |
Check if the current thread already subscribe to a topic.
pszTopic | The topic for information |
length | The size of the topic string |
bool Cpx_IsThreadStaticByID | ( | size_t | nID | ) |
Return if a Threads was statically initiated.
nID | Thread ID |
void Cpx_Join | ( | void | ) |
This will start all the threads.
bool Cpx_Lock | ( | CpxSmartLock * | pLock | ) |
Do a exclusive Lock and set to Simple lock.
pLock | The Lock variable |
bool Cpx_LockInit | ( | CpxSmartLock * | pLock | ) |
Init SmartLock variable.
pLock | The Lock variable |
bool Cpx_NotifyAll | ( | const char * | pszTag, |
size_t | nTagLength | ||
) |
Notify ALL TAGs assigned as waiting thread.
pszTag | The Tag string value |
nTagLength | The length of the tag |
bool Cpx_NotifyMessageAll | ( | const char * | pszTag, |
size_t | nTagLength, | ||
size_t | nAttribute, | ||
uint64_t | nValue | ||
) |
Notify ALL TAGs assigned as waiting thread with a Message payload.
pszTag | The TAG string value |
nTagLength | The length of the tag |
nAttribute | The Attribute Value to be sent |
nValue | The Value of the Attribute to be sent |
bool Cpx_NotifyMessageOne | ( | const char * | pszTag, |
size_t | nTagLength, | ||
size_t | nAttribute, | ||
uint64_t | nValue | ||
) |
Notify ONE TAGs assigned as waiting thread with a Message payload.
pszTag | The Tag string value |
nTagLength | The length of the tag |
nAttribute | The Attribute Value to be sent |
nValue | The Value of the Attribute to be sent |
bool Cpx_NotifyOne | ( | const char * | pszTag, |
size_t | nTagLength | ||
) |
Notify ONE TAG assigned as waiting thread.
pszTag | The Tag string value |
nTagLength | The length of the tag |
size_t Cpx_NotifyVariableLock | ( | void * | nLockID, |
size_t | nStatus, | ||
bool | bOneOnly | ||
) |
Notify all/one Variable lock waiting for notification.
nLockID | Variable address |
nStatus | Payload to be sent, a size_t |
bOneOnly | If true only one is notified |
bool Cpx_PublishTopic | ( | const char * | pszTopic, |
size_t | length, | ||
size_t | nAttribute, | ||
uint64_t | nValue | ||
) |
Public a tuple Param and Value.
pszTopic | Topic name to publish |
length | The size of the topic string |
nAttribute | A attribute to be use to identify the value |
nValue | A value for the attribute (tuple) |
void Cpx_SetNice | ( | uint32_t | nNice | ) |
Set Current Thread Nice.
nNice | Nice to be used |
void Cpx_SetSleep | ( | uint32_t | nDelayTickTime | ) |
Will set the thread sleep parameter before Yield.
nDelayTickTime | How much ticks to sleep |
bool Cpx_SharedLock | ( | CpxSmartLock * | pLock | ) |
Can act as multiple locks.
pLock | The Lock variable |
bool Cpx_SharedUnlock | ( | CpxSmartLock * | pLock | ) |
Unlock shared locks.
pLock | The Lock variable |
void Cpx_SleepTicks | ( | uint32_t | nSleepTime | ) |
void Cpx_StackOverflowHandler | ( | void | ) |
bool Cpx_Start | ( | size_t | nThreadPartitions | ) |
Start CorePartition thread provisioning.
nThreadPartitions | Number of threads to be provisioned |
bool Cpx_StaticStart | ( | CpxThread ** | ppStaticThread, |
size_t | nStaticThreadSize | ||
) |
Start CorePartition thread provisioning.
ppStaticThread | Static Thread pointer type CpxThread** |
nStaticThreadSize | Static Thread size in bytes |
bool Cpx_SubscribeTopic | ( | const char * | pszTopic, |
size_t | length | ||
) |
Subscribe for a specific topic.
pszTopic | The topic to listen for information |
length | The size of the topic string |
bool Cpx_TryLock | ( | CpxSmartLock * | pLock | ) |
Like Lock() but only locks in case it is unlocked.
pLock | The Lock variable |
bool Cpx_Unlock | ( | CpxSmartLock * | pLock | ) |
Unlock exclusive locks.
pLock | The Lock variable |
bool Cpx_Wait | ( | const char * | pszTag, |
size_t | nTagLength | ||
) |
Wait for a specific notification from a given TAG.
pszTag | The Tag string value |
nTagLength | The length of the tag |
size_t Cpx_WaitingVariableLock | ( | void * | nLockID | ) |
Return how much threads are locked waiting for a variable notification.
nLockID | Variable address |
bool Cpx_WaitMessage | ( | const char * | pszTag, |
size_t | nTagLength, | ||
CpxMsgPayload * | payload | ||
) |
Wait for a specific notification from a given TAG and payload.
pszTag | The Tag string value |
nTagLength | The length of the tag |
payload | The payload with the information sent by other thread |
bool Cpx_WaitVariableLock | ( | void * | nLockID, |
size_t * | pnStatus | ||
) |
Wait for a Variable Locks notification.
nLockID | Variable address |
pnStatus | Payload to be sent, a size_t |
uint8_t Cpx_Yield | ( | void | ) |
Function to be called inside a thread to change context.