| 20 | } |
| 21 | |
| 22 | void *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 | |
| 55 | int acquire_gil(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) |
| 56 | { |
no test coverage detected