aboutsummaryrefslogtreecommitdiff
path: root/include/bh/internal/thread.h
blob: 8ef9487e91a50bd2692428ecc376fe108e9714be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef BH_INTERNAL_THREAD_H
#define BH_INTERNAL_THREAD_H

#include <bh/thread.h>
#include "queue.h"

#define BH_THREAD_DONE      0x0100

#define BH_MAX_TLS          32

#if defined(BH_USE_PTHREAD)
#include "thread_posix.h"
#elif defined(BH_USE_WINTHREAD)
#include "thread_win.h"
#else
#include "thread_null.h"
#endif

struct bh_task_s
{
    void (*func)(void *);
    void *data;
    int flags;
};

struct bh_thread_pool_s
{
    bh_thread_t *threads;
    bh_queue_t tasks;
    bh_mutex_t lock;
    bh_cond_t new_task;
    bh_cond_t done_task;
    size_t size;
    size_t active;
    int shutdown;
};

typedef struct bh_tls_info_s
{
    size_t counter;
    bh_spinlock_t lock;
    bh_generic_cb_t cleanup[BH_MAX_TLS];
} bh_tls_info_t;

typedef struct bh_tls_s
{
    void *data[BH_MAX_TLS];
} bh_tls_t;

void bh_task_init(bh_task_t *task,
                  void (*func)(void *),
                  void *data,
                  int flags);

void bh_task_destroy(bh_task_t *task);

void bh_thread_pool_worker(void *arg);

void bh_spinlock_init(bh_spinlock_t *lock);

void bh_spinlock_destroy(bh_spinlock_t *lock);

bh_tls_info_t *bh_tls_info(void);

bh_tls_t *bh_tls_fetch(void);

void bh_tls_cleanup(void);

#endif /* BH_INTERNAL_THREAD_H */