forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskynet_monitor.c
47 lines (40 loc) · 1.02 KB
/
skynet_monitor.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
#include "skynet.h"
#include "skynet_monitor.h"
#include "skynet_server.h"
#include "skynet.h"
#include "atomic.h"
#include <stdlib.h>
#include <string.h>
struct skynet_monitor {
int version;
int check_version;
uint32_t source;
uint32_t destination;
};
struct skynet_monitor *
skynet_monitor_new() {
struct skynet_monitor * ret = skynet_malloc(sizeof(*ret));
memset(ret, 0, sizeof(*ret));
return ret;
}
void
skynet_monitor_delete(struct skynet_monitor *sm) {
skynet_free(sm);
}
void
skynet_monitor_trigger(struct skynet_monitor *sm, uint32_t source, uint32_t destination) {
sm->source = source;
sm->destination = destination;
ATOM_INC(&sm->version);
}
void
skynet_monitor_check(struct skynet_monitor *sm) {
if (sm->version == sm->check_version) {
if (sm->destination) {
skynet_context_endless(sm->destination);
skynet_error(NULL, "A message from [ :%08x ] to [ :%08x ] maybe in an endless loop (version = %d)", sm->source , sm->destination, sm->version);
}
} else {
sm->check_version = sm->version;
}
}