plibsys
puthread.h
Go to the documentation of this file.
1 /*
2  * The MIT License
3  *
4  * Copyright (C) 2010-2019 Alexander Saprykin <saprykin.spb@gmail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * 'Software'), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
90 #if !defined (PLIBSYS_H_INSIDE) && !defined (PLIBSYS_COMPILATION)
91 # error "Header files shouldn't be included directly, consider using <plibsys.h> instead."
92 #endif
93 
94 #ifndef PLIBSYS_HEADER_PUTHREAD_H
95 #define PLIBSYS_HEADER_PUTHREAD_H
96 
97 #include <pmacros.h>
98 #include <ptypes.h>
99 
101 
103 typedef ppointer (*PUThreadFunc) (ppointer arg);
104 
106 typedef struct PUThread_ PUThread;
107 
109 typedef struct PUThreadKey_ PUThreadKey;
110 
112 typedef enum PUThreadPriority_ {
122 
138  ppointer data,
139  pboolean joinable,
140  PUThreadPriority prio,
141  psize stack_size,
142  const pchar *name);
143 
157  ppointer data,
158  pboolean joinable,
159  const pchar *name);
160 
166 P_LIB_API void p_uthread_exit (pint code);
167 
176 
184 
193  PUThreadPriority prio);
194 
203 P_LIB_API void p_uthread_yield (void);
204 
214 
227 
235 
243 P_LIB_API void p_uthread_ref (PUThread *thread);
244 
252 P_LIB_API void p_uthread_unref (PUThread *thread);
253 
261 
271 
281 
293  ppointer value);
294 
307  ppointer value);
308 
310 
311 #endif /* PLIBSYS_HEADER_PUTHREAD_H */
P_LIB_API PUThreadKey * p_uthread_local_new(PDestroyFunc free_func)
Create a new TLS reference key.
Scheduled less often than P_UTHREAD_PRIORITY_NORMAL.
Definition: puthread.h:116
Scheduled more often than P_UTHREAD_PRIORITY_NORMAL.
Definition: puthread.h:118
#define P_END_DECLS
Closes .h file declarations to be exported as C functions, should be always used after P_BEGIN_DECLS...
Definition: pmacros.h:299
P_BEGIN_DECLS typedef ppointer(* PUThreadFunc)(ppointer arg)
Typedef for a PUThread running method.
Definition: puthread.h:103
struct PUThreadKey_ PUThreadKey
TLS key opaque data type.
Definition: puthread.h:109
void(* PDestroyFunc)(ppointer data)
Object destroy notification function.
Definition: ptypes.h:1097
P_LIB_API void p_uthread_yield(void)
Tells the scheduler to skip the current (caller) thread in the current planning stage.
unsigned int puint32
Type for unsigned 32 bit.
Definition: ptypes.h:83
Operating system&#39;s default priority.
Definition: puthread.h:117
P_LIB_API void p_uthread_set_local(PUThreadKey *key, ppointer value)
Sets a TLS value.
P_LIB_API void p_uthread_unref(PUThread *thread)
Decrements a thread reference counter.
int pint
Type for an int.
Definition: ptypes.h:120
Scheduled more often than P_UTHREAD_PRIORITY_HIGH.
Definition: puthread.h:119
char pchar
Type for a char.
Definition: ptypes.h:116
P_LIB_API void p_uthread_ref(PUThread *thread)
Increments a thread reference counter.
P_LIB_API ppointer p_uthread_get_local(PUThreadKey *key)
Gets a TLS value.
unsigned int psize
Type for a platform independent size_t.
Definition: ptypes.h:224
Miscellaneous macros.
P_LIB_API P_HANDLE p_uthread_current_id(void)
Gets an ID of the current (caller) thread.
void * ppointer
Type for a pointer.
Definition: ptypes.h:109
P_LIB_API PUThread * p_uthread_current(void)
Gets a thread structure of the current (caller) thread.
enum PUThreadPriority_ PUThreadPriority
Thread priority.
signed int pboolean
Type for a bool.
Definition: ptypes.h:114
void * P_HANDLE
Platform independent system handle.
Definition: ptypes.h:1070
Scheduled less often than P_UTHREAD_PRIORITY_LOW.
Definition: puthread.h:115
Inherits the caller thread priority.
Definition: puthread.h:113
P_LIB_API void p_uthread_replace_local(PUThreadKey *key, ppointer value)
Replaces a TLS value.
P_LIB_API pint p_uthread_sleep(puint32 msec)
Sleeps the current thread (caller) for a specified amount of time.
P_LIB_API void p_uthread_exit(pint code)
Exits from the currently running (caller) thread.
P_LIB_API void p_uthread_local_free(PUThreadKey *key)
Frees a TLS reference key.
#define P_LIB_API
Exports a symbol from a shared library.
Definition: pmacros.h:138
Scheduled only when no other threads are running.
Definition: puthread.h:114
Scheduled as often as possible.
Definition: puthread.h:120
P_LIB_API PUThread * p_uthread_create(PUThreadFunc func, ppointer data, pboolean joinable, const pchar *name)
Creates a PUThread and starts it.
Types definitions.
P_LIB_API pint p_uthread_join(PUThread *thread)
Waits for the selected thread to become finished.
struct PUThread_ PUThread
Thread opaque data type.
Definition: puthread.h:106
P_LIB_API PUThread * p_uthread_create_full(PUThreadFunc func, ppointer data, pboolean joinable, PUThreadPriority prio, psize stack_size, const pchar *name)
Creates a new PUThread and starts it.
#define P_BEGIN_DECLS
Starts .h file declarations to be exported as C functions.
Definition: pmacros.h:298
P_LIB_API pboolean p_uthread_set_priority(PUThread *thread, PUThreadPriority prio)
Sets a thread priority.
PUThreadPriority_
Thread priority.
Definition: puthread.h:112
P_LIB_API pint p_uthread_ideal_count(void)
Gets the ideal number of threads for the system based on the number of avaialble CPUs and cores (phys...