-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactor.h
60 lines (47 loc) · 1.09 KB
/
actor.h
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
#include "kjson/kjson.h"
#include "sched.h"
#include "queue.h"
#ifndef ACTOR_H
#define ACTOR_H
#ifdef __cplusplus
extern "C" {
#endif
#define __shared__
#define __per_thread__
typedef struct ActorStage {
Scheduler __per_thread__ **sched;
} ActorStage;
enum actor_stage_wait {
wait_nop = 0,
wait_node,
wait_thread,
wait_cores,
wait_failed = -1
};
int ActorStage_init(int max_cores, int threads_per_core);
int ActorStage_finish(void);
int ActorStage_wait(enum actor_stage_wait wait, int val);
typedef union JSON Message;
struct Actor;
struct actor_api {
int (*act)(struct Actor *, Message *);
void (*finit)(struct Actor *);
void (*fexit)(struct Actor *);
};
typedef Queue MailBox;
typedef struct Actor {
const struct actor_api *api;
MailBox *mailbox;
JSON self;
} Actor;
Actor *Actor_new(JSON o, const struct actor_api *api);
void Actor_finalize(Actor *a);
void Actor_act(Actor *a);
void Actor_send(Actor *a, JSON message);
#ifndef mfence
#define mfence() asm volatile("" ::: "memory")
#endif
#ifdef __cplusplus
}
#endif
#endif /* end of include guard */