Skip to content

Commit 2907b16

Browse files
committed
threads: Switch mutexes and conds to futex-based implementation
1 parent f632fca commit 2907b16

File tree

5 files changed

+306
-57
lines changed

5 files changed

+306
-57
lines changed

include/sys/interrupt.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424
extern "C" {
2525
#endif
2626

27-
28-
extern int interrupt(unsigned int n, int (*f)(unsigned int, void *), void *arg, handle_t cond, handle_t *handle);
29-
27+
/* number, handler func, func argument, cond handle, result resource handle */
28+
#define interrupt(n, f, arg, c, h) __interrupt((n), (f), (arg), (c), (h))
3029

3130
#ifdef __cplusplus
3231
}

include/sys/threads.h

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@
2828
extern "C" {
2929
#endif
3030

31+
extern int __mutexUnlock(handle_t m);
32+
#define mutexUnlock(m) __mutexUnlock((m))
33+
34+
extern int __mutexTry(handle_t m);
35+
#define mutexTry(m) __mutexTry((m))
36+
37+
#define phMutexLock(m) mutexLock((m))
38+
39+
extern void _uresource_init(void);
40+
41+
extern int __resourceDestroy(handle_t r);
42+
#define resourceDestroy(r) __resourceDestroy((r))
43+
44+
extern int __condBroadcast(handle_t h);
45+
#define condBroadcast(h) __condBroadcast((h))
46+
47+
extern int __condSignal(handle_t h);
48+
#define condSignal(h) __condSignal((h))
49+
50+
#define phCondWait(c, m, t) condWait((c), (m), (t))
3151

3252
typedef struct {
3353
handle_t mutex;
@@ -73,8 +93,7 @@ extern int threadJoin(int tid, time_t timeout);
7393
extern int beginthreadex(void (*start)(void *), unsigned int priority, void *stack, unsigned int stacksz, void *arg, handle_t *id);
7494

7595

76-
__attribute__((noreturn))
77-
extern void endthread(void);
96+
__attribute__((noreturn)) extern void endthread(void);
7897

7998

8099
static inline int beginthread(void (*start)(void *), unsigned int priority, void *stack, unsigned int stacksz, void *arg)
@@ -89,33 +108,22 @@ extern int threadsinfo(int n, threadinfo_t *info);
89108
extern int priority(int priority);
90109

91110

92-
extern int phMutexCreate(handle_t *h, const struct lockAttr *attr);
93-
94-
95111
extern int mutexCreate(handle_t *h);
96112

97113

98114
static inline int mutexCreateWithAttr(handle_t *h, const struct lockAttr *attr)
99115
{
100-
return phMutexCreate(h, attr);
116+
(void)attr;
117+
return mutexCreate(h);
101118
}
102119

103120

104-
extern int phMutexLock(handle_t h);
105-
106-
107121
extern int mutexLock(handle_t h);
108122

109123

110124
extern int mutexLock2(handle_t h1, handle_t h2);
111125

112126

113-
extern int mutexTry(handle_t h);
114-
115-
116-
extern int mutexUnlock(handle_t h);
117-
118-
119127
extern int semaphoreCreate(semaphore_t *s, unsigned int v);
120128

121129

@@ -128,33 +136,19 @@ extern int semaphoreUp(semaphore_t *s);
128136
extern int semaphoreDone(semaphore_t *s);
129137

130138

131-
extern int phCondCreate(handle_t *h, const struct condAttr *attr);
132-
133-
134139
extern int condCreate(handle_t *h);
135140

136141

137142
static inline int condCreateWithAttr(handle_t *h, const struct condAttr *attr)
138143
{
139-
return phCondCreate(h, attr);
144+
(void)attr;
145+
return condCreate(h);
140146
}
141147

142148

143149
extern int condWait(handle_t h, handle_t m, time_t timeout);
144150

145151

146-
extern int phCondWait(handle_t h, handle_t m, time_t timeout);
147-
148-
149-
extern int condSignal(handle_t h);
150-
151-
152-
extern int condBroadcast(handle_t h);
153-
154-
155-
extern int resourceDestroy(handle_t h);
156-
157-
158152
extern int signalHandle(void (*handler)(void), unsigned mask, unsigned mmask);
159153

160154

misc/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ extern void _errno_init(void);
2222
extern void _atexit_init(void);
2323
extern void _init_array(void);
2424
extern void _pthread_init(void);
25+
extern void _uresource_init(void);
2526

2627

2728
void _libc_init(void)
2829
{
2930
_atexit_init();
3031
_errno_init();
32+
_uresource_init();
3133
_malloc_init();
3234
_env_init();
3335
_signals_init();

0 commit comments

Comments
 (0)