forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmutex.h
More file actions
43 lines (34 loc) · 774 Bytes
/
mutex.h
File metadata and controls
43 lines (34 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2022 Intel Corporation. All rights reserved.
*
*/
/*
* Simple mutex implementation for SOF.
*/
#ifndef __XTOS_RTOS_MUTEX_H
#define __XTOS_RTOS_MUTEX_H
#include <rtos/kernel.h>
#include <rtos/spinlock.h>
#include <stdint.h>
#define K_FOREVER ((k_timeout_t) { .ticks = 0xffffffff })
struct k_mutex {
struct k_spinlock lock;
k_spinlock_key_t key;
};
static inline int k_mutex_init(struct k_mutex *mutex)
{
k_spinlock_init(&mutex->lock);
return 0;
}
static inline int k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout)
{
mutex->key = k_spin_lock(&mutex->lock);
return 0;
}
static inline int k_mutex_unlock(struct k_mutex *mutex)
{
k_spin_unlock(&mutex->lock, mutex->key);
return 0;
}
#endif