Files
skynet/skynet-src/skynet_monitor.c
2012-09-28 16:43:04 +08:00

43 lines
902 B
C

#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;
}
}