QP/C  5.9.3
qxk_mutex.c File Reference

QXMutex_init(), QXMutex_lock and QXMutex_unlock() definitions. More...

#include "qf_port.h"
#include "qxk_pkg.h"
#include "qassert.h"
#include "qs_port.h"

Go to the source code of this file.

Macros

#define QP_IMPL   /* this is QP implementation */
 

Enumerations

enum  { MUTEX_UNUSED = 0xFF }
 

Functions

void QXMutex_init (QXMutex *const me, uint_fast8_t prio)
 The QXMutex initialization. More...
 
void QXMutex_lock (QXMutex *const me)
 QXMutex lock. More...
 
void QXMutex_unlock (QXMutex *const me)
 QXMutex unlock. More...
 

Detailed Description

QXMutex_init(), QXMutex_lock and QXMutex_unlock() definitions.

Definition in file qxk_mutex.c.

Function Documentation

◆ QXMutex_init()

void QXMutex_init ( QXMutex *const  me,
uint_fast8_t  prio 
)

The QXMutex initialization.

Description
Initializes QXK priority-ceiling mutex to the specified ceiling priority.
Parameters
[in,out]mepointer (see Object Orientation)
[in]prioceiling priority of the mutex
Note
A mutex must be initialized before it can be locked or unlocked.
See also
QXMutex_lock(), QXMutex_unlock()
Usage
The following example shows how to initialize, lock and unlock QXK mutex:
QXMutex l_rndMutex; /* mutex to protect the random number generator */
void BSP_randomSeed(uint32_t seed) {
QXMutex_init(&l_rndMutex, N_PHILO); /* <== initialize the mutex */
l_rnd = seed;
}
uint32_t BSP_random(void) { /* a very cheap pseudo-random-number generator */
uint32_t rnd;
QXMutex_lock(&l_rndMutex); /* <== lock the shared random seed */
/* "Super-Duper" Linear Congruential Generator (LCG) */
rnd = l_rnd * (3U*7U*11U*13U*23U);
l_rnd = rnd; /* set for the next time */
QXMutex_unlock(&l_rndMutex); /* <== unlock the shared random seed */
return rnd;
}

Definition at line 78 of file qxk_mutex.c.

◆ QXMutex_lock()

void QXMutex_lock ( QXMutex *const  me)

QXMutex lock.

Description
This function locks the QXK mutex.
Parameters
[in,out]mepointer (see Object Orientation)
Note
A mutex must be initialized before it can be locked or unlocked.
A QXK mutex can be used from both basic threads (AOs) and extended threads.
QXMutex_lock() must be always followed by the corresponding QXMutex_unlock().
Attention
QXK will fire an assertion if a thread holding the mutex attempts to block.
See also
QXMutex_init(), QXMutex_unlock()
Usage
The following example shows how to initialize, lock and unlock QXK mutex:
QXMutex l_rndMutex; /* mutex to protect the random number generator */
void BSP_randomSeed(uint32_t seed) {
QXMutex_init(&l_rndMutex, N_PHILO); /* <== initialize the mutex */
l_rnd = seed;
}
uint32_t BSP_random(void) { /* a very cheap pseudo-random-number generator */
uint32_t rnd;
QXMutex_lock(&l_rndMutex); /* <== lock the shared random seed */
/* "Super-Duper" Linear Congruential Generator (LCG) */
rnd = l_rnd * (3U*7U*11U*13U*23U);
l_rnd = rnd; /* set for the next time */
QXMutex_unlock(&l_rndMutex); /* <== unlock the shared random seed */
return rnd;
}
Precondition
scheduler cannot be locked from the ISR context and the mutex must be unused

Definition at line 110 of file qxk_mutex.c.

◆ QXMutex_unlock()

void QXMutex_unlock ( QXMutex *const  me)

QXMutex unlock.

Description
This function unlocks the QXK mutex.
Parameters
[in]mepointer (see Object Orientation)
Note
A mutex must be initialized before it can be locked or unlocked.
A QXK mutex can be used from both basic threads (AOs) and extended threads.
QXMutex_unlock() must always follow the corresponding QXMutex_lock().
Attention
QXK will fire an assertion if a thread holding the mutex attempts to block.
See also
QXMutex_init(), QXMutex_lock()
Usage
The following example shows how to initialize, lock and unlock QXK mutex:
QXMutex l_rndMutex; /* mutex to protect the random number generator */
void BSP_randomSeed(uint32_t seed) {
QXMutex_init(&l_rndMutex, N_PHILO); /* <== initialize the mutex */
l_rnd = seed;
}
uint32_t BSP_random(void) { /* a very cheap pseudo-random-number generator */
uint32_t rnd;
QXMutex_lock(&l_rndMutex); /* <== lock the shared random seed */
/* "Super-Duper" Linear Congruential Generator (LCG) */
rnd = l_rnd * (3U*7U*11U*13U*23U);
l_rnd = rnd; /* set for the next time */
QXMutex_unlock(&l_rndMutex); /* <== unlock the shared random seed */
return rnd;
}
Precondition
scheduler cannot be unlocked from the ISR context and the mutex must NOT be unused

Definition at line 166 of file qxk_mutex.c.