[176] | 1 | /* |
---|
| 2 | * swift_thread.h |
---|
| 3 | * |
---|
| 4 | * (c) 2009 Ionut Rosoiu <ionut.rosoiu@gmail.com> |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #ifndef SWIFT_THREAD_H_ |
---|
| 9 | #define SWIFT_THREAD_H_ |
---|
| 10 | |
---|
| 11 | #include "swift_common.h" |
---|
| 12 | #include "swift_allocator.h" |
---|
| 13 | #include "swift_declarations.h" |
---|
| 14 | #include "swift_context.h" |
---|
| 15 | #include "swift_deque.h" |
---|
| 16 | #include <pthread.h> |
---|
| 17 | |
---|
| 18 | #define SWIFT_THREAD_RUNNING 0 |
---|
| 19 | #define SWIFT_THREAD_WAITING 1 |
---|
| 20 | |
---|
| 21 | struct swift_thread { |
---|
| 22 | struct swift_context *context; /*< global info (related to the other threads) */ |
---|
| 23 | volatile int state; /*< the state of the thread */ |
---|
| 24 | volatile int stop; /*< true if the thread must stop */ |
---|
| 25 | |
---|
| 26 | int stats; /*< thread statistics */ |
---|
| 27 | |
---|
| 28 | swift_id_t id; /*< the id of the thread */ |
---|
| 29 | swift_deque_t workque; /*< the workqueue */ |
---|
| 30 | |
---|
| 31 | #ifdef SWIFT_USE_CUSTOM_ALLOCATOR |
---|
| 32 | void *heap; /*< base for the thread's heap */ |
---|
| 33 | void *heap_top; /*< the top of the thread's heap */ |
---|
| 34 | void *heap_limit; /*< the limit for the thread's heap */ |
---|
| 35 | swift_allocator_list_t **buckets; /*< the allocator's buckets */ |
---|
| 36 | #endif |
---|
| 37 | |
---|
| 38 | swift_size_t last_sleep_time; /*< used by the backoff algorithm (in ns) */ |
---|
| 39 | swift_size_t round_robin_id; /*< the last target in a round robin steal search */ |
---|
| 40 | swift_size_t frame_no; /*< the number of frames this thread has spawned */ |
---|
| 41 | |
---|
| 42 | pthread_t thread; /*< system-level thread */ |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | typedef void* (*swift_entrypoint_t) (void*); |
---|
| 46 | |
---|
| 47 | void swift_thread_start(swift_thread_t *thread, |
---|
| 48 | swift_entrypoint_t func); |
---|
| 49 | |
---|
| 50 | void swift_thread_wait(swift_thread_t *thread); |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | #endif /* SWIFT_THREAD_H_ */ |
---|