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

Function worker

tests/modules/blockedclient.c:22–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22void *worker(void *arg) {
23 // Retrieve blocked client
24 RedisModuleBlockedClient *bc = (RedisModuleBlockedClient *)arg;
25
26 // Get Redis module context
27 RedisModuleCtx *ctx = RedisModule_GetThreadSafeContext(bc);
28
29 // Acquire GIL
30 RedisModule_ThreadSafeContextLock(ctx);
31
32 // Create another thread which will try to acquire the GIL
33 pthread_t tid;
34 int res = pthread_create(&tid, NULL, sub_worker, ctx);
35 assert(res == 0);
36
37 // Wait for thread
38 pthread_join(tid, NULL);
39
40 // Release GIL
41 RedisModule_ThreadSafeContextUnlock(ctx);
42
43 // Reply to client
44 RedisModule_ReplyWithSimpleString(ctx, "OK");
45
46 // Unblock client
47 RedisModule_UnblockClient(bc, NULL);
48
49 // Free the Redis module context
50 RedisModule_FreeThreadSafeContext(ctx);
51
52 return NULL;
53}
54
55int acquire_gil(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
56{

Callers 1

fastlock_lockFunction · 0.85

Calls 1

pthread_createFunction · 0.50

Tested by

no test coverage detected