mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
term socket thread , fix issue #47
This commit is contained in:
@@ -55,30 +55,43 @@ _socket(void *p) {
|
|||||||
int r = skynet_socket_poll();
|
int r = skynet_socket_poll();
|
||||||
if (r==0)
|
if (r==0)
|
||||||
break;
|
break;
|
||||||
if (r<0)
|
if (r<0) {
|
||||||
|
CHECK_ABORT
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
wakeup(m,0);
|
wakeup(m,0);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_monitor(struct monitor *m) {
|
||||||
|
int i;
|
||||||
|
int n = m->count;
|
||||||
|
for (i=0;i<n;i++) {
|
||||||
|
skynet_monitor_delete(m->m[i]);
|
||||||
|
}
|
||||||
|
pthread_mutex_destroy(&m->mutex);
|
||||||
|
pthread_cond_destroy(&m->cond);
|
||||||
|
free(m->m);
|
||||||
|
free(m);
|
||||||
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
_monitor(void *p) {
|
_monitor(void *p) {
|
||||||
struct monitor * m = p;
|
struct monitor * m = p;
|
||||||
int i;
|
int i;
|
||||||
int n = m->count;
|
int n = m->count;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
CHECK_ABORT
|
||||||
for (i=0;i<n;i++) {
|
for (i=0;i<n;i++) {
|
||||||
skynet_monitor_check(m->m[i]);
|
skynet_monitor_check(m->m[i]);
|
||||||
}
|
}
|
||||||
CHECK_ABORT
|
for (i=0;i<5;i++) {
|
||||||
sleep(5);
|
CHECK_ABORT
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (i=0;i<n;i++) {
|
|
||||||
skynet_monitor_delete(m->m[i]);
|
|
||||||
}
|
|
||||||
free(m->m);
|
|
||||||
free(m);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -92,6 +105,10 @@ _timer(void *p) {
|
|||||||
wakeup(m,m->count-1);
|
wakeup(m,m->count-1);
|
||||||
usleep(2500);
|
usleep(2500);
|
||||||
}
|
}
|
||||||
|
// wakeup socket thread
|
||||||
|
skynet_socket_exit();
|
||||||
|
// wakeup all worker thread
|
||||||
|
pthread_cond_broadcast(&m->cond);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,11 +171,11 @@ _start(int thread) {
|
|||||||
create_thread(&pid[i+3], _worker, &wp[i]);
|
create_thread(&pid[i+3], _worker, &wp[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=1;i<thread+3;i++) {
|
for (i=0;i<thread+3;i++) {
|
||||||
pthread_join(pid[i], NULL);
|
pthread_join(pid[i], NULL);
|
||||||
}
|
}
|
||||||
pthread_mutex_destroy(&m->mutex);
|
|
||||||
pthread_cond_destroy(&m->cond);
|
free_monitor(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|||||||
Reference in New Issue
Block a user