Home --> Documentations --> PJLIB Reference
This module provides multithreading API.
Examples
For examples, please see:
◆ PJ_CHECK_STACK
#define PJ_CHECK_STACK |
( |
| ) |
|
PJ_CHECK_STACK() macro is used to check the sanity of the stack. The OS implementation may check that no stack overflow occurs, and it also may collect statistic about stack usage.
◆ PJ_THREAD_DESC_SIZE
#define PJ_THREAD_DESC_SIZE (64) |
◆ pj_thread_get_stack_info
#define pj_thread_get_stack_info |
( |
|
thread, |
|
|
|
f, |
|
|
|
l |
|
) |
| (*(f)="",*(l)=0) |
◆ pj_thread_get_stack_max_usage
#define pj_thread_get_stack_max_usage |
( |
|
thread | ) |
0 |
◆ pj_thread_desc
typedef long pj_thread_desc[(64)] |
Thread structure, to thread's state when the thread is created by external or native API.
◆ pj_thread_proc
typedef int() pj_thread_proc(void *) |
Type of thread entry function.
◆ pj_thread_create_flags
Thread creation flags:
- PJ_THREAD_SUSPENDED: specify that the thread should be created suspended.
◆ pj_getpid()
Get process ID. - Returns
- process ID.
◆ pj_thread_create()
Create a new thread.
- Parameters
-
pool | The memory pool from which the thread record will be allocated from. |
thread_name | The optional name to be assigned to the thread. |
proc | Thread entry function. |
arg | Argument to be passed to the thread entry function. |
stack_size | The size of the stack for the new thread, or ZERO or PJ_THREAD_DEFAULT_STACK_SIZE to let the library choose the reasonable size for the stack. For some systems, the stack will be allocated from the pool, so the pool must have suitable capacity. |
flags | Flags for thread creation, which is bitmask combination from enum pj_thread_create_flags. |
thread | Pointer to hold the newly created thread. |
- Returns
- PJ_SUCCESS on success, or the error code.
◆ pj_thread_destroy()
Destroy thread and release resources allocated for the thread. However, the memory allocated for the pj_thread_t itself will only be released when the pool used to create the thread is destroyed.
- Parameters
-
- Returns
- zero on success.
◆ pj_thread_get_name()
const char * pj_thread_get_name |
( |
pj_thread_t * |
thread | ) |
|
Get thread name.
- Parameters
-
- Returns
- Thread name as null terminated string.
◆ pj_thread_get_os_handle()
Return native handle from pj_thread_t for manipulation using native OS APIs.
- Parameters
-
thread | PJLIB thread descriptor. |
- Returns
- Native thread handle. For example, when the backend thread uses pthread, this function will return pointer to pthread_t, and on Windows, this function will return HANDLE.
◆ pj_thread_get_prio()
Get thread priority value for the thread.
- Parameters
-
- Returns
- Thread priority value, or -1 on error.
◆ pj_thread_get_prio_max()
Get the highest priority value available for this thread.
- Parameters
-
- Returns
- Minimum thread priority value, or -1 on error.
◆ pj_thread_get_prio_min()
Get the lowest priority value available for this thread.
- Parameters
-
- Returns
- Minimum thread priority value, or -1 on error.
◆ pj_thread_is_registered()
Check if this thread has been registered to PJLIB.
- Returns
- Non-zero if it is registered.
◆ pj_thread_join()
Join thread, and block the caller thread until the specified thread exits. If it is called from within the thread itself, it will return immediately with failure status. If the specified thread has already been dead, or it does not exist, the function will return immediately with successful status.
- Parameters
-
- Returns
- PJ_SUCCESS on success.
◆ pj_thread_register()
Register a thread that was created by external or native API to PJLIB. This function must be called in the context of the thread being registered. When the thread is created by external function or API call, it must be 'registered' to PJLIB using pj_thread_register(), so that it can cooperate with PJLIB's framework. During registration, some data needs to be maintained, and this data must remain available during the thread's lifetime.
- Parameters
-
thread_name | The optional name to be assigned to the thread. |
desc | Thread descriptor, which must be available throughout the lifetime of the thread. |
thread | Pointer to hold the created thread handle. |
- Returns
- PJ_SUCCESS on success, or the error code.
◆ pj_thread_resume()
Resume a suspended thread.
- Parameters
-
- Returns
- zero on success.
◆ pj_thread_set_prio()
Set the thread priority. The priority value must be in the priority value range, which can be retrieved with pj_thread_get_prio_min() and pj_thread_get_prio_max() functions.
For Android, this function will only set the priority of the calling thread (the thread param must be set to NULL or the calling thread handle).
- Parameters
-
thread | Thread handle. |
prio | New priority to be set to the thread. |
- Returns
- PJ_SUCCESS on success or the error code.
◆ pj_thread_sleep()
Put the current thread to sleep for the specified miliseconds.
- Parameters
-
- Returns
- zero if successfull.
◆ pj_thread_this()
Get the current thread.
- Returns
- Thread handle of current thread.
PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.
|