Global

group Global_mutex

mutex globals

lorem

Macros

group Macros_mutex_h

Variables

group Variables_mutex_h

API’s

group Apis_mutex_h

Getters

group Getters_mutex_h

Functions

CosmOS_MutexStateType mutex_getMutexInternal(BitWidthType entityId, CosmOS_MutexVariableType *mutexVar)

Get mutex internal. This function cannot be called from the unprivileged context directly. DEMO.

The implementation contains obtaining of the core configuration by calling the CILcore_getCoreCfg function. Then the function CILmutex_tryMutex is called and the returned mutexState is used in the if condition where in case of MUTEX_STATE_ENUM__SUCCESSFULLY_LOCKED the schedulableOwner in the mutex variable is set to the schedulable in execution obtained from the core variable. If the mutex was not successfully locked the thread variable is obtained by calling the program_getProgramThread function and its blocking mutex variable is set to the mutexVar. The state of the schedulable is set to the SCHEDULABLE_STATE_ENUM__BLOCKED and context switch routine is triggered by calling CILinterrupt_contextSwitchRoutineTrigger. In the end the mutexState is returned.

Parameters
  • entityId[in] is used during the system call dispatching

  • mutexVar[in] pointer to the mutex variable

Returns

CosmOS_MutexStateType

CosmOS_MutexStateType mutex_getMutex(CosmOS_MutexVariableType *mutexVar)

Get mutex. Function can be used within the scope of the program but only for threads. DEMO.

The implementation contains obtaining of the core configuration by calling the CILcore_getCoreCfg function. Then the mutex variable address is checked if its not in the memory protected region by calling the function memoryProtection_isMemoryRegionProtected. If the address of mutex variable is protected mutexState with MUTEX_STATE_ENUM__ERROR_INVALID_MUTEX_ADDRESS value is returned. Nested if condition then subsequently checks if the schedulable in execution which means the mutex release requesting schedulable is a thread type SCHEDULABLE_INSTANCE_ENUM__THREAD. If not the mutexState is returned with the value MUTEX_STATE_ENUM__ERROR_ONLY_THREADS_CAN_USE_MUTEX. After this point another condition is needed to check if the schedulable in execution will not cause the deadlock by calling mutex_willCauseDeadlock function. If yes the mutexState is returned with the value MUTEX_STATE_ENUM__ERROR_DEADLOCK. If not the do while loop is implemented with calling the cosmosApiInternal_mutex_getMutexInternal till the returned value is not MUTEX_STATE_ENUM__SUCCESSFULLY_LOCKED.

Parameters

mutexVar[in] pointer to the mutex variable

Returns

CosmOS_MutexStateType

Setters

group Setters_mutex_h

Functions

void mutex_setMutexValue(CosmOS_MutexVariableType *mutexVar, BitWidthType mutexParam)

Set mutex value.

Parameters
  • mutexVar[out] pointer to the mutex variable

  • CosmOS_MutexStateType[in] mutexParam

Returns

none

void mutex_setMutexSchedulableOwner(CosmOS_MutexVariableType *mutexVar, CosmOS_SchedulableConfigurationType *schedulableOwnerParam)

General

group General_mutex_h

Functions

CosmOS_MutexStateType mutex_tryMutexInternal(BitWidthType entityId, CosmOS_MutexVariableType *mutexVar)

Try to get mutex internal. This function cannot be called from the unprivileged context directly. DEMO.

The implementation contains obtaining of the core configuration by calling the CILcore_getCoreCfg function. Then the function CILmutex_tryMutex is called and the returned mutexState is used in the if condition where in case of MUTEX_STATE_ENUM__SUCCESSFULLY_LOCKED the schedulableOwner in the mutex variable is set to the schedulable in execution obtained from the core variable. In the end the mutexState is returned.

Parameters
  • entityId[in] is used during the system call dispatching

  • mutexVar[in] pointer to the mutex variable

Returns

CosmOS_MutexStateType

CosmOS_MutexStateType mutex_releaseMutexInternal(BitWidthType entityId, CosmOS_MutexVariableType *mutexVar)

Release mutex internal. This function cannot be called from the unprivileged context directly. DEMO.

The implementation contains obtaining of the core configuration by calling the CILcore_getCoreCfg function. Then the function CILmutex_releaseMutex is called. As the mutex is now released it is needed to notice all threads that were waiting for this specific mutex. As the mutex can be used only for the threads within the one program the for loop is implemented that iterates over all threads in the current program and if the thread variable blockingMutexVar is equal to the mutexVar its schedulable state is set to the SCHEDULABLE_STATE_ENUM__READY, the thread blockingMutexVar is set to the NULL pointer and the priority of the thread in current context is obtained by getting the thread variable in the first place by function program_getProgramThread and then comparing this to the thread variable that was blocked by the mutexVar. If the blocked thread priority is higher the flag higherPriorityThreadBlocked is set to True and the CILinterrupt_contextSwitchRoutineTrigger is called in the end to trigger scheduler algorithm to unblock higher priority thread.

Parameters
  • entityId[in] is used during the system call dispatching

  • mutexVar[in] pointer to the mutex variable

Returns

CosmOS_MutexStateType

CosmOS_MutexStateType mutex_tryMutex(CosmOS_MutexVariableType *mutexVar)

Try to get mutex. Function can be used within the scope of the program but only for threads. DEMO.

The implementation contains obtaining of the core configuration by calling the CILcore_getCoreCfg function. Then the mutex variable address is checked if its not in the memory protected region by calling the function memoryProtection_isMemoryRegionProtected. If the address of mutex variable is protected mutexState with MUTEX_STATE_ENUM__ERROR_INVALID_MUTEX_ADDRESS value is returned. Nested if condition then subsequently checks if the schedulable in execution which means the mutex release requesting schedulable is a thread type SCHEDULABLE_INSTANCE_ENUM__THREAD. If not the mutexState is returned with the value MUTEX_STATE_ENUM__ERROR_ONLY_THREADS_CAN_USE_MUTEX. If yes then is possible to try to lock the mutex by calling CosmOS API function cosmosApiInternal_mutex_tryMutexInternal.

Parameters

mutexVar[in] pointer to the mutex variable

Returns

CosmOS_MutexStateType

CosmOS_MutexStateType mutex_releaseMutex(CosmOS_MutexVariableType *mutexVar)

Release mutex. Function can be used within the scope of the program but only for threads. DEMO.

The implementation contains obtaining of the core configuration by calling the CILcore_getCoreCfg function. Then the mutex variable address is checked if its not in the memory protected region by calling the function memoryProtection_isMemoryRegionProtected. If the address of mutex variable is protected mutexState with MUTEX_STATE_ENUM__ERROR_INVALID_MUTEX_ADDRESS value is returned. Nested if condition then subsequently checks if the schedulable in execution which means the mutex release requesting schedulable is a thread type SCHEDULABLE_INSTANCE_ENUM__THREAD. If not the mutexState is returned with the value MUTEX_STATE_ENUM__ERROR_ONLY_THREADS_CAN_USE_MUTEX. After this point another condition is needed to check if the schedulable in execution owns the mutex variable by calling mutex_ownsSchedulableMutex function. If not the mutexState is returned with the value MUTEX_STATE_ENUM__ERROR_SCHEDULABLE_IS_NOT_OWNER. The last if condition checks if the mutex variable value is equal to MUTEX_STATE_ENUM__OCCUPIED which means that the mutex is locked, if not the mutexState is returned with MUTEX_STATE_ENUM__ERROR_NOT_IN_OCCUPIED_STATE. If yes then the mutex can be released by calling CosmOS API function cosmosApiInternal_mutex_releaseMutexInternal.

Parameters

mutexVar[in] pointer to the mutex variable

Returns

CosmOS_MutexStateType

CosmOS_BooleanType mutex_willCauseDeadlock(CosmOS_CoreConfigurationType *core, CosmOS_MutexVariableType *mutexVar)

Check if the mutex will ends up in deadlock. DEMO.

Parameters
  • core[in] configuration pointer

  • mutexVar[in] pointer to the mutex variable

Returns

CosmOS_BufferStateType

CosmOS_BooleanType mutex_ownsSchedulableMutex(CosmOS_CoreConfigurationType *core, CosmOS_MutexVariableType *mutexVar)

Check if the schedulable in execution owns the current mutex.

Parameters
  • core[in] configuration pointer

  • mutexVar[in] pointer to the mutex variable

Returns

CosmOS_BufferStateType