+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 1 | /* Simple Plugin API */ |
| 2 | /* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans */ |
| 3 | /* SPDX-License-Identifier: MIT */ |
| 4 | |
| 5 | #ifndef SPA_THREAD_H |
| 6 | #define SPA_THREAD_H |
| 7 | |
| 8 | #include <string.h> |
| 9 | #include <errno.h> |
| 10 | |
| 11 | #include <spa/utils/defs.h> |
| 12 | #include <spa/utils/hook.h> |
| 13 | #include <spa/utils/dict.h> |
| 14 | |
| 15 | #ifdef __cplusplus |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
| 19 | #ifndef SPA_API_THREAD |
| 20 | #ifdef SPA_API_IMPL |
| 21 | #define SPA_API_THREAD SPA_API_IMPL |
| 22 | #else |
| 23 | #define SPA_API_THREAD static inline |
| 24 | #endif |
| 25 | #endif |
| 26 | |
| 27 | /** \defgroup spa_thread Thread |
| 28 | * Threading utility interfaces |
| 29 | */ |
| 30 | |
| 31 | /** |
| 32 | * \addtogroup spa_thread |
| 33 | * \{ |
| 34 | */ |
| 35 | |
| 36 | /** a thread object. |
| 37 | * This can be cast to a platform native thread, like pthread on posix systems |
| 38 | */ |
| 39 | #define SPA_TYPE_INFO_Thread SPA_TYPE_INFO_POINTER_BASE "Thread" |
| 40 | struct spa_thread; |
| 41 | |
| 42 | #define SPA_TYPE_INTERFACE_ThreadUtils SPA_TYPE_INFO_INTERFACE_BASE "ThreadUtils" |
| 43 | #define SPA_VERSION_THREAD_UTILS 0 |
| 44 | struct spa_thread_utils { struct spa_interface iface; }; |
| 45 | |
| 46 | /** thread utils */ |
| 47 | struct spa_thread_utils_methods { |
| 48 | #define SPA_VERSION_THREAD_UTILS_METHODS 0 |
| 49 | uint32_t version; |
| 50 | |
| 51 | /** create a new thread that runs \a start with \a arg */ |
| 52 | struct spa_thread * (*create) (void *object, const struct spa_dict *props, |
| 53 | void *(*start)(void*), void *arg); |
| 54 | /** stop and join a thread */ |
| 55 | int (*join)(void *object, struct spa_thread *thread, void **retval); |
| 56 | |
| 57 | /** get realtime priority range for threads created with \a props */ |
| 58 | int (*get_rt_range) (void *object, const struct spa_dict *props, int *min, int *max); |
| 59 | /** acquire realtime priority, a priority of -1 refers to the priority |
| 60 | * configured in the realtime module |
| 61 | */ |
| 62 | int (*acquire_rt) (void *object, struct spa_thread *thread, int priority); |
| 63 | /** drop realtime priority */ |
| 64 | int (*drop_rt) (void *object, struct spa_thread *thread); |
| 65 | }; |
| 66 | |
| 67 | /** \copydoc spa_thread_utils_methods.create |
| 68 | * \sa spa_thread_utils_methods.create */ |
| 69 | SPA_API_THREAD struct spa_thread *spa_thread_utils_create(struct spa_thread_utils *o, |
| 70 | const struct spa_dict *props, void *(*start_routine)(void*), void *arg) |
| 71 | { |
| 72 | return spa_api_method_r(struct spa_thread *, NULL, |
| 73 | spa_thread_utils, &o->iface, create, 0, |
| 74 | props, start_routine, arg); |
| 75 | } |
| 76 | |
| 77 | /** \copydoc spa_thread_utils_methods.join |
| 78 | * \sa spa_thread_utils_methods.join */ |
| 79 | SPA_API_THREAD int spa_thread_utils_join(struct spa_thread_utils *o, |
| 80 | struct spa_thread *thread, void **retval) |
| 81 | { |
| 82 | return spa_api_method_r(int, -ENOTSUP, |
| 83 | spa_thread_utils, &o->iface, join, 0, |
| 84 | thread, retval); |
| 85 | } |
| 86 | |
| 87 | /** \copydoc spa_thread_utils_methods.get_rt_range |
| 88 | * \sa spa_thread_utils_methods.get_rt_range */ |
| 89 | SPA_API_THREAD int spa_thread_utils_get_rt_range(struct spa_thread_utils *o, |
| 90 | const struct spa_dict *props, int *min, int *max) |
| 91 | { |
| 92 | return spa_api_method_r(int, -ENOTSUP, |
| 93 | spa_thread_utils, &o->iface, get_rt_range, 0, |
| 94 | props, min, max); |
| 95 | } |
| 96 | |
| 97 | /** \copydoc spa_thread_utils_methods.acquire_rt |
| 98 | * \sa spa_thread_utils_methods.acquire_rt */ |
| 99 | SPA_API_THREAD int spa_thread_utils_acquire_rt(struct spa_thread_utils *o, |
| 100 | struct spa_thread *thread, int priority) |
| 101 | { |
| 102 | return spa_api_method_r(int, -ENOTSUP, |
| 103 | spa_thread_utils, &o->iface, acquire_rt, 0, |
| 104 | thread, priority); |
| 105 | } |
| 106 | |
| 107 | /** \copydoc spa_thread_utils_methods.drop_rt |
| 108 | * \sa spa_thread_utils_methods.drop_rt */ |
| 109 | SPA_API_THREAD int spa_thread_utils_drop_rt(struct spa_thread_utils *o, |
| 110 | struct spa_thread *thread) |
| 111 | { |
| 112 | return spa_api_method_r(int, -ENOTSUP, |
| 113 | spa_thread_utils, &o->iface, drop_rt, 0, thread); |
| 114 | } |
| 115 | |
| 116 | #define SPA_KEY_THREAD_NAME "thread.name" /* the thread name */ |
| 117 | #define SPA_KEY_THREAD_STACK_SIZE "thread.stack-size" /* the stack size of the thread */ |
| 118 | #define SPA_KEY_THREAD_AFFINITY "thread.affinity" /* array of CPUs for this thread */ |
| 119 | #define SPA_KEY_THREAD_CREATOR "thread.creator" /* platform specific thread creator function */ |
| 120 | #define SPA_KEY_THREAD_RESET_ON_FORK "thread.reset-on-fork" /* reset priority and policy for real-time threads |
| 121 | on fork. Default true */ |
| 122 | |
| 123 | /** |
| 124 | * \} |
| 125 | */ |
| 126 | |
| 127 | #ifdef __cplusplus |
| 128 | } /* extern "C" */ |
| 129 | #endif |
| 130 | |
| 131 | #endif /* SPA_THREAD_H */ |