summaryrefslogtreecommitdiff
path: root/firmware/kernel/include/mrsw_lock.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/kernel/include/mrsw_lock.h')
-rw-r--r--firmware/kernel/include/mrsw_lock.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/firmware/kernel/include/mrsw_lock.h b/firmware/kernel/include/mrsw_lock.h
new file mode 100644
index 0000000000..fbfe1d405d
--- /dev/null
+++ b/firmware/kernel/include/mrsw_lock.h
@@ -0,0 +1,54 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2014 by Michael Sevakis
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#ifndef MRSW_LOCK_H
22#define MRSW_LOCK_H
23
24/* Multi-reader, single-writer object that allows mutltiple readers or a
25 * single writer thread access to a critical section.
26 *
27 * Readers and writers, as with a mutex, may claim the lock recursively for
28 * the same type of access they were already granted.
29 *
30 * Writers are trivially granted read access by ignoring the request; the
31 * object is not changed.
32 *
33 * Reader promotion to writer is NOT supported and a reader attempting write
34 * access will result in a deadlock. That could change but for now, be warned.
35 *
36 * Full priority inheritance is implemented.
37 */
38struct mrsw_lock
39{
40 int volatile count; /* rd/wr counter; >0 = reader(s), <0 = writer */
41 struct thread_entry *queue;
42 struct blocker_splay splay; /* priority inheritance info
43 for waiters */
44 uint8_t rdrecursion[MAXTHREADS]; /* per-thread reader recursion counts */
45 IF_COP( struct corelock cl; )
46};
47
48void mrsw_init(struct mrsw_lock *mrsw);
49void mrsw_read_acquire(struct mrsw_lock *mrsw);
50void mrsw_read_release(struct mrsw_lock *mrsw);
51void mrsw_write_acquire(struct mrsw_lock *mrsw);
52void mrsw_write_release(struct mrsw_lock *mrsw);
53
54#endif /* MRSW_LOCK_H */