Fix more concurrency problems

This commit is contained in:
lazio579 2018-10-26 08:48:03 +08:00
parent e64418a1d0
commit 51dd2503a5
4 changed files with 14 additions and 7 deletions

View File

@ -755,7 +755,7 @@ cetus_monitor_mainloop(void *data)
#if 0
cetus_monitor_open(monitor, MONITOR_TYPE_CHECK_CONFIG);
#endif
chassis_event_loop(loop);
chassis_event_loop(loop, NULL);
g_message("monitor thread closing %d mysql conns", g_hash_table_size(monitor->backend_conns));
g_hash_table_destroy(monitor->backend_conns);

View File

@ -114,7 +114,7 @@ cetus_exec_new_binary(cetus_cycle_t *cycle, char **argv)
void
cetus_master_process_cycle(cetus_cycle_t *cycle)
{
int try_cnt;
int try_cnt, mutex_set;
unsigned int live;
cetus_pid = getpid();
@ -140,12 +140,19 @@ cetus_master_process_cycle(cetus_cycle_t *cycle)
live = 1;
try_cnt = 0;
mutex_set = 0;
for ( ;; ) {
if (!cetus_terminate) {
if (mutex_set) {
cycle->socketpair_mutex = 0;
}
chassis_event_loop_t *loop = cycle->event_base;
chassis_event_loop(loop);
chassis_event_loop(loop, &(cycle->socketpair_mutex));
cycle->socketpair_mutex = 1;
mutex_set = 1;
}
if (cetus_terminate) {
@ -604,7 +611,7 @@ cetus_worker_process_cycle(cetus_cycle_t *cycle, void *data)
/* call main procedures for worker */
chassis_event_loop_t *loop = cycle->event_base;
chassis_event_loop(loop);
chassis_event_loop(loop, NULL);
g_message("%s: after chassis_event_loop", G_STRLOC);
if (cetus_terminate) {

View File

@ -93,13 +93,13 @@ chassis_event_loop_free(chassis_event_loop_t *event)
}
void *
chassis_event_loop(chassis_event_loop_t *loop)
chassis_event_loop(chassis_event_loop_t *loop, int *mutex)
{
/**
* check once a second if we shall shutdown the proxy
*/
while (!chassis_is_shutdown()) {
while ((mutex != NULL && (*mutex) != 0) || !chassis_is_shutdown()) {
if (cetus_reap || cetus_change_binary || cetus_quit || cetus_noaccept) {
if (cetus_quit) {
g_message("%s: cetus_quit is true", G_STRLOC);

View File

@ -40,6 +40,6 @@ typedef struct event_base chassis_event_loop_t;
CHASSIS_API chassis_event_loop_t *chassis_event_loop_new();
CHASSIS_API void chassis_event_loop_free(chassis_event_loop_t *e);
CHASSIS_API void chassis_event_set_event_base(chassis_event_loop_t *e, struct event_base *event_base);
CHASSIS_API void *chassis_event_loop(chassis_event_loop_t *);
CHASSIS_API void *chassis_event_loop(chassis_event_loop_t *, int *);
#endif