Removed hasModuleGIL boolean and added fix from PR #292
Former-commit-id: 68d213f4c9c1c3161929a5e20ca4f2b27665c8fd
This commit is contained in:
parent
932fd2e79a
commit
f4dbaab531
@ -329,6 +329,8 @@ static int s_cAcquisitionsModule = 0;
|
|||||||
static std::mutex s_mutex;
|
static std::mutex s_mutex;
|
||||||
static std::condition_variable s_cv;
|
static std::condition_variable s_cv;
|
||||||
static std::recursive_mutex s_mutexModule;
|
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);
|
typedef void (*RedisModuleForkDoneHandler) (int exitcode, int bysignal, void *user_data);
|
||||||
|
|
||||||
@ -4772,6 +4774,10 @@ int moduleClientIsBlockedOnKeys(client *c) {
|
|||||||
* RedisModule_BlockClientOnKeys() is accessible from the timeout
|
* RedisModule_BlockClientOnKeys() is accessible from the timeout
|
||||||
* callback via RM_GetBlockedClientPrivateData). */
|
* callback via RM_GetBlockedClientPrivateData). */
|
||||||
int RM_UnblockClient(RedisModuleBlockedClient *bc, void *privdata) {
|
int RM_UnblockClient(RedisModuleBlockedClient *bc, void *privdata) {
|
||||||
|
if (serverTL == nullptr) {
|
||||||
|
serverTL = &vars;
|
||||||
|
g_fModuleThread = true;
|
||||||
|
}
|
||||||
if (bc->blocked_on_keys) {
|
if (bc->blocked_on_keys) {
|
||||||
/* In theory the user should always pass the timeout handler as an
|
/* In theory the user should always pass the timeout handler as an
|
||||||
* argument, but better to be safe than sorry. */
|
* argument, but better to be safe than sorry. */
|
||||||
@ -5045,15 +5051,14 @@ void RM_FreeThreadSafeContext(RedisModuleCtx *ctx) {
|
|||||||
zfree(ctx);
|
zfree(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static redisServerThreadVars vars;
|
|
||||||
thread_local bool g_fModuleThread = false;
|
|
||||||
/* Acquire the server lock before executing a thread safe API call.
|
/* Acquire the server lock before executing a thread safe API call.
|
||||||
* This is not needed for `RedisModule_Reply*` calls when there is
|
* This is not needed for `RedisModule_Reply*` calls when there is
|
||||||
* a blocked client connected to the thread safe context. */
|
* a blocked client connected to the thread safe context. */
|
||||||
void RM_ThreadSafeContextLock(RedisModuleCtx *ctx) {
|
void RM_ThreadSafeContextLock(RedisModuleCtx *ctx) {
|
||||||
UNUSED(ctx);
|
UNUSED(ctx);
|
||||||
if (serverTL == nullptr) {
|
if (serverTL == nullptr) {
|
||||||
serverTL = &vars; // arbitrary module threads get the main thread context
|
serverTL = &vars;
|
||||||
g_fModuleThread = true;
|
g_fModuleThread = true;
|
||||||
}
|
}
|
||||||
moduleAcquireGIL(FALSE /*fServerThread*/, true /*fExclusive*/);
|
moduleAcquireGIL(FALSE /*fServerThread*/, true /*fExclusive*/);
|
||||||
@ -5102,7 +5107,6 @@ void moduleAcquireGIL(int fServerThread, int fExclusive) {
|
|||||||
if (fServerThread)
|
if (fServerThread)
|
||||||
{
|
{
|
||||||
++s_cAcquisitionsServer;
|
++s_cAcquisitionsServer;
|
||||||
serverTL->hasModuleGIL = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -5138,7 +5142,6 @@ int moduleTryAcquireGIL(bool fServerThread, int fExclusive) {
|
|||||||
if (fServerThread)
|
if (fServerThread)
|
||||||
{
|
{
|
||||||
++s_cAcquisitionsServer;
|
++s_cAcquisitionsServer;
|
||||||
serverTL->hasModuleGIL = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -5163,7 +5166,6 @@ void moduleReleaseGIL(int fServerThread, int fExclusive) {
|
|||||||
if (fServerThread)
|
if (fServerThread)
|
||||||
{
|
{
|
||||||
--s_cAcquisitionsServer;
|
--s_cAcquisitionsServer;
|
||||||
serverTL->hasModuleGIL = false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -5672,9 +5672,8 @@ void *workerThreadMain(void *parg)
|
|||||||
catch (ShutdownException)
|
catch (ShutdownException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
moduleReleaseGIL(true);
|
||||||
serverAssert(!GlobalLocksAcquired());
|
serverAssert(!GlobalLocksAcquired());
|
||||||
if (serverTL->hasModuleGIL)
|
|
||||||
moduleReleaseGIL(true);
|
|
||||||
aeDeleteEventLoop(el);
|
aeDeleteEventLoop(el);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1390,7 +1390,6 @@ struct redisServerThreadVars {
|
|||||||
long unsigned commandsExecuted = 0;
|
long unsigned commandsExecuted = 0;
|
||||||
bool fRetrySetAofEvent = false;
|
bool fRetrySetAofEvent = false;
|
||||||
std::vector<client*> vecclientsProcess;
|
std::vector<client*> vecclientsProcess;
|
||||||
bool hasModuleGIL = false; /* Does this thread own the moduleGIL lock? */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct redisMaster {
|
struct redisMaster {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user