19 #ifndef _CORE_TASK_SCH_H_
20 #define _CORE_TASK_SCH_H_ 1
60 #include <stdatomic.h>
71 #ifndef TASH_SCH_EXTERN
72 #ifndef TASH_SCH_STATIC
74 #define TASH_SCH_EXTERN __declspec(dllimport)
75 #elif defined(__GNUC__) && __GNUC__ >= 4 || __clang__
76 #define TASH_SCH_EXTERN __attribute__((visibility("default")))
78 #define TASH_SCH_EXTERN
81 #define TASH_SCH_EXTERN
88 #define SCH_FLAG_NO_AFM 0x80000000
94 #define SCH_FLAG_INIT 0x1
95 #define SCH_FLAG_RUNNING 0x2
96 #define SCH_FLAG_IDLE 0x4
101 #define SCH_POOL_TERMINATE 0x1
102 #define SCH_POOL_RUNNING 0x2
103 #define SCH_POOL_SLEEP 0x4
108 #define SCH_SIGNAL_IDLE (schBaseSignal() + 0)
109 #define SCH_SIGNAL_RUNNING (schBaseSignal() + 1)
110 #define SCH_SIGNAL_DONE (schBaseSignal() + 2)
111 #define SCH_SIGNAL_CONTINUE (schBaseSignal() + 3)
112 #define SCH_SIGNAL_QUIT (schBaseSignal() + 4)
113 #define SCH_SIGNAL_STOP SIGSTOP
128 SCH_ERROR_UNKNOWN = 0,
129 SCH_ERROR_INVALID_ARG = -1,
130 SCH_ERROR_INVALID_SCH = (-2),
131 SCH_ERROR_INVALID_STATE = (-3),
132 SCH_ERROR_INTERNAL = (-4),
133 SCH_ERROR_POOL_FULL = (-5),
134 SCH_ERROR_SIGNAL = (-6),
135 SCH_ERROR_SYNC_OBJECT = (-7),
136 SCH_ERROR_TIMEOUT = (-8),
137 SCH_ERROR_BUSY = (-9),
138 SCH_ERROR_NOMEM = (-10),
139 SCH_ERROR_LACK_OF_RESOURCES = (-11),
140 SCH_ERROR_PERMISSION_DENIED = (-12),
149 typedef void *(*schFunc)(
void *pdata);
156 typedef void schSpinLock;
157 typedef void schMutex;
158 typedef void schSemaphore;
159 typedef void schRWLock;
160 typedef void schConditional;
161 typedef void schBarrier;
172 typedef void schThread;
173 typedef void schSignalSet;
201 schCallback callback;
273 unsigned int maxPackagesPool);
TASH_SCH_EXTERN void schSetInitCallBack(schTaskSch *sch, schUserCallBack callBack)
Set initialization callback that will be invoked when the scheduler starts.
TASH_SCH_EXTERN int schCreateTaskPool(schTaskSch *sch, int cores, unsigned int flag, unsigned int maxPackagesPool)
Initilize task scheduler internal data structure.
TASH_SCH_EXTERN void * schGetPoolUserData(schTaskSch *sch, int index)
Get pool user data.
TASH_SCH_EXTERN void schSetDeInitCallBack(schTaskSch *sch, schUserCallBack callBack)
Set user deinitialize callback that will be invoked when the scheduler gets terminated.
TASH_SCH_EXTERN void schSetPoolUserData(schTaskSch *sch, int index, const void *user)
Assign user data associated with the scheduler objects pools.
TASH_SCH_EXTERN void schSetSchUserData(schTaskSch *sch, const void *user)
Assign user data associated with the scheduler object.
TASH_SCH_EXTERN int schAllocateTaskPool(schTaskSch **pSch)
Allocate task scheduler object. It will make sure that for any version of the library,...
TASH_SCH_EXTERN int schReleaseTaskSch(schTaskSch *sch)
Release all resources associated with the scheduler object.
TASH_SCH_EXTERN schTaskPool * schGetPool(schTaskSch *sch, int index)
Get scheduler pool by index.
TASH_SCH_EXTERN int schPoolMutexUnLock(schTaskPool *pool)
TASH_SCH_EXTERN int schRunTaskSch(schTaskSch *sch)
TASH_SCH_EXTERN int schTerminateTaskSch(schTaskSch *sch)
TASH_SCH_EXTERN int schWaitTaskWait(schTaskSch *sch, long int wait_nanoseconds)
TASH_SCH_EXTERN int schClearAllTask(schTaskSch *sch)
TASH_SCH_EXTERN int schClearTask(schTaskSch *sch, schTaskPool *pool)
TASH_SCH_EXTERN int schPoolLock(schTaskPool *pool)
TASH_SCH_EXTERN int schStopTaskSch(schTaskSch *sch, long int timeout_nanoseconds)
TASH_SCH_EXTERN int schSubmitTask(schTaskSch *sch, schTaskPackage *package, schTaskPool *pPool)
TASH_SCH_EXTERN int schWaitTask(schTaskSch *sch)
SchErrCode
Set of valid error codes. Anything equal to one or greater is considered as a success.
Definition: taskSch.h:126
TASH_SCH_EXTERN const char * schErrorMsg(int errMsg)
TASH_SCH_EXTERN int schRWLockWrite(schRWLock *rwLock)
TASH_SCH_EXTERN int schRWLocUnLock(schRWLock *rwLock)
TASH_SCH_EXTERN int schCreateSpinLock(schSpinLock **spinlock)
Creates a spinlock synchronization primitive object.
TASH_SCH_EXTERN int schConditionalWait(schConditional *conditional, schMutex *mutex)
TASH_SCH_EXTERN int schInitBarrier(schBarrier *pBarrier, int count)
TASH_SCH_EXTERN int schSemaphoreTimedWait(schSemaphore *pSemaphore, long int timeout)
TASH_SCH_EXTERN int schSignalWait(schSignalSet *sig)
Wait in till signal has been issued.
TASH_SCH_EXTERN int schDeleteSemaphore(schSemaphore *pSemaphore)
Delete semaphore.
TASH_SCH_EXTERN int schDeleteConditional(schConditional *conditional)
TASH_SCH_EXTERN int schConditionalSignal(schConditional *conditional)
TASH_SCH_EXTERN int schSemaphoreValue(schSemaphore *pSemaphore, int *value)
TASH_SCH_EXTERN int schDeleteSpinLock(schSpinLock *spinlock)
Release spinlock resources.
TASH_SCH_EXTERN int schDeleteBarrier(schBarrier *barrier)
TASH_SCH_EXTERN int schTryLockSpinLock(schSpinLock *spinLock)
TASH_SCH_EXTERN int schCreateRWLock(schRWLock **pRwLock)
TASH_SCH_EXTERN int schDeleteSignal(schSignalSet *signal)
TASH_SCH_EXTERN int schWaitBarrier(schBarrier *barrier)
Wait for the barrier to finish.
TASH_SCH_EXTERN int schBaseSignal(void)
TASH_SCH_EXTERN int schSignalWaitTimeOut(schSignalSet *sig, long int nanoseconds)
TASH_SCH_EXTERN int schDeleteMutex(schMutex *mutex)
Release resources associated with the mutex object.
TASH_SCH_EXTERN int schLockSpinLock(schSpinLock *spinlock)
TASH_SCH_EXTERN int schCreateSemaphore(schSemaphore **pSemaphore)
TASH_SCH_EXTERN int schCreateConditional(schConditional **pCondVariable)
TASH_SCH_EXTERN int schCreateBarrier(schBarrier **pBarrier)
Create Memory barrier.
TASH_SCH_EXTERN int schMutexTryLock(schMutex *mutex, long int timeout)
Attempt to lock the mutex. If the wait time exceeds the timeout it will return with the status of tim...
TASH_SCH_EXTERN int schDeleteRWLock(schRWLock *rwLock)
TASH_SCH_EXTERN int schUnlockSpinLock(schSpinLock *spinlock)
TASH_SCH_EXTERN int schSemaphoreTryWait(schSemaphore *semaphore)
TASH_SCH_EXTERN int schMutexLock(schMutex *mutexLock)
Lock mutex and wait initill it has been unlocked for the thread to use the mutex.
TASH_SCH_EXTERN int schMutexUnLock(schMutex *mutexLock)
Unlock mutex.
TASH_SCH_EXTERN int schRWLockRead(schRWLock *rwLock)
TASH_SCH_EXTERN int schSemaphorePost(schSemaphore *pSemaphore)
TASH_SCH_EXTERN schSignalSet * schCreateSignal(void)
TASH_SCH_EXTERN int schSetSignalThreadMask(schSignalSet *set, int nr, const int *signals)
TASH_SCH_EXTERN int schSemaphoreWait(schSemaphore *pSemaphore)
Wait for semaphore to be unlocked.
TASH_SCH_EXTERN int schCreateMutex(schMutex **mutex)
TASH_SCH_EXTERN int schDeleteThread(schThread *thread)
Delete thread This will cause the system to release the thread resources.
TASH_SCH_EXTERN int schWaitThread(schThread *thread, void **retval)
TASH_SCH_EXTERN schThread * schCurrentThread(void)
TASH_SCH_EXTERN schThread * schCreateThread(int affinity, schFunc pfunc, void *userData)
Create new thread object with a custom callback entrypoint.
TASH_SCH_EXTERN int schRaiseThreadSignal(schThread *thread, int signal)
TASH_SCH_EXTERN int schSetThreadName(schThread *thread, const char *name)
TaskPool.
Definition: internal_structures.h:33
Task scheduler main struct container.
Definition: internal_structures.h:75
atomic_uint flag
Definition: taskSch.h:192
void * begin
Definition: taskSch.h:214
unsigned int index
Definition: taskSch.h:196
#define TASH_SCH_EXTERN
Definition: taskSch.h:78
struct sch_task_package_t schTaskPackage
Definition: taskSch.h:180
void * end
Definition: taskSch.h:219
size_t size
Definition: taskSch.h:205
void *(* schFunc)(void *pdata)
Definition: taskSch.h:149
size_t offset
Definition: taskSch.h:209
void * puser
Definition: taskSch.h:223
Definition: taskSch.h:188