thread.h
Go to the documentation of this file.
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2016, Even Rouault
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THREAD_H
#define THREAD_H
#include "openjpeg.h"
typedef struct opj_mutex_t opj_mutex_t;
opj_mutex_t* opj_mutex_create(void);
void opj_mutex_lock(opj_mutex_t* mutex);
void opj_mutex_unlock(opj_mutex_t* mutex);
void opj_mutex_destroy(opj_mutex_t* mutex);
typedef struct opj_cond_t opj_cond_t;
opj_cond_t* opj_cond_create(void);
void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex);
void opj_cond_signal(opj_cond_t* cond);
void opj_cond_destroy(opj_cond_t* cond);
typedef struct opj_thread_t opj_thread_t;
typedef void (*opj_thread_fn)(void* user_data);
opj_thread_t* opj_thread_create(opj_thread_fn thread_fn, void* user_data);
void opj_thread_join(opj_thread_t* thread);
typedef struct opj_tls_t opj_tls_t;
void* opj_tls_get(opj_tls_t* tls, int key);
typedef void (*opj_tls_free_func)(void* value);
OPJ_BOOL opj_tls_set(opj_tls_t* tls, int key, void* value,
opj_tls_free_func free_func);
typedef struct opj_thread_pool_t opj_thread_pool_t;
opj_thread_pool_t* opj_thread_pool_create(int num_threads);
typedef void (*opj_job_fn)(void* user_data, opj_tls_t* tls);
OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t* tp, opj_job_fn job_fn,
void* user_data);
void opj_thread_pool_wait_completion(opj_thread_pool_t* tp,
int max_remaining_jobs);
int opj_thread_pool_get_thread_count(opj_thread_pool_t* tp);
void opj_thread_pool_destroy(opj_thread_pool_t* tp);
#endif /* THREAD_H */
openjpeg.h
OPJ_BOOL
int OPJ_BOOL
Definition openjpeg.h:116
opj_thread_pool_t
Definition thread.c:605
opj_thread_pool_t::tls
opj_tls_t * tls
Definition thread.c:615
opj_tls_t
Definition thread.c:504
opj_thread_create
opj_thread_t * opj_thread_create(opj_thread_fn thread_fn, void *user_data)
Creates a new thread.
Definition thread.c:484
opj_tls_get
void * opj_tls_get(opj_tls_t *tls, int key)
Get a thread local value corresponding to the provided key.
Definition thread.c:529
opj_thread_pool_wait_completion
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.
Definition thread.c:894
opj_cond_signal
void opj_cond_signal(opj_cond_t *cond)
Signal waiting threads on a condition.
Definition thread.c:474
opj_mutex_t
struct opj_mutex_t opj_mutex_t
Opaque type for a mutex.
Definition thread.h:52
opj_thread_pool_create
opj_thread_pool_t * opj_thread_pool_create(int num_threads)
Create a new thread pool.
Definition thread.c:625
opj_tls_free_func
void(* opj_tls_free_func)(void *value)
Type of the function used to free a TLS value.
Definition thread.h:177
opj_cond_t
struct opj_cond_t opj_cond_t
Opaque type for a condition.
Definition thread.h:81
opj_thread_pool_get_thread_count
int opj_thread_pool_get_thread_count(opj_thread_pool_t *tp)
Return the number of threads associated with the thread pool.
Definition thread.c:914
opj_mutex_destroy
void opj_mutex_destroy(opj_mutex_t *mutex)
Destroy a mutex.
Definition thread.c:458
opj_cond_wait
void opj_cond_wait(opj_cond_t *cond, opj_mutex_t *mutex)
Wait for the condition to be signaled.
Definition thread.c:468
opj_cond_create
opj_cond_t * opj_cond_create(void)
Creates a condition.
Definition thread.c:463
opj_mutex_create
opj_mutex_t * opj_mutex_create(void)
Creates a mutex.
Definition thread.c:443
opj_tls_set
OPJ_BOOL opj_tls_set(opj_tls_t *tls, int key, void *value, opj_tls_free_func free_func)
Set a thread local value corresponding to the provided key.
Definition thread.c:540
opj_mutex_lock
void opj_mutex_lock(opj_mutex_t *mutex)
Lock/acquire the mutex.
Definition thread.c:448
opj_mutex_unlock
void opj_mutex_unlock(opj_mutex_t *mutex)
Unlock/release the mutex.
Definition thread.c:453
opj_thread_join
void opj_thread_join(opj_thread_t *thread)
Wait for a thread to be finished and release associated resources to the thread handle.
Definition thread.c:491
opj_thread_pool_destroy
void opj_thread_pool_destroy(opj_thread_pool_t *tp)
Destroy a thread pool.
Definition thread.c:919
opj_thread_fn
void(* opj_thread_fn)(void *user_data)
User function to execute in a thread.
Definition thread.h:146
opj_thread_t
struct opj_thread_t opj_thread_t
Opaque type for a thread handle.
Definition thread.h:141
opj_job_fn
void(* opj_job_fn)(void *user_data, opj_tls_t *tls)
User function to execute in a thread.
Definition thread.h:213
opj_thread_pool_submit_job
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.
Definition thread.c:827
opj_cond_destroy
void opj_cond_destroy(opj_cond_t *cond)
Destroy a condition.
Definition thread.c:479