decode.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /******************************************************************
  2. ** Copyright (c) 2009 Wuhan Mozit Technology Co., Ltd .
  3. ** FileName: decode.c
  4. ** Author: BigHead
  5. ** Mail: jsrenyw@sohu.com
  6. ** Date: 2007-5-31 下午07:17:32
  7. ** Editor: YellowBug
  8. ** Date: 2010-5-26 13:34
  9. ** Version: 2010-5-26
  10. ** File Description: 后台框架结构
  11. ******************************************************************/
  12. #include "../include/decode.h"
  13. #include "../core/core.h"
  14. /******************************************************************
  15. * Function Name: RepeatRun
  16. * Arguments:
  17. * Return Value: void
  18. * Editor: YellowBug
  19. * Date: 2010-5-26
  20. * Description: 负责监测用户状态,发送公告等
  21. ******************************************************************/
  22. void RepeatRun(void)
  23. {
  24. // 该线程关闭, 目前不在启动
  25. log("This is in RepeatRun! pid=%d tid=%ld lwpid=%lu\n", getpid(), pthread_self(), syscall(SYS_gettid));
  26. while (1)
  27. {
  28. sleep(10);
  29. }
  30. }
  31. /******************************************************************
  32. * Function Name: AlarmGateway
  33. * Arguments:
  34. * Return Value: void
  35. * Date: 2023-12-5
  36. * Editor: cc
  37. * Description: 扫描数据库,处理网关报警
  38. ******************************************************************/
  39. void AlarmGateway(void)
  40. {
  41. unsigned int nowTime;
  42. //static MYSQL *_db = NULL;
  43. unsigned int lastHeartTime = 0;
  44. log("This is in AlarmGateway decode! pid=%d tid=%ld lwpid=%lu\n", getpid(), pthread_self(), syscall(SYS_gettid));
  45. while (1)
  46. {
  47. usleep(GAME_HEART_BEAT_g);
  48. nowTime = timeGloble_g;
  49. //每隔30s扫描数据库设备状态表
  50. if (nowTime-lastHeartTime >30 )
  51. {
  52. CoreAlarmGateway();
  53. lastHeartTime = nowTime;
  54. log("AlarmGateway used:%ds=(%d-%d)-----------------------------------------------------------------------\n", timeGloble_g - nowTime, timeGloble_g, nowTime);
  55. fflush(stdout);
  56. }
  57. }
  58. log("AlarmGateway thread be closed!---------------------------------------------------------------------------------\n");
  59. exit(0);
  60. }
  61. /******************************************************************
  62. * Function Name: AlarmNode
  63. * Arguments:
  64. * Return Value: void
  65. * Date: 2023-12-8
  66. * Editor: cc
  67. * Description: 扫描数据库,处理节点告警
  68. ******************************************************************/
  69. void AlarmNode(void)
  70. {
  71. unsigned int nowTime;
  72. //static MYSQL *_db = NULL;
  73. int ret = 0;
  74. unsigned int lastHeartTime = 0;
  75. log("This is in AlarmNode decode! pid=%d tid=%ld lwpid=%lu\n", getpid(), pthread_self(), syscall(SYS_gettid));
  76. while (1)
  77. {
  78. usleep(GAME_HEART_BEAT_g);
  79. nowTime = timeGloble_g;
  80. //每隔30s扫描数据库设备状态表
  81. if (nowTime-lastHeartTime >30 )
  82. {
  83. CoreAlarmNode();
  84. lastHeartTime = nowTime;
  85. log("AlarmNode used:%ds=(%d-%d)----------------------------------------------------------------------------\n", timeGloble_g - nowTime, timeGloble_g, nowTime);
  86. fflush(stdout);
  87. }
  88. }
  89. log("AlarmNode thread be closed!\n");
  90. exit(0);
  91. }
  92. /******************************************************************
  93. * Function Name: pthTime
  94. * Arguments: void
  95. * Return Value: void
  96. * Date: 2006-11-2
  97. * Description: 时间计数器,每秒一次心跳,每秒自加一次
  98. * 以单独线程方式运行
  99. ******************************************************************/
  100. void pthTime(void)
  101. {
  102. static struct timeval tv;
  103. timeGloble_g = timeBegin_g = time(NULL);
  104. srand(time(NULL) + getpid() + random() + timeGloble_g);
  105. sleep(1);
  106. log("在pthTime 中 初始化随机种子完毕,请勿再次初始化随机\n");
  107. srandom(time(NULL) + getpid() + random() + random());
  108. log("This is in pthTime 心跳计数现场! pid=%d tid=%ld lwpid=%lu\n", getpid(), pthread_self(), syscall(SYS_gettid));
  109. gettimeofday(&tv, NULL);
  110. timeGloble_g = tv.tv_sec;
  111. while (1)
  112. {
  113. //edit by liuqing 20181201 调整精度 从原来的1s调整到0.3s 5hz
  114. usleep(200000);
  115. gettimeofday(&tv, NULL);
  116. timeGloble_g = tv.tv_sec;
  117. }
  118. }