#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <core/mutex.h>
#include <syscall.h>
#include <sys/syscall.h>
Go to the source code of this file.
|
typedef | TAILQ_HEAD (pthreadList, pthread) |
|
void | __pthread_init (void) |
|
pthread_t | pthread_self (void) |
|
void | pthreadCreateHelper (void *arg) |
|
int | pthread_create (pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) |
|
void | pthread_exit (void *value_ptr) |
|
int | pthread_join (pthread_t thread, void **value_ptr) |
|
void | pthread_yield (void) |
|
int | pthread_barrier_init (pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned count) |
|
int | pthread_barrier_destroy (pthread_barrier_t *barrier) |
|
int | pthread_barrier_wait (pthread_barrier_t *barrier) |
|
int | pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) |
|
int | pthread_mutex_destroy (pthread_mutex_t *mutex) |
|
int | pthread_mutex_lock (pthread_mutex_t *mutex) |
|
int | pthread_mutex_trylock (pthread_mutex_t *mutex) |
|
int | pthread_mutex_unlock (pthread_mutex_t *mutex) |
|
int | pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr) |
|
int | pthread_cond_destroy (pthread_cond_t *cond) |
|
int | pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) |
|
int | pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) |
|
int | pthread_cond_signal (pthread_cond_t *cond) |
|
int | pthread_cond_broadcast (pthread_cond_t *cond) |
|
◆ pthread_attr
◆ pthread
◆ pthread_mutexattr
◆ pthread_mutex
◆ pthread_condattr
◆ pthread_cond
◆ THREAD_HASH_SLOTS
#define THREAD_HASH_SLOTS 32 |
◆ __pthread_init()
void __pthread_init |
( |
void |
| ) |
|
Definition at line 53 of file pthread.c.
54{
55 int i;
57
60 }
61
64 }
65
69 thr->arg = 0;
70
72
76}
void CoreMutex_Lock(CoreMutex *mtx)
void CoreMutex_Unlock(CoreMutex *mtx)
void CoreMutex_Init(CoreMutex *mtx)
#define THREAD_HASH_SLOTS
#define TAILQ_INSERT_HEAD(head, elm, field)
_Noreturn void abort(void)
◆ pthread_barrier_destroy()
◆ pthread_barrier_init()
◆ pthread_barrier_wait()
◆ pthread_cond_broadcast()
Definition at line 459 of file pthread.c.
460{
462
465 if (status != 0)
466 return status;
467 }
468 cnd = *cond;
469
473
474 return 0;
475}
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
◆ pthread_cond_destroy()
Definition at line 344 of file pthread.c.
345{
347
350
351 return 0;
352}
◆ pthread_cond_init()
Definition at line 326 of file pthread.c.
327{
329
332 }
333
337
338 *cond = cnd;
339
340 return 0;
341}
◆ pthread_cond_signal()
Definition at line 440 of file pthread.c.
441{
443
446 if (status != 0)
447 return status;
448 }
449 cnd = *cond;
450
454
455 return 0;
456}
◆ pthread_cond_timedwait()
Definition at line 393 of file pthread.c.
395{
396 int status = 0;
397 int rstatus = 0;
401
404 if (status != 0)
405 return status;
406 }
407 cnd = *cond;
408
409 if (mutex) {
411 if (status != 0)
412 return status;
413 }
414
419
420 while (level >= cnd->
exit) {
422
425 break;
426 }
427 }
428
429 if (mutex) {
431 if (status != 0)
432 return status;
433 }
434
435 return rstatus;
436}
int OSThreadSleep(uint64_t time)
int pthread_mutex_lock(pthread_mutex_t *mutex)
int pthread_mutex_unlock(pthread_mutex_t *mutex)
◆ pthread_cond_wait()
Definition at line 355 of file pthread.c.
356{
357 int status;
360
363 if (status != 0)
364 return status;
365 }
366 cnd = *cond;
367
368 if (mutex) {
370 if (status != 0)
371 return status;
372 }
373
378
379 while (level >= cnd->
exit) {
381 }
382
383 if (mutex) {
385 if (status != 0)
386 return status;
387 }
388
389 return 0;
390}
◆ pthread_create()
int pthread_create |
( |
pthread_t * |
thread, |
|
|
const pthread_attr_t * |
attr, |
|
|
void *(*)(void *) |
start_routine, |
|
|
void * |
arg |
|
) |
| |
Definition at line 108 of file pthread.c.
110{
113
114 thr =
malloc(
sizeof(*thr));
115 if (!thr) {
117 }
118
119 memset(thr, 0,
sizeof(*thr));
120
121 thr->entry = start_routine;
122 thr->arg = arg;
123
128 }
129
131
135
136 *thread = thr;
137
138 return 0;
139}
int OSThreadCreate(uint64_t rip, uint64_t arg)
void pthreadCreateHelper(void *arg)
void * memset(void *dst, int c, size_t len)
#define SYSCALL_ERRCODE(_result)
#define SYSCALL_VALUE(_result)
◆ pthread_exit()
void pthread_exit |
( |
void * |
value_ptr | ) |
|
Definition at line 142 of file pthread.c.
143{
145
146 thr->result = value_ptr;
147
149}
int OSThreadExit(uint64_t status)
pthread_t pthread_self(void)
◆ pthread_join()
int pthread_join |
( |
pthread_t |
thread, |
|
|
void ** |
value_ptr |
|
) |
| |
Definition at line 152 of file pthread.c.
153{
157 return status;
158 }
159
160 *value_ptr = (void *)thr->result;
161
165
166
168
169 return 0;
170}
int OSThreadWait(uint64_t tid)
#define TAILQ_REMOVE(head, elm, field)
◆ pthread_mutex_destroy()
Definition at line 230 of file pthread.c.
231{
233
236 }
else if (mtx->
lock == 1) {
238 } else {
241 return 0;
242 }
243}
◆ pthread_mutex_init()
Definition at line 215 of file pthread.c.
216{
218
221 }
222
224 *mutex = mtx;
225
226 return 0;
227}
◆ pthread_mutex_lock()
Definition at line 246 of file pthread.c.
247{
249
250 if (*mutex ==
NULL) {
252 if (status != 0)
253 return status;
254 }
255
256 mtx = *mutex;
257
258
259 while (__sync_lock_test_and_set(&mtx->
lock, 1) == 1) {
261 }
262
263 return 0;
264}
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
◆ pthread_mutex_trylock()
Definition at line 267 of file pthread.c.
268{
270
271 if (*mutex ==
NULL) {
273 if (status != 0)
274 return status;
275 }
276
277 mtx = *mutex;
278
279 if (__sync_lock_test_and_set(&mtx->
lock, 1) == 1) {
281 } else {
282
283 return 0;
284 }
285}
◆ pthread_mutex_unlock()
Definition at line 288 of file pthread.c.
289{
291
292 if (*mutex ==
NULL) {
294 if (status != 0)
295 return status;
296 }
297
298 mtx = *mutex;
299
300 __sync_lock_release(&mtx->
lock);
301
302
303 return 0;
304}
◆ pthread_self()
Definition at line 79 of file pthread.c.
80{
83
88 return thr;
89 }
90 }
92
93 printf(
"pthread_self failed to find current thread!\n");
95}
#define TAILQ_FOREACH(var, head, field)
int printf(const char *fmt,...)
◆ pthread_yield()
void pthread_yield |
( |
void |
| ) |
|
◆ pthreadCreateHelper()
void pthreadCreateHelper |
( |
void * |
arg | ) |
|
Definition at line 98 of file pthread.c.
99{
101
102 thr->result = (thr->entry)(thr->arg);
103
105}
◆ TAILQ_HEAD()
typedef TAILQ_HEAD |
( |
|
pthreadList, |
|
|
pthread |
|
|
) |
| |