Quake II RTX doxygen  1.0 dev
threads.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <stdint.h>
6 
7 // storage will be in the corresponding threads.c file:
8 extern uint32_t threads_id;
9 
10 typedef struct { void* x; } pthread_mutex_t;
11 #define threads_mutex_lock(m) ((void*)m)
12 #define threads_mutex_unlock(m) ((void*)m)
13 #define threads_mutex_destroy(m) ((void*)m)
14 #define threads_mutex_init(m, p) ((void*)m)
15 
16 // hack :/
17 #define __sync_fetch_and_add(p, a) ((*(p) += (a)), *(p) - (a))
18 
19 #ifndef aligned_alloc
20 #define aligned_alloc(a, s) _aligned_malloc(s, a)
21 #endif
22 #ifndef aligned_free
23 #define aligned_free(p) _aligned_free(p)
24 #endif
25 
26 #define sysconf(x) 1
27 #ifndef usleep
28 #define usleep(x)
29 #endif
30 #ifndef sched_yield
31 #define sched_yield()
32 #endif
33 
34 typedef struct threads_t
35 {
36  uint32_t num_threads;
37  uint32_t task[1];
38  void *pool;
39 }
40 threads_t;
41 
42 static inline void
43 pthread_pool_task_init(uint32_t *task, void *pool, void* (*f)(void *), void *param)
44 { // single threaded execution in line
45  f(param);
46 }
47 
48 static inline void pthread_pool_wait(void *pool) { }
49 
50 static inline threads_t *threads_init(uint32_t num_threads)
51 {
52  threads_t *t = malloc(sizeof(*t));
53  t->num_threads = 1;
54  t->task[0] = 0;
55  t->pool = 0;
56  threads_id = 0;
57  return t;
58 }
59 
60 static inline void threads_cleanup(threads_t *t)
61 {
62  free(t);
63 }
64 
pthread_pool_wait
static void pthread_pool_wait(void *pool)
Definition: threads.h:48
pthread_mutex_t::x
void * x
Definition: threads.h:10
threads_t
Definition: threads.h:34
threads_t::pool
void * pool
Definition: threads.h:38
threads_t
struct threads_t threads_t
threads_t::num_threads
uint32_t num_threads
Definition: threads.h:36
pthread_mutex_t
Definition: threads.h:10
threads_cleanup
static void threads_cleanup(threads_t *t)
Definition: threads.h:60
pthread_pool_task_init
static void pthread_pool_task_init(uint32_t *task, void *pool, void *(*f)(void *), void *param)
Definition: threads.h:43
threads_id
uint32_t threads_id
Definition: threads.c:4
threads_init
static threads_t * threads_init(uint32_t num_threads)
Definition: threads.h:50
threads_t::task
uint32_t task[1]
Definition: threads.h:37