From 5fda7bdc1f8b671702b284f56b01b843ba4f10f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Mon, 14 Oct 2013 16:02:21 +0800 Subject: [PATCH] term socket thread , fix issue #47 --- skynet-src/skynet_start.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/skynet-src/skynet_start.c b/skynet-src/skynet_start.c index 371290bf..f590fd3b 100644 --- a/skynet-src/skynet_start.c +++ b/skynet-src/skynet_start.c @@ -55,30 +55,43 @@ _socket(void *p) { int r = skynet_socket_poll(); if (r==0) break; - if (r<0) + if (r<0) { + CHECK_ABORT continue; + } wakeup(m,0); } return NULL; } +static void +free_monitor(struct monitor *m) { + int i; + int n = m->count; + for (i=0;im[i]); + } + pthread_mutex_destroy(&m->mutex); + pthread_cond_destroy(&m->cond); + free(m->m); + free(m); +} + static void * _monitor(void *p) { struct monitor * m = p; int i; int n = m->count; for (;;) { + CHECK_ABORT for (i=0;im[i]); } - CHECK_ABORT - sleep(5); + for (i=0;i<5;i++) { + CHECK_ABORT + sleep(1); + } } - for (i=0;im[i]); - } - free(m->m); - free(m); return NULL; } @@ -92,6 +105,10 @@ _timer(void *p) { wakeup(m,m->count-1); usleep(2500); } + // wakeup socket thread + skynet_socket_exit(); + // wakeup all worker thread + pthread_cond_broadcast(&m->cond); return NULL; } @@ -154,11 +171,11 @@ _start(int thread) { create_thread(&pid[i+3], _worker, &wp[i]); } - for (i=1;imutex); - pthread_cond_destroy(&m->cond); + + free_monitor(m); } static int