Task Scheduler  f3c51100
Thread Synchronization

Syncronization Functions. More...

Functions

TASH_SCH_EXTERN schSignalSet * schCreateSignal (void)
 
TASH_SCH_EXTERN int schDeleteSignal (schSignalSet *signal)
 
TASH_SCH_EXTERN int schBaseSignal (void)
 
TASH_SCH_EXTERN int schSignalWait (schSignalSet *sig)
 Wait in till signal has been issued. More...
 
TASH_SCH_EXTERN int schSignalWaitTimeOut (schSignalSet *sig, long int nanoseconds)
 
TASH_SCH_EXTERN int schSetSignalThreadMask (schSignalSet *set, int nr, const int *signals)
 
TASH_SCH_EXTERN int schCreateMutex (schMutex **mutex)
 
TASH_SCH_EXTERN int schCreateSpinLock (schSpinLock **spinlock)
 Creates a spinlock synchronization primitive object. More...
 
TASH_SCH_EXTERN int schCreateSemaphore (schSemaphore **pSemaphore)
 
TASH_SCH_EXTERN int schCreateBarrier (schBarrier **pBarrier)
 Create Memory barrier. More...
 
TASH_SCH_EXTERN int schInitBarrier (schBarrier *pBarrier, int count)
 
TASH_SCH_EXTERN int schDeleteBarrier (schBarrier *barrier)
 
TASH_SCH_EXTERN int schWaitBarrier (schBarrier *barrier)
 Wait for the barrier to finish. More...
 
TASH_SCH_EXTERN int schCreateConditional (schConditional **pCondVariable)
 
TASH_SCH_EXTERN int schDeleteConditional (schConditional *conditional)
 
TASH_SCH_EXTERN int schConditionalWait (schConditional *conditional, schMutex *mutex)
 
TASH_SCH_EXTERN int schConditionalSignal (schConditional *conditional)
 
TASH_SCH_EXTERN int schCreateRWLock (schRWLock **pRwLock)
 
TASH_SCH_EXTERN int schDeleteRWLock (schRWLock *rwLock)
 
TASH_SCH_EXTERN int schRWLockRead (schRWLock *rwLock)
 
TASH_SCH_EXTERN int schRWLockWrite (schRWLock *rwLock)
 
TASH_SCH_EXTERN int schRWLocUnLock (schRWLock *rwLock)
 
TASH_SCH_EXTERN int schDeleteMutex (schMutex *mutex)
 Release resources associated with the mutex object. More...
 
TASH_SCH_EXTERN int schDeleteSpinLock (schSpinLock *spinlock)
 Release spinlock resources. More...
 
TASH_SCH_EXTERN int schDeleteSemaphore (schSemaphore *pSemaphore)
 Delete semaphore. More...
 
TASH_SCH_EXTERN int schMutexLock (schMutex *mutexLock)
 Lock mutex and wait initill it has been unlocked for the thread to use the mutex. More...
 
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 timeout. More...
 
TASH_SCH_EXTERN int schMutexUnLock (schMutex *mutexLock)
 Unlock mutex. More...
 
TASH_SCH_EXTERN int schSemaphoreWait (schSemaphore *pSemaphore)
 Wait for semaphore to be unlocked. More...
 
TASH_SCH_EXTERN int schSemaphoreTryWait (schSemaphore *semaphore)
 
TASH_SCH_EXTERN int schSemaphoreTimedWait (schSemaphore *pSemaphore, long int timeout)
 
TASH_SCH_EXTERN int schSemaphorePost (schSemaphore *pSemaphore)
 
TASH_SCH_EXTERN int schSemaphoreValue (schSemaphore *pSemaphore, int *value)
 
TASH_SCH_EXTERN int schLockSpinLock (schSpinLock *spinlock)
 
TASH_SCH_EXTERN int schTryLockSpinLock (schSpinLock *spinLock)
 
TASH_SCH_EXTERN int schUnlockSpinLock (schSpinLock *spinlock)
 

Detailed Description

Syncronization Functions.

Function Documentation

◆ schCreateSignal()

TASH_SCH_EXTERN schSignalSet* schCreateSignal ( void  )

Allocate signal object.

Since
0.1.0
Returns
non-null if successfully.

◆ schDeleteSignal()

TASH_SCH_EXTERN int schDeleteSignal ( schSignalSet *  signal)

Release signal resources.

Since
0.1.0
Parameters
signalvalid signal pointer.
Returns

◆ schBaseSignal()

TASH_SCH_EXTERN int schBaseSignal ( void  )

Get the base signal number that are valid for sending signal between threads and that will not conflicts with the kernel specified signals.

Since
0.1.0
Returns
non-negative number.

◆ schSignalWait()

TASH_SCH_EXTERN int schSignalWait ( schSignalSet *  sig)

Wait in till signal has been issued.

See also
Since
0.1.0
Parameters
sigsignal object.
Returns
signal received.

◆ schSignalWaitTimeOut()

TASH_SCH_EXTERN int schSignalWaitTimeOut ( schSignalSet *  sig,
long int  nanoseconds 
)

Wait in till a signal has been issued in the timeout time frame.

Since
0.1.0
Parameters
sigsignal object.
nanosecondsin nano seconds for the timeout.
Returns
signal.

◆ schSetSignalThreadMask()

TASH_SCH_EXTERN int schSetSignalThreadMask ( schSignalSet *  set,
int  nr,
const int *  signals 
)

Set thread signal mask. Mask what signal to listen and how to

Since
0.1.0
Parameters
setobject.
nrnumber of signals.
signalsarray of valid signals.
Returns
non-negative if successfully.

◆ schCreateMutex()

TASH_SCH_EXTERN int schCreateMutex ( schMutex **  mutex)

Create mutex pointer.

Since
0.1.0
Parameters
mutexnon-null pointer to mutex pointer.
Returns
non-zero if successfully.

◆ schCreateSpinLock()

TASH_SCH_EXTERN int schCreateSpinLock ( schSpinLock **  spinlock)

Creates a spinlock synchronization primitive object.

The Synchronization primitive works by using a thight for loop and check if still locked or if has been unlocked and can proceeded.

Use this synchronization primitive when the lock is suspected to be very short or if to prevent the kernel from switching the process directly.

schSpinLock* spinlock;
schCreateSpinLock(&spinlock);
schLockSpinLock(spinlock);
... compute something....
schUnlockSpinLockspinlock);
TASH_SCH_EXTERN int schCreateSpinLock(schSpinLock **spinlock)
Creates a spinlock synchronization primitive object.
TASH_SCH_EXTERN int schDeleteSpinLock(schSpinLock *spinlock)
Release spinlock resources.
TASH_SCH_EXTERN int schLockSpinLock(schSpinLock *spinlock)
Since
0.1.1
See also
schLockSpinLock
schTryLockSpinLock
schUnlockSpinLock
Parameters
spinlockvalid pointer.
Returns
non-negative if successfull.

◆ schCreateSemaphore()

TASH_SCH_EXTERN int schCreateSemaphore ( schSemaphore **  pSemaphore)

Create semaphore object.

Since
0.1.1
See also
schDeleteSemaphore
Parameters
pSemaphorevalid pointer.
Returns
non-negative if successfully.

◆ schCreateBarrier()

TASH_SCH_EXTERN int schCreateBarrier ( schBarrier **  pBarrier)

Create Memory barrier.

See also
schDeleteBarrier
schInitBarrier
Since
0.1.1
Parameters
pBarriervalid pointer.
Returns
non-negative if successfully.

◆ schInitBarrier()

TASH_SCH_EXTERN int schInitBarrier ( schBarrier *  pBarrier,
int  count 
)
Since
0.1.1
Parameters
pBarrier
count
Returns
non-negative if successfully.

◆ schDeleteBarrier()

TASH_SCH_EXTERN int schDeleteBarrier ( schBarrier *  barrier)
Since
0.1.1
Parameters
barrier
Returns
non-negative if successfully.

◆ schWaitBarrier()

TASH_SCH_EXTERN int schWaitBarrier ( schBarrier *  barrier)

Wait for the barrier to finish.

Since
0.1.1
Parameters
barrier
Returns
non-negative if successfully.

◆ schCreateConditional()

TASH_SCH_EXTERN int schCreateConditional ( schConditional **  pCondVariable)
Since
0.1.1
Parameters
pCondVariable
Returns
non-negative if successfully.

◆ schDeleteConditional()

TASH_SCH_EXTERN int schDeleteConditional ( schConditional *  conditional)
Since
0.1.1
Parameters
conditional
Returns
non-negative if successfully.

◆ schConditionalWait()

TASH_SCH_EXTERN int schConditionalWait ( schConditional *  conditional,
schMutex *  mutex 
)
Since
0.1.1
Parameters
conditional
mutex
Returns
non-negative if successfully.

◆ schConditionalSignal()

TASH_SCH_EXTERN int schConditionalSignal ( schConditional *  conditional)
Since
0.1.1
Parameters
conditional
Returns
non-negative if successfully.

◆ schCreateRWLock()

TASH_SCH_EXTERN int schCreateRWLock ( schRWLock **  pRwLock)
Since
0.1.1
Parameters
pRwLock
Returns
non-negative if successfully.

◆ schDeleteRWLock()

TASH_SCH_EXTERN int schDeleteRWLock ( schRWLock *  rwLock)
Since
0.1.1
Parameters
rwLock
Returns
non-negative if successfully.

◆ schRWLockRead()

TASH_SCH_EXTERN int schRWLockRead ( schRWLock *  rwLock)
Since
0.1.1
Parameters
rwLock
Returns
non-negative if successfully.

◆ schRWLockWrite()

TASH_SCH_EXTERN int schRWLockWrite ( schRWLock *  rwLock)
Since
0.1.1
Parameters
rwLock
Returns
non-negative if successfully.

◆ schRWLocUnLock()

TASH_SCH_EXTERN int schRWLocUnLock ( schRWLock *  rwLock)
Since
0.1.1
Parameters
rwLock
Returns
non-negative if successfully.

◆ schDeleteMutex()

TASH_SCH_EXTERN int schDeleteMutex ( schMutex *  mutex)

Release resources associated with the mutex object.

Since
0.1.1
Parameters
mutexvalid mutex object pointer.
Returns
non-negative if successfully.

◆ schDeleteSpinLock()

TASH_SCH_EXTERN int schDeleteSpinLock ( schSpinLock *  spinlock)

Release spinlock resources.

Since
0.1.1
Parameters
spinlockvalid spinlock pointer.
Returns
non-negative if successfully.

◆ schDeleteSemaphore()

TASH_SCH_EXTERN int schDeleteSemaphore ( schSemaphore *  pSemaphore)

Delete semaphore.

Since
0.1.1
Parameters
pSemaphorevalid pointer.
Returns
non-negative if successfully.

◆ schMutexLock()

TASH_SCH_EXTERN int schMutexLock ( schMutex *  mutexLock)

Lock mutex and wait initill it has been unlocked for the thread to use the mutex.

Since
0.1.1
Parameters
mutexLockvalid mutex pointer.
Returns
non-negative if successfully.

◆ schMutexTryLock()

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 timeout.

Since
0.1.1
Parameters
mutexvalid mutex pointer object.
timeoutnumber of nanoseconds that it will wait.
Returns
non-negative if successfully.

◆ schMutexUnLock()

TASH_SCH_EXTERN int schMutexUnLock ( schMutex *  mutexLock)

Unlock mutex.

Since
0.1.1
Parameters
mutexLockvalid mutex pointer.
Returns
non-negative if successfully.

◆ schSemaphoreWait()

TASH_SCH_EXTERN int schSemaphoreWait ( schSemaphore *  pSemaphore)

Wait for semaphore to be unlocked.

If the counter is it will block and wait for the schSemaphorePost function to be wait. Otherwise it will continue execution while blocking any other thread passing the wait function in till the schSemaphorePost. function is invoked. Wait in till the semaphore has been unlocked.

Since
0.1.1
Parameters
pSemaphorevalid semaphore object.
Returns
non-negative if successfull.

◆ schSemaphoreTryWait()

TASH_SCH_EXTERN int schSemaphoreTryWait ( schSemaphore *  semaphore)

Similar to schSemaphoreWait execpet it won't be blocking if blocked by other semaphore and will return status that it is timed out.

Since
0.1.1
Parameters
semaphorevalid semaphore object.
Returns
non-negative if successfully, SCH_ERROR_TIMEOUT

◆ schSemaphoreTimedWait()

TASH_SCH_EXTERN int schSemaphoreTimedWait ( schSemaphore *  pSemaphore,
long int  timeout 
)

Wait for the semaphore has been unlocked for a explicit duration of time in nanoseconds.

Since
0.1.1
Parameters
pSemaphorevalid semaphore object.
timeoutnon-negative time in nanoseconds.
Returns
non-negative if successfully.

◆ schSemaphorePost()

TASH_SCH_EXTERN int schSemaphorePost ( schSemaphore *  pSemaphore)

Function will decrease the counter and let next first waiting semaphore continue while looking the remaining waiting semaphore.

Since
0.1.1
Parameters
pSemaphorevalid semaphore object.
Returns
non-negative if successfully.

◆ schSemaphoreValue()

TASH_SCH_EXTERN int schSemaphoreValue ( schSemaphore *  pSemaphore,
int *  value 
)

Get current value of the semaphore.

Since
0.1.1
Parameters
pSemaphorevalid semaphore object.
value
Returns
non-negative if successfully.

◆ schLockSpinLock()

TASH_SCH_EXTERN int schLockSpinLock ( schSpinLock *  spinlock)

Lock spinlock.

Since
0.1.1
Parameters
spinlockvalid spinlock pointer.
Returns
non-negative if successfully.

◆ schTryLockSpinLock()

TASH_SCH_EXTERN int schTryLockSpinLock ( schSpinLock *  spinLock)

Attempt to lock the spinlock. If failed it will return directly rather than wait.

Since
0.1.1
Parameters
spinLockvalid spinlock pointer object.
Returns
non-negative if successfully.

◆ schUnlockSpinLock()

TASH_SCH_EXTERN int schUnlockSpinLock ( schSpinLock *  spinlock)

Unlock spinlock.

Since
0.1.1
Parameters
spinlockvalid spinlock pointer.
Returns
non-negative if successfully.