| 53 | } |
| 54 | |
| 55 | int acquire_gil(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) |
| 56 | { |
| 57 | UNUSED(argv); |
| 58 | UNUSED(argc); |
| 59 | |
| 60 | int flags = RedisModule_GetContextFlags(ctx); |
| 61 | int allFlags = RedisModule_GetContextFlagsAll(); |
| 62 | if ((allFlags & REDISMODULE_CTX_FLAGS_MULTI) && |
| 63 | (flags & REDISMODULE_CTX_FLAGS_MULTI)) { |
| 64 | RedisModule_ReplyWithSimpleString(ctx, "Blocked client is not supported inside multi"); |
| 65 | return REDISMODULE_OK; |
| 66 | } |
| 67 | |
| 68 | if ((allFlags & REDISMODULE_CTX_FLAGS_DENY_BLOCKING) && |
| 69 | (flags & REDISMODULE_CTX_FLAGS_DENY_BLOCKING)) { |
| 70 | RedisModule_ReplyWithSimpleString(ctx, "Blocked client is not allowed"); |
| 71 | return REDISMODULE_OK; |
| 72 | } |
| 73 | |
| 74 | /* This command handler tries to acquire the GIL twice |
| 75 | * once in the worker thread using "RedisModule_ThreadSafeContextLock" |
| 76 | * second in the sub-worker thread |
| 77 | * using "RedisModule_ThreadSafeContextTryLock" |
| 78 | * as the GIL is already locked. */ |
| 79 | RedisModuleBlockedClient *bc = RedisModule_BlockClient(ctx, NULL, NULL, NULL, 0); |
| 80 | |
| 81 | pthread_t tid; |
| 82 | int res = pthread_create(&tid, NULL, worker, bc); |
| 83 | assert(res == 0); |
| 84 | |
| 85 | return REDISMODULE_OK; |
| 86 | } |
| 87 | |
| 88 | typedef struct { |
| 89 | RedisModuleString **argv; |
nothing calls this directly
no test coverage detected