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