mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add endless-loop monitor
This commit is contained in:
42
skynet-src/skynet_monitor.c
Normal file
42
skynet-src/skynet_monitor.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "skynet_monitor.h"
|
||||
#include "skynet.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 = malloc(sizeof(*ret));
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
skynet_monitor_delete(struct skynet_monitor *sm) {
|
||||
free(sm);
|
||||
}
|
||||
|
||||
void
|
||||
skynet_monitor_trigger(struct skynet_monitor *sm, uint32_t source, uint32_t destination) {
|
||||
sm->source = source;
|
||||
sm->destination = destination;
|
||||
__sync_fetch_and_add(&sm->version , 1);
|
||||
}
|
||||
|
||||
void
|
||||
skynet_monitor_check(struct skynet_monitor *sm) {
|
||||
if (sm->version == sm->check_version) {
|
||||
if (sm->destination) {
|
||||
skynet_error(NULL, "A message from [ :%08x ] to [ :%08x ] maybe in an endless loop", sm->source , sm->destination);
|
||||
}
|
||||
} else {
|
||||
sm->check_version = sm->version;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user