bugfix: dead lock in drop queue

This commit is contained in:
云风
2012-08-31 23:12:44 +08:00
parent 243dc58c35
commit 4d1781fe39
4 changed files with 10 additions and 6 deletions

View File

@@ -2,7 +2,6 @@ local skynet = require "skynet"
skynet.start(function() skynet.start(function()
print("Server start") print("Server start")
local launcher = skynet.launch("snlua","launcher")
local connection = skynet.launch("connection","256") local connection = skynet.launch("connection","256")
local lualog = skynet.launch("snlua","lualog") local lualog = skynet.launch("snlua","lualog")
local console = skynet.launch("snlua","console") local console = skynet.launch("snlua","console")
@@ -12,7 +11,7 @@ skynet.start(function()
local watchdog = skynet.launch("snlua","watchdog","8888 4 0") local watchdog = skynet.launch("snlua","watchdog","8888 4 0")
local db = skynet.launch("snlua","simpledb") local db = skynet.launch("snlua","simpledb")
local redis = skynet.launch("snlua","redis-mgr") local redis = skynet.launch("snlua","redis-mgr")
-- skynet.launch("snlua","testgroup") skynet.launch("snlua","testgroup")
skynet.exit() skynet.exit()
end) end)

View File

@@ -72,10 +72,10 @@ skynet_handle_retire(uint32_t handle) {
uint32_t hash = handle & (s->slot_size-1); uint32_t hash = handle & (s->slot_size-1);
struct skynet_context * ctx = s->slot[hash]; struct skynet_context * ctx = s->slot[hash];
if (skynet_context_handle(ctx) == handle) { if (skynet_context_handle(ctx) == handle) {
skynet_context_release(ctx); skynet_context_release(ctx);
s->slot[hash] = NULL; s->slot[hash] = NULL;
int i; int i;
int j=0, n=s->name_count; int j=0, n=s->name_count;
for (i=0; i<n; ++i) { for (i=0; i<n; ++i) {

View File

@@ -211,12 +211,12 @@ skynet_mq_release(struct message_queue *q) {
LOCK(q) LOCK(q)
if (q->release) { if (q->release) {
UNLOCK(q)
ret = _drop_queue(q); ret = _drop_queue(q);
} else { } else {
skynet_mq_force_push(q); skynet_mq_force_push(q);
UNLOCK(q)
} }
UNLOCK(q)
return ret; return ret;
} }

View File

@@ -10,6 +10,7 @@
#include <pthread.h> #include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
static void * static void *
_timer(void *p) { _timer(void *p) {
@@ -37,6 +38,7 @@ _start(int thread) {
pthread_create(&pid[0], NULL, _timer, NULL); pthread_create(&pid[0], NULL, _timer, NULL);
int i; int i;
for (i=1;i<thread+1;i++) { for (i=1;i<thread+1;i++) {
pthread_create(&pid[i], NULL, _worker, NULL); pthread_create(&pid[i], NULL, _worker, NULL);
} }
@@ -70,6 +72,7 @@ skynet_start(struct skynet_config * config) {
} }
// harbor must be init first // harbor must be init first
if (skynet_harbor_start(config->master , config->local)) { if (skynet_harbor_start(config->master , config->local)) {
fprintf(stderr, "Init fail : no master");
return; return;
} }
@@ -78,6 +81,8 @@ skynet_start(struct skynet_config * config) {
if (ctx == NULL) { if (ctx == NULL) {
return; return;
} }
ctx = skynet_context_new("snlua", "launcher");
assert(ctx);
ctx = skynet_context_new("snlua", config->start); ctx = skynet_context_new("snlua", config->start);
_start(config->thread); _start(config->thread);