ReactOS 0.4.16-dev-297-gc569aee
Collaboration diagram for Mutexes:

Functions

err_t sys_mutex_new (sys_mutex_t *mutex)
 
void sys_mutex_lock (sys_mutex_t *mutex)
 
void sys_mutex_unlock (sys_mutex_t *mutex)
 
void sys_mutex_free (sys_mutex_t *mutex)
 
int sys_mutex_valid (sys_mutex_t *mutex)
 
void sys_mutex_set_invalid (sys_mutex_t *mutex)
 

Detailed Description

Mutexes are recommended to correctly handle priority inversion, especially if you use LWIP_CORE_LOCKING .

Function Documentation

◆ sys_mutex_free()

void sys_mutex_free ( sys_mutex_t mutex)

Deallocates a mutex.

Parameters
mutexthe mutex to delete

Definition at line 157 of file sys_arch.c.

158{
159 /* parameter check */
160 LWIP_ASSERT("mutex != NULL", mutex != NULL);
161 LWIP_ASSERT("*mutex >= 1", *mutex >= 1);
162 *mutex = 0;
163}
#define NULL
Definition: types.h:112
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
Definition: module.h:456

◆ sys_mutex_lock()

void sys_mutex_lock ( sys_mutex_t mutex)

Blocks the thread until the mutex can be grabbed.

Parameters
mutexthe mutex to lock

Definition at line 173 of file sys_arch.c.

174{
175 /* nothing to do, no multithreading supported */
176 LWIP_ASSERT("mutex != NULL", mutex != NULL);
177 /* check that the mutext is valid and unlocked (no nested locking) */
178 LWIP_ASSERT("*mutex >= 1", *mutex == 1);
179 /* we count up just to check the correct pairing of lock/unlock */
180 (*mutex)++;
181 LWIP_ASSERT("*mutex >= 1", *mutex >= 1);
182}

Referenced by mem_malloc().

◆ sys_mutex_new()

err_t sys_mutex_new ( sys_mutex_t mutex)

Create a new mutex. Note that mutexes are expected to not be taken recursively by the lwIP code, so both implementation types (recursive or non-recursive) should work. The mutex is allocated to the memory that 'mutex' points to (which can be both a pointer or the actual OS structure). If the mutex has been created, ERR_OK should be returned. Returning any other error will provide a hint what went wrong, but except for assertions, no real error handling is implemented.

Parameters
mutexpointer to the mutex to create
Returns
ERR_OK if successful, another err_t otherwise

Definition at line 149 of file sys_arch.c.

150{
151 LWIP_ASSERT("mutex != NULL", mutex != NULL);
152 *mutex = 1; /* 1 allocated */
153 return ERR_OK;
154}
@ ERR_OK
Definition: err.h:55

Referenced by mem_init(), and tcpip_init().

◆ sys_mutex_set_invalid()

void sys_mutex_set_invalid ( sys_mutex_t mutex)

Invalidate a mutex so that sys_mutex_valid() returns 0. ATTENTION: This does NOT mean that the mutex shall be deallocated: sys_mutex_free() is always called before calling this function! This may also be a define, in which case the function is not prototyped.

Definition at line 166 of file sys_arch.c.

167{
168 LWIP_ASSERT("mutex != NULL", mutex != NULL);
169 *mutex = 0;
170}

◆ sys_mutex_unlock()

void sys_mutex_unlock ( sys_mutex_t mutex)

Releases the mutex previously locked through 'sys_mutex_lock()'.

Parameters
mutexthe mutex to unlock

Definition at line 185 of file sys_arch.c.

186{
187 /* nothing to do, no multithreading supported */
188 LWIP_ASSERT("mutex != NULL", mutex != NULL);
189 LWIP_ASSERT("*mutex >= 1", *mutex >= 1);
190 /* we count down just to check the correct pairing of lock/unlock */
191 (*mutex)--;
192 LWIP_ASSERT("*mutex >= 1", *mutex >= 1);
193}

Referenced by mem_malloc().

◆ sys_mutex_valid()

int sys_mutex_valid ( sys_mutex_t mutex)

Returns 1 if the mutes is valid, 0 if it is not valid. When using pointers, a simple way is to check the pointer for != NULL. When directly using OS structures, implementing this may be more complex. This may also be a define, in which case the function is not prototyped.