|
mUPnP for C
|
#include <string.h>#include <signal.h>#include <mupnp/util/log.h>#include <mupnp/util/thread.h>#include <mupnp/util/time.h>Functions | |
| static void | sig_handler (int sign) |
| static void | mupnp_thread_createkey (void) |
| mUpnpThread * | mupnp_thread_self (void) |
| Get the mUpnpThread object for the currently executing thread. | |
| static void * | posix_thread_proc (void *param) |
| mUpnpThread * | mupnp_thread_new (void) |
| Create a new thread instance. | |
| bool | mupnp_thread_delete (mUpnpThread *thread) |
| Stop and destroy a thread, freeing all resources. | |
| bool | mupnp_thread_start (mUpnpThread *thread) |
| Start a thread's execution. | |
| bool | mupnp_thread_stop (mUpnpThread *thread) |
| Request a thread to stop execution. | |
| bool | mupnp_thread_stop_with_cond (mUpnpThread *thread, mUpnpCond *cond) |
| bool | mupnp_thread_restart (mUpnpThread *thread) |
| bool | mupnp_thread_isrunnable (mUpnpThread *thread) |
| void | mupnp_thread_setaction (mUpnpThread *thread, MUPNP_THREAD_FUNC func) |
| void | mupnp_thread_setuserdata (mUpnpThread *thread, void *value) |
| void * | mupnp_thread_getuserdata (mUpnpThread *thread) |
Variables | |
| static pthread_key_t | mupnpThreadSelfRef |
| static pthread_once_t | mupnpThreadMykeycreated = PTHREAD_ONCE_INIT |
|
static |
| bool mupnp_thread_delete | ( | mUpnpThread * | thread | ) |
Stop and destroy a thread, freeing all resources.
Stops the thread if it is running and releases all associated resources. This function blocks until the thread has fully terminated.
The thread's action function should periodically check mupnp_thread_isrunnable() and exit when it returns false to ensure graceful shutdown.
| thread | The thread to destroy. May be NULL (no-op if NULL). |
| true | Successfully stopped and destroyed the thread |
| false | Failed to destroy (e.g., thread is NULL) |
| void * mupnp_thread_getuserdata | ( | mUpnpThread * | thread | ) |
Get the user data pointer
| thread | Thread from which to get the pointer |
| bool mupnp_thread_isrunnable | ( | mUpnpThread * | thread | ) |
Check if a thread has been started
| thread | Thread to check |
| mUpnpThread * mupnp_thread_new | ( | void | ) |
Create a new thread instance.
Allocates and initializes a platform-independent thread object. The thread is initially in a stopped state (not running).
Before starting the thread, you must:
Platform support:
| bool mupnp_thread_restart | ( | mUpnpThread * | thread | ) |
Restart a thread. Essentially calls mupnp_thread_stop() and mupnp_thread_start()
| thread | Thread to restart |
| mUpnpThread * mupnp_thread_self | ( | void | ) |
Get the mUpnpThread object for the currently executing thread.
Returns a reference to the thread structure for the calling thread. This is useful when a thread needs to access its own thread data or check if it should continue running.
| void mupnp_thread_setaction | ( | mUpnpThread * | thread, |
| MUPNP_THREAD_FUNC | actionFunc ) |
Set the thread's worker function.
| thread | Thread struct |
| actionFunc | Function pointer to set as the worker function |
| void mupnp_thread_setuserdata | ( | mUpnpThread * | thread, |
| void * | data ) |
Set the user data pointer
| thread | Thread struct |
| data | Pointer to user data |
| bool mupnp_thread_start | ( | mUpnpThread * | thread | ) |
Start a thread's execution.
Starts the thread, causing its action function to begin execution in a new thread of control. The thread must have been created with mupnp_thread_new() and must have an action function set with mupnp_thread_setaction().
After starting, the action function runs concurrently with the calling thread until the thread is stopped or the action function returns.
| thread | The thread to start. Must not be NULL and must have an action function set. |
| true | Successfully started the thread |
| false | Failed to start due to:
|
| bool mupnp_thread_stop | ( | mUpnpThread * | thread | ) |
Request a thread to stop execution.
Signals the thread to stop by setting its runnable flag to false. This function does NOT forcibly terminate the thread; the thread's action function must cooperatively check mupnp_thread_isrunnable() and exit when it returns false.
This function returns immediately without waiting for the thread to terminate. Use mupnp_thread_delete() if you need to wait for termination.
| thread | The thread to stop. Must not be NULL. |
| true | Successfully signaled the thread to stop |
| false | Failed to signal (e.g., thread is NULL) |
| bool mupnp_thread_stop_with_cond | ( | mUpnpThread * | thread, |
| mUpnpCond * | cond ) |
Stop the running thread and signal the given CGCond.
|
static |
|
static |
|
static |
|
static |