-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuddy.c
82 lines (59 loc) · 2.05 KB
/
buddy.c
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
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "buddy.h"
#include <stdio.h>
void buddy_init(struct thorium_actor *self);
void buddy_destroy(struct thorium_actor *self);
void buddy_receive(struct thorium_actor *self, struct thorium_message *message);
/* this script is required */
struct thorium_script buddy_script = {
.identifier = SCRIPT_BUDDY,
.init = buddy_init,
.destroy = buddy_destroy,
.receive = buddy_receive,
.size = sizeof(struct buddy),
.name = "buddy"
};
void buddy_init(struct thorium_actor *actor)
{
struct buddy *buddy1;
buddy1 = (struct buddy *)thorium_actor_concrete_actor(actor);
buddy1->received = 0;
}
void buddy_destroy(struct thorium_actor *actor)
{
struct buddy *buddy1;
buddy1 = (struct buddy *)thorium_actor_concrete_actor(actor);
buddy1->received = -1;
}
void buddy_receive(struct thorium_actor *actor, struct thorium_message *message)
{
int tag;
int source;
int name;
name = thorium_actor_name(actor);
source = thorium_message_source(message);
tag = thorium_message_action(message);
if (tag == ACTION_BUDDY_BOOT) {
printf("ACTION_BUDDY_BOOT\n");
thorium_actor_print(actor);
thorium_message_init(message, ACTION_BUDDY_BOOT_REPLY, 0, NULL);
thorium_actor_send(actor, source, message);
} else if (tag == ACTION_BUDDY_HELLO) {
printf("ACTION_BUDDY_HELLO\n");
/* pin the actor to the worker for no reason !
*/
/*
thorium_actor_send_to_self_empty(actor, ACTION_PIN_TO_WORKER);
*/
thorium_message_init(message, ACTION_BUDDY_HELLO_REPLY, 0, NULL);
thorium_actor_send(actor, source, message);
} else if (tag == ACTION_ASK_TO_STOP) {
printf("BUDDY_DIE\n");
printf("buddy_receive Actor %i received a message (%i BUDDY_DIE) from actor %i\n",
name, tag, source);
/*
thorium_actor_send_to_self_empty(actor, ACTION_UNPIN_FROM_WORKER);
*/
thorium_message_init(message, ACTION_STOP, 0, NULL);
thorium_actor_send(actor, name, message);
}
}