1 | /* $Id: shthread.h 3448 2020-09-13 11:15:59Z bird $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * Shell thread methods.
|
---|
5 | *
|
---|
6 | * Copyright (c) 2007-2010 knut st. osmundsen <[email protected]>
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * This file is part of kBuild.
|
---|
10 | *
|
---|
11 | * kBuild is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * kBuild is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with kBuild; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef ___shthread_h___
|
---|
28 | #define ___shthread_h___
|
---|
29 |
|
---|
30 | #include "shtypes.h"
|
---|
31 |
|
---|
32 | typedef union shmtx
|
---|
33 | {
|
---|
34 | char b[64];
|
---|
35 | KU64 au64[64/sizeof(KU64)];
|
---|
36 | void *aptrs[64/sizeof(void *)];
|
---|
37 | } shmtx;
|
---|
38 |
|
---|
39 | /** Magic mutex value (final u64).
|
---|
40 | * This is used to detect whether the mutex has been initialized or not,
|
---|
41 | * allowing shmtx_delete to be called more than once without doing harm.
|
---|
42 | * @internal */
|
---|
43 | #define SHMTX_MAGIC KU64_C(0x8888000019641018) /**< Charles Stross */
|
---|
44 | /** Index into shmtx::au64 of the SHMTX_MAGIC value.
|
---|
45 | * @internal */
|
---|
46 | #define SHMTX_MAGIC_IDX (sizeof(shmtx) / sizeof(KU64) - 1)
|
---|
47 |
|
---|
48 | typedef struct shmtxtmp { int i; } shmtxtmp;
|
---|
49 |
|
---|
50 | typedef uintptr_t shtid;
|
---|
51 |
|
---|
52 | void shthread_set_shell(struct shinstance *);
|
---|
53 | struct shinstance *shthread_get_shell(void);
|
---|
54 |
|
---|
55 | int shmtx_init(shmtx *pmtx);
|
---|
56 | void shmtx_delete(shmtx *pmtx);
|
---|
57 | void shmtx_enter(shmtx *pmtx, shmtxtmp *ptmp);
|
---|
58 | void shmtx_leave(shmtx *pmtx, shmtxtmp *ptmp);
|
---|
59 |
|
---|
60 |
|
---|
61 | K_INLINE unsigned sh_atomic_inc(KU32 volatile *valuep)
|
---|
62 | {
|
---|
63 | #ifdef _MSC_VER
|
---|
64 | return _InterlockedIncrement((long *)valuep);
|
---|
65 | #else
|
---|
66 | return __sync_fetch_and_add(valuep, 1);
|
---|
67 | #endif
|
---|
68 | }
|
---|
69 |
|
---|
70 | K_INLINE unsigned sh_atomic_dec(unsigned volatile *valuep)
|
---|
71 | {
|
---|
72 | #ifdef _MSC_VER
|
---|
73 | return _InterlockedDecrement((long *)valuep);
|
---|
74 | #else
|
---|
75 | return __sync_fetch_and_sub(valuep, 1);
|
---|
76 | #endif
|
---|
77 | }
|
---|
78 |
|
---|
79 | #endif
|
---|
80 |
|
---|