xref: /f-stack/lib/include/sys/mutex.h (revision 2317ada5)
1a9643ea8Slogwang /*
2*2317ada5Sfengbojiang  * Copyright (C) 2017-2021 THL A29 Limited, a Tencent company.
3a9643ea8Slogwang  * All rights reserved.
4a9643ea8Slogwang  *
5a9643ea8Slogwang  * Redistribution and use in source and binary forms, with or without
6a9643ea8Slogwang  * modification, are permitted provided that the following conditions are met:
7a9643ea8Slogwang  *
8a9643ea8Slogwang  * 1. Redistributions of source code must retain the above copyright notice, this
9a9643ea8Slogwang  *   list of conditions and the following disclaimer.
10a9643ea8Slogwang  * 2. Redistributions in binary form must reproduce the above copyright notice,
11a9643ea8Slogwang  *   this list of conditions and the following disclaimer in the documentation
12a9643ea8Slogwang  *   and/or other materials provided with the distribution.
13a9643ea8Slogwang  *
14a9643ea8Slogwang  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15a9643ea8Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16a9643ea8Slogwang  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17a9643ea8Slogwang  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18a9643ea8Slogwang  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19a9643ea8Slogwang  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20a9643ea8Slogwang  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21a9643ea8Slogwang  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22a9643ea8Slogwang  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23a9643ea8Slogwang  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24a9643ea8Slogwang  *
25a9643ea8Slogwang  */
26a9643ea8Slogwang 
27a9643ea8Slogwang #ifndef _FSTACK_SYS_MUTEX_H_
28a9643ea8Slogwang #define _FSTACK_SYS_MUTEX_H_
29a9643ea8Slogwang #include_next <sys/mutex.h>
30a9643ea8Slogwang 
31a9643ea8Slogwang #undef __mtx_lock
32a9643ea8Slogwang #undef __mtx_unlock
33a9643ea8Slogwang #undef __mtx_lock_spin
34a9643ea8Slogwang #undef __mtx_unlock_spin
35a9643ea8Slogwang 
36a9643ea8Slogwang #undef _mtx_lock_flags
37a9643ea8Slogwang #undef _mtx_unlock_flags
38a9643ea8Slogwang #undef _mtx_lock_spin_flags
39a9643ea8Slogwang #undef _mtx_unlock_spin_flags
40a9643ea8Slogwang 
41a9643ea8Slogwang #undef thread_lock_flags_
42a9643ea8Slogwang #undef thread_lock
43a9643ea8Slogwang #undef thread_lock_flags
44a9643ea8Slogwang #undef thread_unlock
45a9643ea8Slogwang 
46a9643ea8Slogwang #undef mtx_trylock_flags_
47a9643ea8Slogwang #undef _mtx_trylock_spin_flags
48a9643ea8Slogwang #undef __mtx_trylock_spin
49a9643ea8Slogwang 
50a9643ea8Slogwang #undef mtx_init
51a9643ea8Slogwang #undef mtx_destroy
52a9643ea8Slogwang #undef mtx_owned
53a9643ea8Slogwang 
54d9ca4c12Sfengbojiang #undef DROP_GIANT
55d9ca4c12Sfengbojiang #undef PICKUP_GIANT
56d9ca4c12Sfengbojiang 
57a9643ea8Slogwang #define DO_NOTHING do {} while(0)
58a9643ea8Slogwang 
59a9643ea8Slogwang #define __mtx_lock(mp, tid, opts, file, line) DO_NOTHING
60a9643ea8Slogwang #define __mtx_unlock(mp, tid, opts, file, line) DO_NOTHING
61a9643ea8Slogwang #define __mtx_lock_spin(mp, tid, opts, file, line) DO_NOTHING
62a9643ea8Slogwang #define __mtx_unlock_spin(mp) DO_NOTHING
63a9643ea8Slogwang 
64a9643ea8Slogwang #define _mtx_lock_flags(m, opts, file, line) DO_NOTHING
65a9643ea8Slogwang #define _mtx_unlock_flags(m, opts, file, line) DO_NOTHING
66a9643ea8Slogwang #define _mtx_lock_spin_flags(m, opts, file, line) DO_NOTHING
67a9643ea8Slogwang #define _mtx_unlock_spin_flags(m, opts, file, line) DO_NOTHING
68a9643ea8Slogwang 
69a9643ea8Slogwang #define thread_lock_flags_(tdp, opts, file, line) DO_NOTHING
70a9643ea8Slogwang #define thread_lock(tdp) DO_NOTHING
71a9643ea8Slogwang #define thread_lock_flags(tdp, opt)    DO_NOTHING
72a9643ea8Slogwang #define thread_unlock(tdp) DO_NOTHING
73a9643ea8Slogwang 
74a9643ea8Slogwang #define mtx_trylock_flags_(m, o, f, l) 1
75a9643ea8Slogwang #define _mtx_trylock_spin_flags(m, o, f, l) 1
76a9643ea8Slogwang #define __mtx_trylock_spin(m, t, o, f, l) 1
77a9643ea8Slogwang 
78a9643ea8Slogwang void ff_mtx_init(struct lock_object *lo, const char *name, const char *type, int opts);
79a9643ea8Slogwang 
80a9643ea8Slogwang #define mtx_init(m, n, t, o) \
81a9643ea8Slogwang     ff_mtx_init(&(m)->lock_object, n, t, o)
82a9643ea8Slogwang 
83a9643ea8Slogwang #define mtx_destroy(m) DO_NOTHING
84a9643ea8Slogwang 
85a9643ea8Slogwang #define mtx_owned(m)    (1)
86a9643ea8Slogwang 
87d9ca4c12Sfengbojiang #define DROP_GIANT()    DO_NOTHING
88d9ca4c12Sfengbojiang #define PICKUP_GIANT()  DO_NOTHING
89d9ca4c12Sfengbojiang 
90a9643ea8Slogwang #endif    /* _FSTACK_SYS_MUTEX_H_ */
91