mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-24 22:13:52 +01:00
cpu/esp32: changes for retagetable locking
This commit is contained in:
parent
881a92fe47
commit
839cf4223d
73
cpu/esp32/include/sys/lock.h
Normal file
73
cpu/esp32/include/sys/lock.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Gunar Schorcht
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup cpu_esp32
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Wrapper for sys/lock.h
|
||||
*
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
*
|
||||
* This file is a wrapper for sys/lock.h to ensure source code compatibility
|
||||
* even if retargetable locking is enabled in newlib.
|
||||
*/
|
||||
|
||||
#ifndef SYS_LOCK_H
|
||||
#define SYS_LOCK_H
|
||||
|
||||
#ifndef DOXYGEN
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include_next <sys/lock.h>
|
||||
|
||||
#if defined(_RETARGETABLE_LOCKING)
|
||||
|
||||
/*
|
||||
* The structured lock type has to be large enough to hold a recursive mutex.
|
||||
* Since `rmutex.h` cannot be included in this stage of header inclusion,
|
||||
* `sizeof` cannot be used here and an array of sufficient size has to be
|
||||
* defined. This is ensured by a `static_assert` in `cpu/esp_common/syscalls.c`.
|
||||
*/
|
||||
typedef struct __lock {
|
||||
void *reserved[2];
|
||||
} __lock_t;
|
||||
|
||||
#endif /* defined(_RETARGETABLE_LOCKING) */
|
||||
|
||||
/*
|
||||
* Declarations for source code compatibility. These functions were used
|
||||
* in earlier newlib versions. In newer newlib versions, either the
|
||||
* __lock_* or __retarget_* functions are used. They are still used in
|
||||
* ESP-IDF.
|
||||
*/
|
||||
|
||||
typedef _LOCK_T _lock_t;
|
||||
|
||||
void _lock_init(_lock_t *lock);
|
||||
void _lock_init_recursive(_lock_t *lock);
|
||||
void _lock_close(_lock_t *lock);
|
||||
void _lock_close_recursive(_lock_t *lock);
|
||||
void _lock_acquire(_lock_t *lock);
|
||||
void _lock_acquire_recursive(_lock_t *lock);
|
||||
int _lock_try_acquire(_lock_t *lock);
|
||||
int _lock_try_acquire_recursive(_lock_t *lock);
|
||||
void _lock_release(_lock_t *lock);
|
||||
void _lock_release_recursive(_lock_t *lock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DOXYGEN */
|
||||
#endif /* SYS_LOCK_H */
|
||||
/** @} */
|
||||
@ -252,6 +252,77 @@ void IRAM_ATTR _lock_release_recursive(_lock_t *lock)
|
||||
rmutex_unlock((rmutex_t*)*lock);
|
||||
}
|
||||
|
||||
#if defined(_RETARGETABLE_LOCKING)
|
||||
|
||||
/* check whether `struct __lock` is large enough to hold a recursive mutex */
|
||||
static_assert(sizeof(struct __lock) >= sizeof(rmutex_t),
|
||||
"struct __lock is too small to hold a recursive mutex of type rmutex_t");
|
||||
|
||||
/* definition of locks required by the newlib if retargetable locking is used */
|
||||
struct __lock __lock___sinit_recursive_mutex;
|
||||
struct __lock __lock___sfp_recursive_mutex;
|
||||
struct __lock __lock___atexit_recursive_mutex;
|
||||
struct __lock __lock___at_quick_exit_mutex;
|
||||
struct __lock __lock___malloc_recursive_mutex;
|
||||
struct __lock __lock___env_recursive_mutex;
|
||||
struct __lock __lock___tz_mutex;
|
||||
struct __lock __lock___dd_hash_mutex;
|
||||
struct __lock __lock___arc4random_mutex;
|
||||
|
||||
/* map newlib's `__retarget_*` functions to the existing `_lock_*` functions */
|
||||
|
||||
void __retarget_lock_init(_LOCK_T *lock)
|
||||
{
|
||||
_lock_init(lock);
|
||||
}
|
||||
|
||||
extern void __retarget_lock_init_recursive(_LOCK_T *lock)
|
||||
{
|
||||
_lock_init_recursive(lock);
|
||||
}
|
||||
|
||||
void __retarget_lock_close(_LOCK_T lock)
|
||||
{
|
||||
_lock_close(&lock);
|
||||
}
|
||||
|
||||
void __retarget_lock_close_recursive(_LOCK_T lock)
|
||||
{
|
||||
_lock_close_recursive(&lock);
|
||||
}
|
||||
|
||||
void __retarget_lock_acquire(_LOCK_T lock)
|
||||
{
|
||||
_lock_acquire(&lock);
|
||||
}
|
||||
|
||||
void __retarget_lock_acquire_recursive(_LOCK_T lock)
|
||||
{
|
||||
_lock_acquire_recursive(&lock);
|
||||
}
|
||||
|
||||
int __retarget_lock_try_acquire(_LOCK_T lock)
|
||||
{
|
||||
return _lock_try_acquire(&lock);
|
||||
}
|
||||
|
||||
int __retarget_lock_try_acquire_recursive(_LOCK_T lock)
|
||||
{
|
||||
return _lock_try_acquire_recursive(&lock);
|
||||
}
|
||||
|
||||
void __retarget_lock_release(_LOCK_T lock)
|
||||
{
|
||||
_lock_release(&lock);
|
||||
}
|
||||
|
||||
void __retarget_lock_release_recursive(_LOCK_T lock)
|
||||
{
|
||||
_lock_release(&lock);
|
||||
}
|
||||
|
||||
#endif /* _RETARGETABLE_LOCKING */
|
||||
|
||||
/**
|
||||
* @name Memory allocation functions
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user