Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_thread.h
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework thread support header.
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_THREAD_H__
10 #define __AFW_THREAD_H__
11 
12 #include "afw_interface.h"
13 
29 
31 #define afw_thread_mutex_create apr_thread_mutex_create
32 
34 #define afw_thread_mutex_lock apr_thread_mutex_lock
35 
37 #define afw_thread_mutex_trylock apr_thread_mutex_trylock
38 
40 #define afw_thread_mutex_unlock apr_thread_mutex_unlock
41 
43 #define afw_thread_mutex_destroy apr_thread_mutex_destroy
44 
46 #define AFW_THREAD_FUNCTION APR_THREAD_FUNC
47 
50  (const afw_thread_t *thread, void *arg);
51 
53 typedef struct afw_thread_attr_s afw_thread_attr_t;
54 
56 struct afw_thread_s {
57  afw_thread_attr_t *thread_attr;
58 
61 
64 
66  const afw_utf8_t *name;
67 
70 
72  const afw_pool_t *p;
73 
76 
78  apr_thread_t *apr_thread;
79 };
80 
81 
90  const afw_pool_t *p, afw_xctx_t *xctx);
91 
92 
104 AFW_DECLARE(const afw_thread_t *)
106  afw_thread_attr_t *thread_attr,
107  afw_thread_function_t start_function,
108  void *start_function_arg,
109  const afw_utf8_t *name,
110  afw_integer_t thread_number,
111  afw_xctx_t *xctx);
112 
113 
120 AFW_DECLARE(void)
122  const afw_thread_t *thread,
123  afw_xctx_t *xctx);
124 
125 
137 #define AFW_THREAD_MUTEX_LOCK(mutex, xctx) \
138 do { \
139  afw_thread_mutex_t *this_mutex; \
140  this_mutex = mutex; \
141  afw_thread_mutex_lock(mutex); \
142  AFW_TRY
143 
144 
145 
151 #define AFW_THREAD_MUTEX_UNLOCK() \
152 AFW_FINALLY { \
153  afw_thread_mutex_unlock(this_mutex); \
154 } \
155 AFW_ENDTRY; \
156 } while(0)
157 
158 
159 AFW_END_DECLARES
160 
163 #endif /* __AFW_THREAD_H__ */
#define AFW_BEGIN_DECLARES
#define AFW_DECLARE(type)
Declare a public afw function.
Interfaceafw_interface header.
struct afw_thread_attr_s afw_thread_attr_t
Typedef for afw_thread_attr.
Definition: afw_common.h:1374
apr_int64_t afw_integer_t
typedef for big signed int.
Definition: afw_common.h:321
void *(AFW_THREAD_FUNCTION * afw_thread_function_t)(const afw_thread_t *thread, void *arg)
Typedef for thread start function.
Definition: afw_thread.h:50
void afw_thread_join(const afw_thread_t *thread, afw_xctx_t *xctx)
Join a thread.
Definition: afw_thread.c:71
#define AFW_THREAD_FUNCTION
Uses APR_THREAD_FUNC as AFW_THREAD_FUNCTION.
Definition: afw_thread.h:46
const afw_thread_t * afw_thread_create(afw_thread_attr_t *thread_attr, afw_thread_function_t start_function, void *start_function_arg, const afw_utf8_t *name, afw_integer_t thread_number, afw_xctx_t *xctx)
Create a thread.
Definition: afw_thread.c:41
afw_thread_attr_t * afw_thread_attr_create(const afw_pool_t *p, afw_xctx_t *xctx)
Create a thread attr.
Definition: afw_thread.c:19
Interface afw_pool public struct.
Struct for public part of afw_pool_t.
Definition: afw_thread.h:56
afw_integer_t thread_number
The thread number within the afw environment.
Definition: afw_thread.h:69
afw_xctx_t * xctx
The base xctx for the thread.
Definition: afw_thread.h:75
apr_thread_t * apr_thread
The associated apr thread.
Definition: afw_thread.h:78
const afw_pool_t * p
The thread specific pool for the thread.
Definition: afw_thread.h:72
afw_thread_function_t start_function
The function called when the thread starts.
Definition: afw_thread.h:60
const afw_utf8_t * name
The name passed on afw_thread_create().
Definition: afw_thread.h:66
void * start_function_arg
The arg passed to the start function.
Definition: afw_thread.h:63
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.