OpenJPEG 2.3.0

Data Structures | Typedefs | Enumerations | Functions
thread.c File Reference
`#include <assert.h>`
`#include "opj_includes.h"`

## Data Structures
struct | opj_tls_key_val_t
struct | opj_tls_t
struct | opj_worker_thread_job_t
struct | opj_worker_thread_t
struct | opj_job_list_t
struct | opj_worker_thread_list_t
struct | opj_thread_pool_t

## Typedefs
typedef struct opj_job_list_t | opj_job_list_t
typedef struct opj_worker_thread_list_t | opj_worker_thread_list_t

## Enumerations
enum | opj_worker_thread_state { OPJWTS_OK, OPJWTS_STOP, OPJWTS_ERROR }

## Functions
OPJ_BOOL OPJ_CALLCONV | opj_has_thread_support (void)
| Returns if the library is built with thread support. More...
int OPJ_CALLCONV | opj_get_num_cpus (void)
| Return the number of virtual CPUs. More...
opj_mutex_t * | opj_mutex_create (void)
| Creates a mutex. More...
void | opj_mutex_lock (opj_mutex_t *mutex)
| Lock/acquire the mutex. More...
void | opj_mutex_unlock (opj_mutex_t *mutex)
| Unlock/release the mutex. More...
void | opj_mutex_destroy (opj_mutex_t *mutex)
| Destroy a mutex. More...
opj_cond_t * | opj_cond_create (void)
| Creates a condition. More...
void | opj_cond_wait (opj_cond_t *cond, opj_mutex_t *mutex)
| Wait for the condition to be signaled. More...
void | opj_cond_signal (opj_cond_t *cond)
| Signal waiting threads on a condition. More...
void | opj_cond_destroy (opj_cond_t *cond)
| Destroy a condition. More...
opj_thread_t * | opj_thread_create (opj_thread_fn thread_fn, void *user_data)
| Creates a new thread. More...
void | opj_thread_join (opj_thread_t *thread)
| Wait for a thread to be finished and release associated resources to the thread handle. More...
static opj_tls_t * | opj_tls_new (void)
static void | opj_tls_destroy (opj_tls_t *tls)
void * | opj_tls_get (opj_tls_t *tls, int key)
| Get a thread local value corresponding to the provided key. More...
OPJ_BOOL | opj_tls_set (opj_tls_t *tls, int key, void *value, opj_tls_free_func opj_free_func)
| Set a thread local value corresponding to the provided key. More...
static OPJ_BOOL | opj_thread_pool_setup (opj_thread_pool_t *tp, int num_threads)
static opj_worker_thread_job_t * | opj_thread_pool_get_next_job (opj_thread_pool_t *tp, opj_worker_thread_t *worker_thread, OPJ_BOOL signal_job_finished)
opj_thread_pool_t * | opj_thread_pool_create (int num_threads)
| Create a new thread pool. More...
static void | opj_worker_thread_function (void *user_data)
OPJ_BOOL | opj_thread_pool_submit_job (opj_thread_pool_t *tp, opj_job_fn job_fn, void *user_data)
| Submit a new job to be run by one of the thread in the thread pool. More...
void | opj_thread_pool_wait_completion (opj_thread_pool_t *tp, int max_remaining_jobs)
| Wait that no more than max_remaining_jobs jobs are remaining in the queue of the thread pool. More...
int | opj_thread_pool_get_thread_count (opj_thread_pool_t *tp)
| Return the number of threads associated with the thread pool. More...
void | opj_thread_pool_destroy (opj_thread_pool_t *tp)
| Destroy a thread pool. More...

## Typedef Documentation

## ◆ opj_job_list_t

typedef struct opj_job_list_t opj_job_list_t

## ◆ opj_worker_thread_list_t

typedef struct opj_worker_thread_list_t opj_worker_thread_list_t

## Enumeration Type Documentation

## ◆ opj_worker_thread_state

enum opj_worker_thread_state

Enumerator
OPJWTS_OK |
OPJWTS_STOP |
OPJWTS_ERROR |

## Function Documentation

## ◆ opj_get_num_cpus()

int OPJ_CALLCONV opj_get_num_cpus | ( | void |  | ) |

Return the number of virtual CPUs.

Referenced by opj_j2k_get_default_thread_count().

## ◆ opj_has_thread_support()

OPJ_BOOL OPJ_CALLCONV opj_has_thread_support | ( | void |  | ) |

Returns if the library is built with thread support.

OPJ_TRUE if mutex, condition, thread, thread pool are available.

References OPJ_FALSE.

Referenced by opj_j2k_get_default_thread_count(), and opj_j2k_set_threads().

## ◆ opj_thread_pool_get_next_job()

static opj_worker_thread_job_t * opj_thread_pool_get_next_job | ( | opj_thread_pool_t * | tp,
|  | opj_worker_thread_t * | worker_thread,
|  | OPJ_BOOL | signal_job_finished
| ) |  |
| static

References opj_worker_thread_t::cond, opj_thread_pool_t::cond, opj_job_list_t::job, opj_thread_pool_t::job_queue, opj_worker_thread_t::marked_as_waiting, opj_worker_thread_t::mutex, opj_thread_pool_t::mutex, opj_job_list_t::next, opj_worker_thread_list_t::next, opj_cond_signal(), opj_cond_wait(), OPJ_FALSE, opj_free(), opj_malloc(), opj_mutex_lock(), opj_mutex_unlock(), OPJ_TRUE, OPJWTS_ERROR, OPJWTS_STOP, opj_thread_pool_t::pending_jobs_count, opj_thread_pool_t::signaling_threshold, opj_thread_pool_t::state, opj_thread_pool_t::waiting_worker_thread_count, opj_thread_pool_t::waiting_worker_thread_list, opj_worker_thread_list_t::worker_thread, and opj_thread_pool_t::worker_threads_count.

Referenced by opj_worker_thread_function().

## ◆ opj_thread_pool_setup()

static OPJ_BOOL opj_thread_pool_setup | ( | opj_thread_pool_t * | tp,
|  | int | num_threads
| ) |  |
| static

References opj_worker_thread_t::cond, opj_thread_pool_t::cond, opj_worker_thread_t::marked_as_waiting, opj_worker_thread_t::mutex, opj_thread_pool_t::mutex, opj_calloc(), opj_cond_create(), opj_cond_wait(), OPJ_FALSE, opj_mutex_create(), opj_mutex_destroy(), opj_mutex_lock(), opj_mutex_unlock(), opj_thread_create(), OPJ_TRUE, opj_worker_thread_function(), OPJWTS_ERROR, opj_thread_pool_t::state, opj_worker_thread_t::thread, opj_worker_thread_t::tp, opj_thread_pool_t::waiting_worker_thread_count, opj_thread_pool_t::worker_threads, and opj_thread_pool_t::worker_threads_count.

Referenced by opj_thread_pool_create().

## ◆ opj_tls_destroy()

static void opj_tls_destroy | ( | opj_tls_t * | tls | ) |
| static

References opj_tls_t::key_val, opj_tls_t::key_val_count, opj_free(), opj_tls_key_val_t::opj_free_func, and opj_tls_key_val_t::value.

Referenced by opj_thread_pool_destroy(), and opj_worker_thread_function().

## ◆ opj_tls_new()

static opj_tls_t* opj_tls_new | ( | void |  | ) |
| static

References opj_calloc().

Referenced by opj_thread_pool_create(), and opj_worker_thread_function().

## ◆ opj_worker_thread_function()

static void opj_worker_thread_function | ( | void * | user_data | ) |
| static

References opj_worker_thread_job_t::job_fn, OPJ_FALSE, opj_free(), opj_thread_pool_get_next_job(), opj_tls_destroy(), opj_tls_new(), OPJ_TRUE, opj_worker_thread_t::tp, and opj_worker_thread_job_t::user_data.

Referenced by opj_thread_pool_setup().