plibsys  0.0.4
puthread.h
Go to the documentation of this file.
1 /*
2  * The MIT License
3  *
4  * Copyright (C) 2010-2017 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 
86 #if !defined (PLIBSYS_H_INSIDE) && !defined (PLIBSYS_COMPILATION)
87 # error "Header files shouldn't be included directly, consider using <plibsys.h> instead."
88 #endif
89 
90 #ifndef PLIBSYS_HEADER_PUTHREAD_H
91 #define PLIBSYS_HEADER_PUTHREAD_H
92 
93 #include <pmacros.h>
94 #include <ptypes.h>
95 
97 
99 typedef ppointer (*PUThreadFunc) (ppointer arg);
100 
102 typedef struct PUThread_ PUThread;
103 
105 typedef struct PUThreadKey_ PUThreadKey;
106 
108 typedef enum PUThreadPriority_ {
118 
133  ppointer data,
134  pboolean joinable,
135  PUThreadPriority prio,
136  psize stack_size);
137 
150  ppointer data,
151  pboolean joinable);
152 
158 P_LIB_API void p_uthread_exit (pint code);
159 
168 
176 
185  PUThreadPriority prio);
186 
195 P_LIB_API void p_uthread_yield (void);
196 
206 
219 
227 
235 P_LIB_API void p_uthread_ref (PUThread *thread);
236 
244 P_LIB_API void p_uthread_unref (PUThread *thread);
245 
253 
263 
273 
285  ppointer value);
286 
299  ppointer value);
300 
302 
303 #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:112
Scheduled more often than P_UTHREAD_PRIORITY_NORMAL.
Definition: puthread.h:114
#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
struct PUThreadKey_ PUThreadKey
TLS key opaque data type.
Definition: puthread.h:105
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.
P_LIB_API PUThread * p_uthread_create_full(PUThreadFunc func, ppointer data, pboolean joinable, PUThreadPriority prio, psize stack_size)
Creates a new PUThread and starts it.
unsigned int puint32
Type for unsigned 32 bit.
Definition: ptypes.h:83
Operating system&#39;s default priority.
Definition: puthread.h:113
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:115
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 __int64 psize
Type for a platform independent size_t.
Definition: ptypes.h:194
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:111
Inherits the caller thread priority.
Definition: puthread.h:109
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:110
Scheduled as often as possible.
Definition: puthread.h:116
P_LIB_API PUThread * p_uthread_create(PUThreadFunc func, ppointer data, pboolean joinable)
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:102
ppointer(* PUThreadFunc)(ppointer arg)
Typedef for a PUThread running method.
Definition: puthread.h:99
#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:108
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...