summaryrefslogtreecommitdiff
path: root/libptimc/libptimc.h
blob: c6314dda5efb3abae5012dd365da68979896a668 (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
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <ucontext.h>
#include "libimc.h"

enum thread_state {
    THREAD_STATE_FETUS,
    THREAD_STATE_ALIVE,
    THREAD_STATE_DEAD,
};

typedef struct imcthread {
    void *(*fn)(void *);
    void *arg;
    enum thread_state state;
    int id;
    struct imcthread *waiting_on;
    void *retval;

    ucontext_t ctx;
} *imcthread_t;

typedef int imcthread_attr_t;

int imcthread_create(imcthread_t *thread,
                     // only support NULL attr for now
                     imcthread_attr_t *attr,
                     void *(*start_routine)(void *),
                     void *arg);
int imcthread_yield(void);
int imcthread_join(imcthread_t thread, void **retval);

int imcthread_yieldh(hash_t hash);
int imcthread_joinh(imcthread_t thread, void **retval, hash_t hash);

void check_main(void);

extern void imc_check_main(void);

#ifdef __cplusplus
}
#endif
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback