Last active
July 25, 2021 09:48
-
-
Save losophy/6be78f27a5e4d514d57cd577fcf17c46 to your computer and use it in GitHub Desktop.
skynet monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef SKYNET_MONITOR_H | |
#define SKYNET_MONITOR_H | |
#include <stdint.h> | |
struct skynet_monitor; | |
struct skynet_monitor * skynet_monitor_new(); | |
void skynet_monitor_delete(struct skynet_monitor *); | |
void skynet_monitor_trigger(struct skynet_monitor *, uint32_t source, uint32_t destination); | |
void skynet_monitor_check(struct skynet_monitor *); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment