plibsys 0.0.5
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
104
106typedef struct PUThread_ PUThread;
107
109typedef struct PUThreadKey_ PUThreadKey;
110
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
167
176
184
193 PUThreadPriority prio);
194
204
214
227
235
244
253
261
271
281
293 ppointer value);
294
307 ppointer value);
308
310
311#endif /* PLIBSYS_HEADER_PUTHREAD_H */
Miscellaneous macros.
#define P_BEGIN_DECLS
Starts .h file declarations to be exported as C functions.
Definition pmacros.h:298
#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
#define P_LIB_API
Exports a symbol from a shared library.
Definition pmacros.h:138
Types definitions.
void(* PDestroyFunc)(ppointer data)
Object destroy notification function.
Definition ptypes.h:1097
char pchar
Type for a char.
Definition ptypes.h:116
unsigned int psize
Type for a platform independent size_t.
Definition ptypes.h:224
void * P_HANDLE
Platform independent system handle.
Definition ptypes.h:1070
void * ppointer
Type for a pointer.
Definition ptypes.h:109
int pint
Type for an int.
Definition ptypes.h:120
signed int pboolean
Type for a bool.
Definition ptypes.h:114
unsigned int puint32
Type for unsigned 32 bit.
Definition ptypes.h:83
P_LIB_API void p_uthread_set_local(PUThreadKey *key, ppointer value)
Sets a TLS value.
P_LIB_API void p_uthread_replace_local(PUThreadKey *key, ppointer value)
Replaces a TLS value.
P_LIB_API P_HANDLE p_uthread_current_id(void)
Gets an ID of the current (caller) thread.
P_LIB_API void p_uthread_exit(pint code)
Exits from the currently running (caller) thread.
P_LIB_API void p_uthread_yield(void)
Tells the scheduler to skip the current (caller) thread in the current planning stage.
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...
P_LIB_API pint p_uthread_join(PUThread *thread)
Waits for the selected thread to become finished.
P_LIB_API void p_uthread_local_free(PUThreadKey *key)
Frees a TLS reference key.
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_ref(PUThread *thread)
Increments a thread reference counter.
P_LIB_API pboolean p_uthread_set_priority(PUThread *thread, PUThreadPriority prio)
Sets a thread priority.
P_LIB_API PUThread * p_uthread_current(void)
Gets a thread structure of the current (caller) thread.
PUThreadPriority_
Thread priority.
Definition puthread.h:112
@ P_UTHREAD_PRIORITY_LOW
Scheduled less often than P_UTHREAD_PRIORITY_NORMAL.
Definition puthread.h:116
@ P_UTHREAD_PRIORITY_TIMECRITICAL
Scheduled as often as possible.
Definition puthread.h:120
@ P_UTHREAD_PRIORITY_INHERIT
Inherits the caller thread priority.
Definition puthread.h:113
@ P_UTHREAD_PRIORITY_NORMAL
Operating system's default priority.
Definition puthread.h:117
@ P_UTHREAD_PRIORITY_LOWEST
Scheduled less often than P_UTHREAD_PRIORITY_LOW.
Definition puthread.h:115
@ P_UTHREAD_PRIORITY_IDLE
Scheduled only when no other threads are running.
Definition puthread.h:114
@ P_UTHREAD_PRIORITY_HIGHEST
Scheduled more often than P_UTHREAD_PRIORITY_HIGH.
Definition puthread.h:119
@ P_UTHREAD_PRIORITY_HIGH
Scheduled more often than P_UTHREAD_PRIORITY_NORMAL.
Definition puthread.h:118
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.
P_LIB_API PUThreadKey * p_uthread_local_new(PDestroyFunc free_func)
Create a new TLS reference key.
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
P_LIB_API ppointer p_uthread_get_local(PUThreadKey *key)
Gets a TLS value.
struct PUThread_ PUThread
Thread opaque data type.
Definition puthread.h:106
P_LIB_API void p_uthread_unref(PUThread *thread)
Decrements a thread reference counter.
P_LIB_API PUThread * p_uthread_create(PUThreadFunc func, ppointer data, pboolean joinable, const pchar *name)
Creates a PUThread and starts it.
enum PUThreadPriority_ PUThreadPriority
Thread priority.