MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / acquire_gil

Function acquire_gil

tests/modules/blockedclient.c:55–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55int 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
88typedef struct {
89 RedisModuleString **argv;

Callers

nothing calls this directly

Calls 1

pthread_createFunction · 0.50

Tested by

no test coverage detected