diff options
Diffstat (limited to 'firmware/kernel/include/mutex.h')
-rw-r--r-- | firmware/kernel/include/mutex.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/firmware/kernel/include/mutex.h b/firmware/kernel/include/mutex.h new file mode 100644 index 0000000000..bcf5701bd9 --- /dev/null +++ b/firmware/kernel/include/mutex.h | |||
@@ -0,0 +1,62 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Björn Stenberg | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef MUTEX_H | ||
23 | #define MUTEX_H | ||
24 | |||
25 | #include <stdbool.h> | ||
26 | #include "config.h" | ||
27 | #include "thread.h" | ||
28 | |||
29 | struct mutex | ||
30 | { | ||
31 | struct thread_entry *queue; /* waiter list */ | ||
32 | int recursion; /* lock owner recursion count */ | ||
33 | #ifdef HAVE_PRIORITY_SCHEDULING | ||
34 | struct blocker blocker; /* priority inheritance info | ||
35 | for waiters */ | ||
36 | bool no_preempt; /* don't allow higher-priority thread | ||
37 | to be scheduled even if woken */ | ||
38 | #else | ||
39 | struct thread_entry *thread; /* Indicates owner thread - an owner | ||
40 | implies a locked state - same goes | ||
41 | for priority scheduling | ||
42 | (in blocker struct for that) */ | ||
43 | #endif | ||
44 | IF_COP( struct corelock cl; ) /* multiprocessor sync */ | ||
45 | }; | ||
46 | |||
47 | extern void mutex_init(struct mutex *m); | ||
48 | extern void mutex_lock(struct mutex *m); | ||
49 | extern void mutex_unlock(struct mutex *m); | ||
50 | #ifdef HAVE_PRIORITY_SCHEDULING | ||
51 | /* Deprecated temporary function to disable mutex preempting a thread on | ||
52 | * unlock - firmware/drivers/fat.c and a couple places in apps/buffering.c - | ||
53 | * reliance on it is a bug! */ | ||
54 | static inline void mutex_set_preempt(struct mutex *m, bool preempt) | ||
55 | { m->no_preempt = !preempt; } | ||
56 | #else | ||
57 | /* Deprecated but needed for now - firmware/drivers/ata_mmc.c */ | ||
58 | static inline bool mutex_test(const struct mutex *m) | ||
59 | { return m->thread != NULL; } | ||
60 | #endif /* HAVE_PRIORITY_SCHEDULING */ | ||
61 | |||
62 | #endif /* MUTEX_H */ | ||