Global¶
- group Global_semaphore
semaphore globals
lorem
Macros¶
- group Macros_semaphore_h
Variables¶
- group Variables_semaphore_h
API’s¶
- group Apis_semaphore_h
Getters¶
- group Getters_semaphore_h
Functions
-
CosmOS_SemaphoreStateType semaphore_getSemaphore(BitWidthType semaphoreId)¶
Get semaphore. DEMO.
The implementation contains obtaining of the operating system and core configuration by calling functions os_getOsCfg and CILcore_getCoreCfg. Then the operating system configuration in function os_getOsNumberOfSemaphores to get number of semaphores. The input element id argument is then checked againts the number of semaphore, if it is greater than number of semaphores SEMAPHORE_STATE_ENUM__ERROR_INVALID_ID is returned. Semaphore variable is then obtained based on the id argument by the function os_getOsSemaphoreVar. Nested if condition then subsequently checks if the schedulable in execution which means the semaphore release requesting schedulable is a thread type SCHEDULABLE_INSTANCE_ENUM__THREAD. If not the semaphoreState is returned with the value SEMAPHORE_STATE_ENUM__ERROR_ONLY_THREADS_CAN_USE_SEMAPHORE. The function semaphore_willCauseDeadlock is called to check if the semaphore would cause eventually deadlock, if yes the semaphore state SEMAPHORE_STATE_ENUM__ERROR_DEADLOCK is returned. Otherwise the function cosmosApiInternal_semaphore_getSemaphoreInternal is called if the core is in the privileged mode or semaphore_getSemaphoreInternal is called to get semaphore and result is then returned as semaphore state. The schedulable owner member in semaphore variable is set to the schedulable in execution.
- Parameters
semaphoreId – [in] semaphore identifier
- Returns
CosmOS_SemaphoreStateType
-
CosmOS_SemaphoreStateType semaphore_getSemaphoreInternal(BitWidthType id, CosmOS_SemaphoreVariableType *semaphoreVar, BitWidthType semaphoreId)¶
Get to get semaphore internal. This function cannot be called from the unprivileged context directly. DEMO.
- Parameters
id – [in] is used during the system call dispatching
semaphoreVar – [in] variable structure pointer
semaphoreId – [in] semaphore identifier
- Returns
CosmOS_SemaphoreStateType
-
CosmOS_SemaphoreStateType semaphore_getSemaphore(BitWidthType semaphoreId)¶
Setters¶
- group Setters_semaphore_h
Functions
-
void semaphore_setSemaphoreValue(CosmOS_SemaphoreVariableType *semaphoreVar, BitWidthType semaphoreParam)¶
Set semaphore value. This function cannot be called from the unprivileged context directly.
- Parameters
semaphoreVar – [out] pointer
semaphoreParam – [in] value to be set to the semaphore variable
- Returns
none
-
void semaphore_setSemaphoreSchedulableOwner(CosmOS_SemaphoreVariableType *semaphoreVar, CosmOS_SchedulableConfigurationType *schedulableOwnerParam)¶
Set semaphore schedulableOwner. This function cannot be called from the unprivileged context directly.
- Parameters
semaphoreVar – [out] pointer
schedulableOwnerParam – [in] pointer to the schedulable that owns current semaphore
- Returns
none
-
void semaphore_setSemaphoreValue(CosmOS_SemaphoreVariableType *semaphoreVar, BitWidthType semaphoreParam)¶
General¶
- group General_semaphore_h
Functions
-
CosmOS_SemaphoreStateType semaphore_trySemaphoreInternal(BitWidthType id, CosmOS_SemaphoreVariableType *semaphoreVar, BitWidthType semaphoreId)¶
Try to get semaphore internal. This function cannot be called from the unprivileged context directly. DEMO.
The implementation contains obtaining of the core configuration by calling function CILcore_getCoreCfg. Then the function CILsemaphore_trySemaphore is called to try to get semaphore and result is then returned as semaphore state. The if condition is implemented to check if the result from CILsemaphore_trySemaphore is equal to the SEMAPHORE_STATE_ENUM__SUCCESSFULLY_LOCKED and if yes the schedulable owner member in semaphore variable is set to the schedulable in execution.
- Parameters
id – [in] is used during the system call dispatching
semaphoreVar – [in] variable structure pointer
semaphoreId – [in] semaphore identifier
- Returns
CosmOS_SemaphoreStateType
-
CosmOS_SemaphoreStateType semaphore_releaseSemaphoreInternal(BitWidthType id, CosmOS_SemaphoreVariableType *semaphoreVar, BitWidthType semaphoreId)¶
Release to get semaphore 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 CILsemaphore_releaseSemaphore is called. As the semaphore is now released it is needed to notice all threads that were waiting for this specific semaphore. As the semaphore can be used for synchronizing threads between the different programs (inter-program) the for loops are implemented which iterate over the all configured cores in the system and threads in their programs and if the thread variable blockingSemaphoreVar is equal to the semaphoreVar its schedulable state is set to the SCHEDULABLE_STATE_ENUM__READY and thread blockingSemaphoreVar is set to the NULL pointer. If the core id of current core is equal to the core iterator for loop variable, we check if threads which were blocked do not have higher priority than the running thread that releases the semaphore, if yes the local boolean variable higherPriorityThreadBlocked is set to True and it is checked in the end if we have to trigger the reschedule on the current core. If the blocked threads are bound to the different core we set the event handle core variable with the coreId related to this core. After iterating over all threads in the system we call the function osEvent_triggerEvent if atleastOneCoreHandleEvent local variable is True with the OS_EVENT_RESCHEDULE event and core handle array we configured before. Then assertion is called to check if the os event state is OS_EVENT_STATE_ENUM__OK. In the end the if condition is implemented that checks if there is higherPriorityThreadBlocked on the current core and if yes the CILinterrupt_contextSwitchRoutineTrigger function is called.
- Parameters
id – [in] is used during the system call dispatching
semaphoreVar – [in] variable structure pointer
semaphoreId – [in] semaphore identifier
- Returns
CosmOS_SemaphoreStateType
-
CosmOS_SemaphoreStateType semaphore_trySemaphore(BitWidthType semaphoreId)¶
Try to get semaphore. DEMO.
The implementation contains obtaining of the operating system and core configuration by calling functions os_getOsCfg and CILcore_getCoreCfg. Then the operating system configuration in function os_getOsNumberOfSemaphores to get number of semaphores. The input element id argument is then checked againts the number of semaphore, if it is greater than number of semaphores SEMAPHORE_STATE_ENUM__ERROR_INVALID_ID is returned. Semaphore variable is then obtained based on the id argument by the function os_getOsSemaphoreVar. Next if condition then subsequently checks if the schedulable in execution which means the semaphore release requesting schedulable is a thread type SCHEDULABLE_INSTANCE_ENUM__THREAD. If not the semaphoreState is returned with the value SEMAPHORE_STATE_ENUM__ERROR_ONLY_THREADS_CAN_USE_SEMAPHORE. Then the function cosmosApiInternal_semaphore_trySemaphoreInternal is called if the core is in the privileged mode or semaphore_trySemaphoreInternal is called try to get semaphore and result is then returned as semaphore state. The if condition is implemented to check if the result from cosmosApiInternal_semaphore_trySemaphoreInternal is equal to the SEMAPHORE_STATE_ENUM__SUCCESSFULLY_LOCKED and if yes the schedulable owner member in semaphore variable is set to the schedulable in execution.
- Parameters
semaphoreId – [in] semaphore identifier
- Returns
CosmOS_SemaphoreStateType
-
CosmOS_SemaphoreStateType semaphore_releaseSemaphore(BitWidthType semaphoreId)¶
Release semaphore. DEMO.
The implementation contains obtaining of the operating system and core configuration by calling functions os_getOsCfg and CILcore_getCoreCfg. Then the operating system configuration in function os_getOsNumberOfSemaphores to get number of semaphores. The input element id argument is then checked againts the number of semaphore, if it is greater than number of semaphores SEMAPHORE_STATE_ENUM__ERROR_INVALID_ID is returned. Semaphore variable is then obtained based on the id argument by the function os_getOsSemaphoreVar. Next if condition then subsequently checks if the schedulable in execution which means the semaphore release requesting schedulable is a thread type SCHEDULABLE_INSTANCE_ENUM__THREAD. If not the semaphoreState is returned with the value SEMAPHORE_STATE_ENUM__ERROR_ONLY_THREADS_CAN_USE_SEMAPHORE. The the boolean is obtained by calling function semaphore_ownsSchedulableSemaphore to know if the requesting schedulable owns the semaphore which means if the schedulable locked the semaphore before. The semaphore member of the semaphore variable structure is compared in the implemented if condition that checks if the semaphore is equal to the state SEMAPHORE_STATE_ENUM__OCCUPIED otherwise the semaphore state is returned with the value SEMAPHORE_STATE_ENUM__ERROR_NOT_IN_OCCUPIED_STATE. Another nested if condition is implemented to check the obtained boolean variable that stores value if the requesting schedulable owns the semaphore. If yes the cosmosApiInternal_semaphore_releaseSemaphoreInternal function is called if the core is in the privileged mode or semaphore_releaseSemaphoreInternal is called and the result is returned as semaphore state. Otherwise the semaphore state is SEMAPHORE_STATE_ENUM__ERROR_SCHEDULABLE_IS_NOT_OWNER.
- Parameters
semaphoreId – [in] semaphore identifier
- Returns
CosmOS_SemaphoreStateType
-
CosmOS_BooleanType semaphore_willCauseDeadlock(CosmOS_CoreConfigurationType *core, CosmOS_SemaphoreVariableType *semaphoreVar)¶
Check if the semaphore will ends up in deadlock. DEMO.
- Parameters
core – [in] configuration pointer
semaphoreVar – [in] pointer
- Returns
CosmOS_BufferStateType
-
CosmOS_BooleanType semaphore_ownsSchedulableSemaphore(CosmOS_CoreConfigurationType *core, CosmOS_SemaphoreVariableType *semaphoreVar)¶
Check if the schedulable in execution owns the current semaphore.
- Parameters
core – [in] configuration pointer
semaphoreVar – [in] pointer
- Returns
CosmOS_BufferStateType
-
CosmOS_SemaphoreStateType semaphore_trySemaphoreInternal(BitWidthType id, CosmOS_SemaphoreVariableType *semaphoreVar, BitWidthType semaphoreId)¶