From 34599691b373151c77854b20b3c7a621077f6c64 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 7 Oct 2016 16:34:40 +0200 Subject: Modules: fixes to the blocking commands API: examples now works. --- src/module.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/module.c b/src/module.c index 2bf07aee0..a3e755c29 100644 --- a/src/module.c +++ b/src/module.c @@ -3115,7 +3115,7 @@ RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc bc->timeout_callback = timeout_callback; bc->free_privdata = free_privdata; bc->privdata = NULL; - c->bpop.timeout = timeout_ms; + c->bpop.timeout = timeout_ms ? (mstime()+timeout_ms) : 0; blockClient(c,BLOCKED_MODULE); return bc; @@ -3157,7 +3157,11 @@ void moduleHandleBlockedClients(void) { ln = listFirst(moduleUnblockedClients); bc = ln->value; client *c = bc->client; - listDelNode(server.unblocked_clients,ln); + listDelNode(moduleUnblockedClients,ln); + pthread_mutex_unlock(&moduleUnblockedClientsMutex); + + /* Release the lock during the loop, as long as we don't + * touch the shared list. */ if (c != NULL) { RedisModuleCtx ctx = REDISMODULE_CTX_INIT; @@ -3172,6 +3176,10 @@ void moduleHandleBlockedClients(void) { if (bc->privdata && bc->free_privdata) bc->free_privdata(bc->privdata); zfree(bc); + if (c != NULL) unblockClient(bc->client); + + /* Lock again before to iterate the loop. */ + pthread_mutex_lock(&moduleUnblockedClientsMutex); } pthread_mutex_unlock(&moduleUnblockedClientsMutex); } -- cgit v1.2.1