Skip to content

Commit

Permalink
Removed hasModuleGIL boolean and added fix from PR #292
Browse files Browse the repository at this point in the history
  • Loading branch information
VivekSainiEQ authored and JohnSully committed Mar 18, 2021
1 parent cd395a7 commit 318fcb6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ static int s_cAcquisitionsModule = 0;
static std::mutex s_mutex;
static std::condition_variable s_cv;
static std::recursive_mutex s_mutexModule;
static redisServerThreadVars vars; /* Server thread local variables to be used by module threads */
thread_local bool g_fModuleThread = false;

typedef void (*RedisModuleForkDoneHandler) (int exitcode, int bysignal, void *user_data);

Expand Down Expand Up @@ -4772,6 +4774,10 @@ int moduleClientIsBlockedOnKeys(client *c) {
* RedisModule_BlockClientOnKeys() is accessible from the timeout
* callback via RM_GetBlockedClientPrivateData). */
int RM_UnblockClient(RedisModuleBlockedClient *bc, void *privdata) {
if (serverTL == nullptr) {
serverTL = &vars;
g_fModuleThread = true;
}
if (bc->blocked_on_keys) {
/* In theory the user should always pass the timeout handler as an
* argument, but better to be safe than sorry. */
Expand Down Expand Up @@ -5045,15 +5051,14 @@ void RM_FreeThreadSafeContext(RedisModuleCtx *ctx) {
zfree(ctx);
}

static redisServerThreadVars vars;
thread_local bool g_fModuleThread = false;

/* Acquire the server lock before executing a thread safe API call.
* This is not needed for `RedisModule_Reply*` calls when there is
* a blocked client connected to the thread safe context. */
void RM_ThreadSafeContextLock(RedisModuleCtx *ctx) {
UNUSED(ctx);
if (serverTL == nullptr) {
serverTL = &vars; // arbitrary module threads get the main thread context
serverTL = &vars;
g_fModuleThread = true;
}
moduleAcquireGIL(FALSE /*fServerThread*/, true /*fExclusive*/);
Expand Down Expand Up @@ -5102,7 +5107,6 @@ void moduleAcquireGIL(int fServerThread, int fExclusive) {
if (fServerThread)
{
++s_cAcquisitionsServer;
serverTL->hasModuleGIL = true;
}
else
{
Expand Down Expand Up @@ -5138,7 +5142,6 @@ int moduleTryAcquireGIL(bool fServerThread, int fExclusive) {
if (fServerThread)
{
++s_cAcquisitionsServer;
serverTL->hasModuleGIL = true;
}
else
{
Expand All @@ -5163,7 +5166,6 @@ void moduleReleaseGIL(int fServerThread, int fExclusive) {
if (fServerThread)
{
--s_cAcquisitionsServer;
serverTL->hasModuleGIL = false;
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5725,9 +5725,8 @@ void *workerThreadMain(void *parg)
catch (ShutdownException)
{
}
moduleReleaseGIL(true);
serverAssert(!GlobalLocksAcquired());
if (serverTL->hasModuleGIL)
moduleReleaseGIL(true);
aeDeleteEventLoop(el);

return NULL;
Expand Down
1 change: 0 additions & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,6 @@ struct redisServerThreadVars {
bool fRetrySetAofEvent = false;
std::vector<client*> vecclientsProcess;
dictAsyncRehashCtl *rehashCtl = nullptr;
bool hasModuleGIL = false; /* Does this thread own the moduleGIL lock? */
};

struct redisMaster {
Expand Down

0 comments on commit 318fcb6

Please sign in to comment.