diff options
Diffstat (limited to 'examples/redis-unstable/src/threads_mngr.h')
| -rw-r--r-- | examples/redis-unstable/src/threads_mngr.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/redis-unstable/src/threads_mngr.h b/examples/redis-unstable/src/threads_mngr.h new file mode 100644 index 0000000..9c585c0 --- /dev/null +++ b/examples/redis-unstable/src/threads_mngr.h | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2021-Present, Redis Ltd. | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Licensed under your choice of (a) the Redis Source Available License 2.0 | ||
| 6 | * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the | ||
| 7 | * GNU Affero General Public License v3 (AGPLv3). | ||
| 8 | */ | ||
| 9 | |||
| 10 | #pragma once | ||
| 11 | |||
| 12 | #include "fmacros.h" | ||
| 13 | |||
| 14 | #include <sys/types.h> | ||
| 15 | #include <unistd.h> | ||
| 16 | |||
| 17 | /** This is an API to invoke callback on a list of threads using a user defined signal handler. | ||
| 18 | * NOTE: This is API is only supported only in linux systems. | ||
| 19 | * Calling the functions below on any other system does nothing. | ||
| 20 | */ | ||
| 21 | |||
| 22 | #define THREADS_SIGNAL SIGUSR2 | ||
| 23 | |||
| 24 | /* Callback signature */ | ||
| 25 | typedef void(*run_on_thread_cb)(void); | ||
| 26 | |||
| 27 | /* Register the process to THREADS_SIGNAL */ | ||
| 28 | void ThreadsManager_init(void); | ||
| 29 | |||
| 30 | /** @brief Invoke callback by each thread in tids. | ||
| 31 | * | ||
| 32 | * @param tids An array of threads that need to invoke callback. | ||
| 33 | * @param tids_len The number of threads in @param tids. | ||
| 34 | * @param callback A callback to be invoked by each thread in @param tids. | ||
| 35 | * | ||
| 36 | * NOTES: | ||
| 37 | * It is assumed that all the threads don't block or ignore THREADS_SIGNAL. | ||
| 38 | * | ||
| 39 | * It is safe to include the calling thread in @param tids. However, be aware that subsequent tids will | ||
| 40 | * not be signaled until the calling thread returns from the callback invocation. | ||
| 41 | * Hence, it is recommended to place the calling thread last in @param tids. | ||
| 42 | * | ||
| 43 | * The function returns only when @param tids_len threads have returned from @param callback, or when we reached timeout. | ||
| 44 | * | ||
| 45 | * @return 1 if successful, 0 If ThreadsManager_runOnThreads is already in the middle of execution. | ||
| 46 | * | ||
| 47 | **/ | ||
| 48 | |||
| 49 | int ThreadsManager_runOnThreads(pid_t *tids, size_t tids_len, run_on_thread_cb callback); | ||
