Home --> Documentations --> PJLIB Reference
Defines |
#define | PJ_THREAD_DESC_SIZE (64) |
#define | PJ_CHECK_STACK() |
#define | pj_thread_get_stack_max_usage(thread) 0 |
#define | pj_thread_get_stack_info(thread, f, l) (*(f)="",*(l)=0) |
Typedefs |
typedef long | pj_thread_desc [(64)] |
Enumerations |
enum | pj_thread_create_flags { PJ_THREAD_SUSPENDED = 1
} |
Functions |
typedef | int (PJ_THREAD_FUNC pj_thread_proc)(void *) |
pj_uint32_t | pj_getpid (void) |
pj_status_t | pj_thread_create (pj_pool_t *pool, const char *thread_name, pj_thread_proc *proc, void *arg, pj_size_t stack_size, unsigned flags, pj_thread_t **thread) |
pj_status_t | pj_thread_register (const char *thread_name, pj_thread_desc desc, pj_thread_t **thread) |
pj_bool_t | pj_thread_is_registered (void) |
int | pj_thread_get_prio (pj_thread_t *thread) |
pj_status_t | pj_thread_set_prio (pj_thread_t *thread, int prio) |
int | pj_thread_get_prio_min (pj_thread_t *thread) |
int | pj_thread_get_prio_max (pj_thread_t *thread) |
void * | pj_thread_get_os_handle (pj_thread_t *thread) |
const char * | pj_thread_get_name (pj_thread_t *thread) |
pj_status_t | pj_thread_resume (pj_thread_t *thread) |
pj_thread_t * | pj_thread_this (void) |
pj_status_t | pj_thread_join (pj_thread_t *thread) |
pj_status_t | pj_thread_destroy (pj_thread_t *thread) |
pj_status_t | pj_thread_sleep (unsigned msec) |
Detailed Description
This module provides multithreading API.
Examples
For examples, please see:
Define Documentation
#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.
#define PJ_THREAD_DESC_SIZE (64) |
#define pj_thread_get_stack_info |
( |
|
thread, |
|
|
|
f, |
|
|
|
l | |
|
) |
| | (*(f)="",*(l)=0) |
#define pj_thread_get_stack_max_usage |
( |
|
thread |
) |
0 |
Typedef Documentation
Thread structure, to thread's state when the thread is created by external or native API.
Enumeration Type Documentation
Thread creation flags:
- PJ_THREAD_SUSPENDED: specify that the thread should be created suspended.
Function Documentation
typedef int |
( |
PJ_THREAD_FUNC |
pj_thread_proc |
) |
|
Type of thread entry function.
Get process ID.
- Returns:
- process ID.
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.
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:
-
| thread | The thread handle. |
- Returns:
- zero on success.
const char* pj_thread_get_name |
( |
pj_thread_t * |
thread |
) |
|
Get thread name.
- Parameters:
-
| thread | The thread handle. |
- Returns:
- Thread name as null terminated string.
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.
Get thread priority value for the thread.
- Parameters:
-
- Returns:
- Thread priority value, or -1 on error.
Get the highest priority value available for this thread.
- Parameters:
-
- Returns:
- Minimum thread priority value, or -1 on error.
Get the lowest priority value available for this thread.
- Parameters:
-
- Returns:
- Minimum thread priority value, or -1 on error.
Check if this thread has been registered to PJLIB.
- Returns:
- Non-zero if it is registered.
Join thread, and block the caller thread until the specified thread exits. If the specified thread has already been dead, or it does not exist, the function will return immediately with successfull status.
- Parameters:
-
| thread | The thread handle. |
- Returns:
- PJ_SUCCESS on success.
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.
Resume a suspended thread.
- Parameters:
-
| thread | The thread handle. |
- Returns:
- zero on success.
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.
- Parameters:
-
| thread | Thread handle. |
| prio | New priority to be set to the thread. |
- Returns:
- PJ_SUCCESS on success or the error code.
Put the current thread to sleep for the specified miliseconds.
- Parameters:
-
- Returns:
- zero if successfull.
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.
|