Let's not assume how much memory has been allocated
[p5sagit/p5-mst-13.2.git] / fakethr.h
1 typedef int perl_mutex;
2 typedef int perl_key;
3
4 typedef struct perl_thread *perl_os_thread;
5 /* With fake threads, thr is global(ish) so we don't need dTHR */
6 #define dTHR extern int errno
7
8 struct perl_wait_queue {
9     struct perl_thread *        thread;
10     struct perl_wait_queue *    next;
11 };
12 typedef struct perl_wait_queue *perl_cond;
13
14 /* Ask thread.h to include our per-thread extras */
15 #define HAVE_THREAD_INTERN
16 struct thread_intern {
17     perl_os_thread next_run, prev_run;  /* Linked list of runnable threads */
18     perl_cond   wait_queue;             /* Wait queue that we are waiting on */
19     IV          private;                /* Holds data across time slices */
20     I32         savemark;               /* Holds MARK for thread join values */
21 };
22
23 #define init_thread_intern(t)                           \
24     STMT_START {                                        \
25         t->self = (t);                                  \
26         (t)->i.next_run = (t)->i.prev_run = (t);        \
27         (t)->i.wait_queue = 0;                          \
28         (t)->i.private = 0;                             \
29     } STMT_END
30
31 /*
32  * Note that SCHEDULE() is only callable from pp code (which
33  * must be expecting to be restarted). We'll have to do
34  * something a bit different for XS code.
35  */
36
37 #define SCHEDULE() return schedule(), PL_op
38
39 #define MUTEX_LOCK(m)
40 #define MUTEX_UNLOCK(m)
41 #define MUTEX_INIT(m)
42 #define MUTEX_DESTROY(m)
43 #define COND_INIT(c) perl_cond_init(c)
44 #define COND_SIGNAL(c) perl_cond_signal(c)
45 #define COND_BROADCAST(c) perl_cond_broadcast(c)
46 #define COND_WAIT(c, m)         \
47     STMT_START {                \
48         perl_cond_wait(c);      \
49         SCHEDULE();             \
50     } STMT_END
51 #define COND_DESTROY(c)
52
53 #define THREAD_CREATE(t, f)     f((t))
54 #define THREAD_POST_CREATE(t)   NOOP
55
56 #define YIELD   NOOP