OpenJPEG  2.4.0
thread.h
Go to the documentation of this file.
1 /*
2  * The copyright in this software is being made available under the 2-clauses
3  * BSD License, included below. This software may be subject to other third
4  * party and contributor rights, including patent rights, and no such rights
5  * are granted under this license.
6  *
7  * Copyright (c) 2016, Even Rouault
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef THREAD_H
33 #define THREAD_H
34 
35 #include "openjpeg.h"
36 
47 
50 
52 typedef struct opj_mutex_t opj_mutex_t;
53 
59 
63 void opj_mutex_lock(opj_mutex_t* mutex);
64 
68 void opj_mutex_unlock(opj_mutex_t* mutex);
69 
73 void opj_mutex_destroy(opj_mutex_t* mutex);
74 
79 
81 typedef struct opj_cond_t opj_cond_t;
82 
88 
120 void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex);
121 
128 void opj_cond_signal(opj_cond_t* cond);
129 
133 void opj_cond_destroy(opj_cond_t* cond);
134 
139 
141 typedef struct opj_thread_t opj_thread_t;
142 
146 typedef void (*opj_thread_fn)(void* user_data);
147 
154 opj_thread_t* opj_thread_create(opj_thread_fn thread_fn, void* user_data);
155 
160 void opj_thread_join(opj_thread_t* thread);
161 
167 typedef struct opj_tls_t opj_tls_t;
168 
174 void* opj_tls_get(opj_tls_t* tls, int key);
175 
177 typedef void (*opj_tls_free_func)(void* value);
178 
186 OPJ_BOOL opj_tls_set(opj_tls_t* tls, int key, void* value,
187  opj_tls_free_func free_func);
188 
193 
196 
207 opj_thread_pool_t* opj_thread_pool_create(int num_threads);
208 
213 typedef void (*opj_job_fn)(void* user_data, opj_tls_t* tls);
214 
215 
226  void* user_data);
227 
238  int max_remaining_jobs);
239 
246 
251 
255 
256 #endif /* THREAD_H */
void(* opj_job_fn)(void *user_data, opj_tls_t *tls)
User function to execute in a thread.
Definition: thread.h:213
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
int OPJ_BOOL
Definition: openjpeg.h:110
opj_thread_pool_t * opj_thread_pool_create(int num_threads)
Create a new thread pool.
Definition: thread.c:625
opj_cond_t * opj_cond_create(void)
Creates a condition.
Definition: thread.c:463
void opj_cond_wait(opj_cond_t *cond, opj_mutex_t *mutex)
Wait for the condition to be signaled.
Definition: thread.c:468
void(* opj_thread_fn)(void *user_data)
User function to execute in a thread.
Definition: thread.h:146
Definition: thread.c:504
void(* opj_tls_free_func)(void *value)
Type of the function used to free a TLS value.
Definition: thread.h:177
void opj_cond_destroy(opj_cond_t *cond)
Destroy a condition.
Definition: thread.c:479
struct opj_cond_t opj_cond_t
Opaque type for a condition.
Definition: thread.h:81
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
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_thread_t * opj_thread_create(opj_thread_fn thread_fn, void *user_data)
Creates a new thread.
Definition: thread.c:484
void opj_mutex_destroy(opj_mutex_t *mutex)
Destroy a mutex.
Definition: thread.c:458
void opj_cond_signal(opj_cond_t *cond)
Signal waiting threads on a condition.
Definition: thread.c:474
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
struct opj_mutex_t opj_mutex_t
Opaque type for a mutex.
Definition: thread.h:52
struct opj_thread_t opj_thread_t
Opaque type for a thread handle.
Definition: thread.h:141
opj_mutex_t * opj_mutex_create(void)
Creates a mutex.
Definition: thread.c:443
Definition: thread.c:605
void opj_mutex_unlock(opj_mutex_t *mutex)
Unlock/release the mutex.
Definition: thread.c:453
opj_tls_t * tls
Definition: thread.c:615
void * opj_tls_get(opj_tls_t *tls, int key)
Get a thread local value corresponding to the provided key.
Definition: thread.c:529
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
void opj_mutex_lock(opj_mutex_t *mutex)
Lock/acquire the mutex.
Definition: thread.c:448
void opj_thread_pool_destroy(opj_thread_pool_t *tp)
Destroy a thread pool.
Definition: thread.c:919