1a9643ea8Slogwang /*
2a9643ea8Slogwang * Copyright (c) 2010 Kip Macy All rights reserved.
3*2317ada5Sfengbojiang * Copyright (C) 2017-2021 THL A29 Limited, a Tencent company.
4a9643ea8Slogwang * All rights reserved.
5a9643ea8Slogwang *
6a9643ea8Slogwang * Redistribution and use in source and binary forms, with or without
7a9643ea8Slogwang * modification, are permitted provided that the following conditions are met:
8a9643ea8Slogwang *
9a9643ea8Slogwang * 1. Redistributions of source code must retain the above copyright notice, this
10a9643ea8Slogwang * list of conditions and the following disclaimer.
11a9643ea8Slogwang * 2. Redistributions in binary form must reproduce the above copyright notice,
12a9643ea8Slogwang * this list of conditions and the following disclaimer in the documentation
13a9643ea8Slogwang * and/or other materials provided with the distribution.
14a9643ea8Slogwang *
15a9643ea8Slogwang * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16a9643ea8Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17a9643ea8Slogwang * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18a9643ea8Slogwang * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19a9643ea8Slogwang * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20a9643ea8Slogwang * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21a9643ea8Slogwang * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22a9643ea8Slogwang * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23a9643ea8Slogwang * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24a9643ea8Slogwang * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25a9643ea8Slogwang *
26a9643ea8Slogwang */
27a9643ea8Slogwang
28a9643ea8Slogwang #ifndef _FSTACK_MACHINE_PCPU_H_
29a9643ea8Slogwang #define _FSTACK_MACHINE_PCPU_H_
30a9643ea8Slogwang
31a9643ea8Slogwang #include_next <machine/pcpu.h>
32a9643ea8Slogwang
33a9643ea8Slogwang #undef __curthread
34d9ca4c12Sfengbojiang #undef get_pcpu
35a9643ea8Slogwang #undef PCPU_GET
36a9643ea8Slogwang #undef PCPU_ADD
37a9643ea8Slogwang #undef PCPU_INC
38a9643ea8Slogwang #undef PCPU_PTR
39a9643ea8Slogwang #undef PCPU_SET
40a9643ea8Slogwang
41a9643ea8Slogwang extern __thread struct thread *pcurthread;
42a9643ea8Slogwang extern struct pcpu *pcpup;
43a9643ea8Slogwang
44d9ca4c12Sfengbojiang #define get_pcpu() (pcpup->pc_ ## prvspace)
45d9ca4c12Sfengbojiang
46a9643ea8Slogwang #define PCPU_GET(member) (pcpup->pc_ ## member)
47a9643ea8Slogwang #define PCPU_ADD(member, val) (pcpup->pc_ ## member += (val))
48a9643ea8Slogwang #define PCPU_INC(member) PCPU_ADD(member, 1)
49a9643ea8Slogwang #define PCPU_PTR(member) (&pcpup->pc_ ## member)
50a9643ea8Slogwang #define PCPU_SET(member, val) (pcpup->pc_ ## member = (val))
51a9643ea8Slogwang
52a9643ea8Slogwang static __inline struct thread *
__curthread_ff(void)53a9643ea8Slogwang __curthread_ff(void)
54a9643ea8Slogwang {
55a9643ea8Slogwang return (pcurthread);
56a9643ea8Slogwang }
57a9643ea8Slogwang
5822ce4affSfengbojiang #ifndef __curthread
59a9643ea8Slogwang #define __curthread __curthread_ff
6022ce4affSfengbojiang #endif
61a9643ea8Slogwang
62a9643ea8Slogwang #ifndef curthread
63a9643ea8Slogwang #define curthread __curthread_ff()
64a9643ea8Slogwang #endif
6522ce4affSfengbojiang
66a9643ea8Slogwang #endif /* _FSTACK_MACHINE_PCPU_H_ */
67