skynet_monitor.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "skynet.h"
  2. #include "skynet_monitor.h"
  3. #include "skynet_server.h"
  4. #include "skynet.h"
  5. #include "atomic.h"
  6. #include <stdlib.h>
  7. #include <string.h>
  8. struct skynet_monitor {
  9. ATOM_INT version;
  10. int check_version;
  11. uint32_t source;
  12. uint32_t destination;
  13. };
  14. struct skynet_monitor *
  15. skynet_monitor_new() {
  16. struct skynet_monitor * ret = skynet_malloc(sizeof(*ret));
  17. memset(ret, 0, sizeof(*ret));
  18. return ret;
  19. }
  20. void
  21. skynet_monitor_delete(struct skynet_monitor *sm) {
  22. skynet_free(sm);
  23. }
  24. void
  25. skynet_monitor_trigger(struct skynet_monitor *sm, uint32_t source, uint32_t destination) {
  26. sm->source = source;
  27. sm->destination = destination;
  28. ATOM_FINC(&sm->version);
  29. }
  30. void
  31. skynet_monitor_check(struct skynet_monitor *sm) {
  32. if (sm->version == sm->check_version) {
  33. if (sm->destination) {
  34. skynet_context_endless(sm->destination);
  35. skynet_error(NULL, "A message from [ :%08x ] to [ :%08x ] maybe in an endless loop (version = %d)", sm->source , sm->destination, sm->version);
  36. }
  37. } else {
  38. sm->check_version = sm->version;
  39. }
  40. }