#include "gwlib/gwlib.h"#include "msg.h"Include dependency graph for heartbeat.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Defines | |
| #define | DEFAULT_HEARTBEAT 30 |
| #define | ALL_HEARTBEATS -1 |
Typedefs | |
| typedef long | hb_load_func_t (void) |
| typedef void | hb_send_func_t (Msg *hb) |
Functions | |
| long | heartbeat_start (hb_send_func_t *send_func, double freq, hb_load_func_t *load_func) |
| void | heartbeat_stop (long hb_thread) |
|
|
Definition at line 68 of file heartbeat.h. Referenced by main(). |
|
|
Definition at line 67 of file heartbeat.h. Referenced by heartbeat_start(). |
|
|
Definition at line 72 of file heartbeat.h. |
|
|
Definition at line 78 of file heartbeat.h. |
|
||||||||||||||||
|
Definition at line 126 of file heartbeat.c. References DEFAULT_HEARTBEAT, hb_info::freq, gwlist_append(), gwlist_create, gwthread_create, heartbeat_thread(), heartbeats, info(), hb_info::load_func, hb_info::running, hb_info::send_func, and hb_info::thread. Referenced by main(). 00128 {
00129 struct hb_info *info;
00130
00131 /* can't start with send_funct NULL */
00132 if (send_func == NULL)
00133 return -1;
00134
00135 info = gw_malloc(sizeof(*info));
00136 info->send_func = send_func;
00137 info->freq = (freq <= 0 ? DEFAULT_HEARTBEAT : freq);
00138 info->load_func = load_func;
00139 info->running = 1;
00140 info->thread = gwthread_create(heartbeat_thread, info);
00141 if (info->thread >= 0) {
00142 if (heartbeats == NULL)
00143 heartbeats = gwlist_create();
00144 gwlist_append(heartbeats, info);
00145 return info->thread;
00146 } else {
00147 gw_free(info);
00148 return -1;
00149 }
00150 }
|
Here is the call graph for this function:

|
|
Definition at line 160 of file heartbeat.c. References find_hb(), gw_assert, gwlist_destroy(), gwlist_extract_first(), gwlist_extract_matching(), gwlist_len(), gwthread_join(), gwthread_wakeup(), heartbeats, info(), hb_info::running, hb_info::thread, and warning(). Referenced by main(). 00161 {
00162 List *matching_info;
00163 struct hb_info *info;
00164
00165 /*
00166 * First, check if there are heartbeats to stop.
00167 * If not, do not continue, otherwise this function will crash
00168 */
00169 if (heartbeats == NULL)
00170 return;
00171
00172 if (hb_thread == ALL_HEARTBEATS) {
00173 while (NULL != (info = gwlist_extract_first(heartbeats))) {
00174 gw_assert(info);
00175 info->running = 0;
00176 gwthread_wakeup(info->thread);
00177 gwthread_join(info->thread);
00178 gw_free(info);
00179 }
00180 } else {
00181 matching_info = gwlist_extract_matching(heartbeats, &hb_thread, find_hb);
00182 if (matching_info == NULL) {
00183 warning(0, "Could not stop heartbeat %ld: not found.", hb_thread);
00184 return;
00185 }
00186 gw_assert(gwlist_len(matching_info) == 1);
00187 info = gwlist_extract_first(matching_info);
00188 gwlist_destroy(matching_info, NULL);
00189
00190 info->running = 0;
00191 gwthread_wakeup(hb_thread);
00192 gwthread_join(hb_thread);
00193 gw_free(info);
00194 }
00195 if (gwlist_len(heartbeats) == 0) {
00196 gwlist_destroy(heartbeats, NULL);
00197 heartbeats = NULL;
00198 }
00199 }
|
Here is the call graph for this function:
