QP/C  5.9.3
qk_mutex.c File Reference

QMutex_init(), QMutex_lock and QMutex_unlock() definitions. More...

#include "qf_port.h"
#include "qf_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 QMutex_init (QMutex *const me, uint_fast8_t prio)
 The QMutex initialization. More...
 
void QMutex_lock (QMutex *const me)
 QMutex lock. More...
 
void QMutex_unlock (QMutex *const me)
 QMutex unlock. More...
 

Detailed Description

QMutex_init(), QMutex_lock and QMutex_unlock() definitions.

Definition in file qk_mutex.c.

Function Documentation

◆ QMutex_init()

void QMutex_init ( QMutex *const  me,
uint_fast8_t  prio 
)

The QMutex initialization.

Description
Initializes QK 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
QMutex_lock(), QMutex_unlock()
Usage
The following example shows how to initialize, lock and unlock QK mutex:
QMutex l_rndMutex; /* mutex to protect the random number generator */
void BSP_randomSeed(uint32_t seed) {
QMutex_init(&l_rndMutex, N_PHILO); /* ceiling == max Philo priority */
l_rnd = seed;
}
uint32_t BSP_random(void) { /* a very cheap pseudo-random-number generator */
uint32_t rnd;
QMutex_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 */
QMutex_unlock(&l_rndMutex); /* <== unlock the shared random seed */
return rnd;
}

Definition at line 78 of file qk_mutex.c.

◆ QMutex_lock()

void QMutex_lock ( QMutex *const  me)

QMutex lock.

Description
This function locks the QK mutex.
Parameters
[in,out]mepointer (see Object Orientation)
Note
A mutex must be initialized before it can be locked or unlocked.
QMutex_lock() must be always followed by the corresponding QMutex_unlock().
See also
QMutex_init(), QMutex_unlock()
Usage
The following example shows how to initialize, lock and unlock QK mutex:
QMutex l_rndMutex; /* mutex to protect the random number generator */
void BSP_randomSeed(uint32_t seed) {
QMutex_init(&l_rndMutex, N_PHILO); /* ceiling == max Philo priority */
l_rnd = seed;
}
uint32_t BSP_random(void) { /* a very cheap pseudo-random-number generator */
uint32_t rnd;
QMutex_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 */
QMutex_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 103 of file qk_mutex.c.

◆ QMutex_unlock()

void QMutex_unlock ( QMutex *const  me)

QMutex unlock.

Description
This function unlocks the QK mutex.
Parameters
[in]mepointer (see Object Orientation)
Note
A mutex must be initialized before it can be locked or unlocked.
QMutex_unlock() must always follow the corresponding QMutex_lock().
See also
QMutex_init(), QMutex_lock()
Usage
The following example shows how to initialize, lock and unlock QK mutex:
QMutex l_rndMutex; /* mutex to protect the random number generator */
void BSP_randomSeed(uint32_t seed) {
QMutex_init(&l_rndMutex, N_PHILO); /* ceiling == max Philo priority */
l_rnd = seed;
}
uint32_t BSP_random(void) { /* a very cheap pseudo-random-number generator */
uint32_t rnd;
QMutex_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 */
QMutex_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 146 of file qk_mutex.c.