lock_core.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_LOCK_CORE_H
8#define _PICO_LOCK_CORE_H
9
10#include "pico.h"
11#include "pico/time.h"
12#include "hardware/sync.h"
13
41// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_LOCK_CORE, Enable/disable assertions in the lock core, type=bool, default=0, group=pico_sync
42#ifndef PARAM_ASSERTIONS_ENABLED_LOCK_CORE
43#define PARAM_ASSERTIONS_ENABLED_LOCK_CORE 0
44#endif
45
53struct lock_core {
54 // spin lock protecting this lock's state
55 spin_lock_t *spin_lock;
56
57 // note any lock members in containing structures need not be volatile;
58 // they are protected by memory/compiler barriers when gaining and release spin locks
59};
60
61typedef struct lock_core lock_core_t;
62
72void lock_init(lock_core_t *core, uint lock_num);
73
74#ifndef lock_owner_id_t
81#define lock_owner_id_t int8_t
82#endif
83
84#ifndef LOCK_INVALID_OWNER_ID
88#define LOCK_INVALID_OWNER_ID ((lock_owner_id_t)-1)
89#endif
90
91#ifndef lock_get_caller_owner_id
97#define lock_get_caller_owner_id() ((lock_owner_id_t)get_core_num())
98#ifndef lock_is_owner_id_valid
99#define lock_is_owner_id_valid(id) ((id)>=0)
100#endif
101#endif
102
103#ifndef lock_is_owner_id_valid
104#define lock_is_owner_id_valid(id) ((id) != LOCK_INVALID_OWNER_ID)
105#endif
106
107#ifndef lock_internal_spin_unlock_with_wait
128#define lock_internal_spin_unlock_with_wait(lock, save) spin_unlock((lock)->spin_lock, save), __wfe()
129#endif
130
131#ifndef lock_internal_spin_unlock_with_notify
151#define lock_internal_spin_unlock_with_notify(lock, save) spin_unlock((lock)->spin_lock, save), __sev()
152#endif
153
154#ifndef lock_internal_spin_unlock_with_best_effort_wait_or_timeout
177#define lock_internal_spin_unlock_with_best_effort_wait_or_timeout(lock, save, until) ({ \
178 spin_unlock((lock)->spin_lock, save); \
179 best_effort_wfe_or_timeout(until); \
180})
181#endif
182
183#ifndef sync_internal_yield_until_before
196#define sync_internal_yield_until_before(until) ((void)0)
197#endif
198
199#endif
void lock_init(lock_core_t *core, uint lock_num)
Initialise a lock structure.
Definition: lock_core.c:9
Definition: lock_core.h:53