summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-10-07 16:34:40 +0200
committerantirez <antirez@gmail.com>2016-10-07 16:34:40 +0200
commit34599691b373151c77854b20b3c7a621077f6c64 (patch)
tree156cfe02943d46adf22cd5e52c4235f426e60eba
parentf156038db84e25304862fcac43f1222a4382abef (diff)
downloadredis-34599691b373151c77854b20b3c7a621077f6c64.tar.gz
Modules: fixes to the blocking commands API: examples now works.
-rw-r--r--src/module.c12
1 files 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);
}