Qore Programming Language 0.8.8

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qore_thread.h
Go to the documentation of this file.
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 qore_thread.h
4
5 POSIX thread library for Qore
6
7 Qore Programming Language
8
9 Copyright 2003 - 2013 David Nichols
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #ifndef _QORE_QORE_THREAD_H
27 #define _QORE_QORE_THREAD_H
28
33 #include <stdio.h>
34 #include <pthread.h>
35
36 class QoreProgram;
37 class AbstractQoreZoneInfo;
38 class ThreadCleanupNode;
39 class AbstractThreadResource;
40
42 typedef void (*qtdest_t)(void *);
43
45 typedef void (*qtrdest_t)(void *, ExceptionSink *);
46
48 typedef void (*q_thread_t)(ExceptionSink* xsink, void* arg);
49
51
57 DLLEXPORT bool is_valid_qore_thread();
58
60 DLLEXPORT int gettid();
61
63 DLLEXPORT QoreProgram *getProgram();
64
66 DLLEXPORT const AbstractQoreZoneInfo *currentTZ();
67
69
71 DLLEXPORT void set_thread_resource(AbstractThreadResource* atr);
72
74
77 DLLEXPORT int remove_thread_resource(AbstractThreadResource* atr);
78
80
83 DLLEXPORT bool check_thread_resource(AbstractThreadResource* atr);
84
85 #if 0
86
93 DLLEXPORT void set_thread_resource_id(q_trid_t trid, AbstractThreadResource *atr);
94
96
101 DLLEXPORT int remove_thread_resource_id(q_trid_t trid);
102
104
107 DLLEXPORT bool check_thread_resource_id(q_trid_t trid);
108 #endif
109
111 DLLEXPORT q_trid_t qore_get_trid();
112
114
121 class ThreadCleanupList {
122 private:
123 static ThreadCleanupNode *head;
124
125 public:
126 DLLLOCAL ThreadCleanupList();
127 DLLLOCAL ~ThreadCleanupList();
128 DLLLOCAL void exec();
129
131
134 DLLEXPORT void push(qtdest_t func, void *arg);
135
137
139 DLLEXPORT void pop(bool exec = true);
140 };
141
143 DLLEXPORT extern ThreadCleanupList tclist;
144
148 #define QFT_OK 0
149 #define QFT_ERROR -1
150 #define QFT_REGISTERED -2
151
152
153
165 DLLEXPORT int q_register_foreign_thread();
166
168
177 DLLEXPORT int q_deregister_foreign_thread();
178
180
184 DLLEXPORT int q_reserve_foreign_thread_id();
185
187
193 DLLEXPORT int q_release_reserved_foreign_thread_id(int tid);
194
196
202 DLLEXPORT int q_register_reserved_foreign_thread(int tid);
203
205
209 DLLEXPORT int q_deregister_reserved_foreign_thread();
210
212
220 int q_start_thread(ExceptionSink* xsink, q_thread_t f, void* arg = 0);
221
223
225 class QoreForeignThreadHelper {
226 private:
228 DLLLOCAL QoreForeignThreadHelper& operator=(const QoreForeignThreadHelper&);
229 DLLLOCAL QoreForeignThreadHelper(const QoreForeignThreadHelper&);
230 DLLLOCAL void* operator new(size_t);
231
232 protected:
233 class qore_foreign_thread_priv* priv;
234
235 public:
237 DLLEXPORT QoreForeignThreadHelper();
238
240 DLLEXPORT explicit QoreForeignThreadHelper(int tid);
241
243 DLLEXPORT ~QoreForeignThreadHelper();
244 };
245
246 #endif // ifndef _QORE_THREAD_H
AbstractThreadResource
base class for saving data using Qore&#39;s thread resource management system
Definition: AbstractThreadResource.h:42
q_reserve_foreign_thread_id
DLLEXPORT int q_reserve_foreign_thread_id()
reserves a thread ID for later registration and returns the TID reserved; use q_release_reserved_fore...
q_thread_t
void(* q_thread_t)(ExceptionSink *xsink, void *arg)
pointer to a function that can be started with q_start_thread()
Definition: qore_thread.h:48
gettid
DLLEXPORT int gettid()
returns the current TID number
ThreadCleanupList::pop
DLLEXPORT void pop(bool exec=true)
must only be called in the module destructor/deletion function
QoreForeignThreadHelper::~QoreForeignThreadHelper
DLLEXPORT ~QoreForeignThreadHelper()
deregisters the current thread if the registration was successful using either q_deregister_foreign_t...
check_thread_resource
DLLEXPORT bool check_thread_resource(AbstractThreadResource *atr)
check if a thread resouce has been saved
tclist
DLLEXPORT ThreadCleanupList tclist
the interface to the thread cleanup list
set_thread_resource
DLLEXPORT void set_thread_resource(AbstractThreadResource *atr)
save a resource against a thread for thread resource handling
qtrdest_t
void(* qtrdest_t)(void *, ExceptionSink *)
pointer to a qore thread resource destructor function
Definition: qore_thread.h:45
ThreadCleanupList::push
DLLEXPORT void push(qtdest_t func, void *arg)
must only be called in the module initialization function
remove_thread_resource
DLLEXPORT int remove_thread_resource(AbstractThreadResource *atr)
remove the resource from the thread resource list for the current thread
getProgram
DLLEXPORT QoreProgram * getProgram()
returns the current QoreProgram
q_deregister_foreign_thread
DLLEXPORT int q_deregister_foreign_thread()
deregisters the current thread as a foreign thread
qtdest_t
void(* qtdest_t)(void *)
pointer to a qore thread destructor function
Definition: qore_thread.h:42
q_release_reserved_foreign_thread_id
DLLEXPORT int q_release_reserved_foreign_thread_id(int tid)
releases a TID reserved with q_reserve_foreign_thread_id()
q_trid_t
unsigned q_trid_t
type for thread resource IDs (unique within a single running qore library process) ...
Definition: common.h:423
QoreProgram
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:95
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
QoreForeignThreadHelper::QoreForeignThreadHelper
DLLEXPORT QoreForeignThreadHelper()
registers the current thread as a foreign thread; the thread will be deregistered with q_deregister_f...
ThreadCleanupList
list of functions to be run when a thread ends; required for some external libraries that require exp...
Definition: qore_thread.h:121
q_register_foreign_thread
DLLEXPORT int q_register_foreign_thread()
registers the current thread as a Qore thread; returns QFT_OK (0) if the thread was successfully regi...
QoreForeignThreadHelper
use this class to temporarily register and deregister a foreign thread to allow Qore code to be execu...
Definition: qore_thread.h:225
q_start_thread
int q_start_thread(ExceptionSink *xsink, q_thread_t f, void *arg=0)
starts a new thread with the given arguments, when the thread terminates, it deregisters itself ...
qore_get_trid
DLLEXPORT q_trid_t qore_get_trid()
get a thread resource ID
q_deregister_reserved_foreign_thread
DLLEXPORT int q_deregister_reserved_foreign_thread()
deregisters a foreign qore thread but retains the TID as reserved
q_register_reserved_foreign_thread
DLLEXPORT int q_register_reserved_foreign_thread(int tid)
registers a foreign qore thread as a Qore thread with a reserved TID
is_valid_qore_thread
DLLEXPORT bool is_valid_qore_thread()
returns true if the current thread is a valid qore thread; it is not safe to call most Qore functions...
currentTZ
DLLEXPORT const AbstractQoreZoneInfo * currentTZ()
returns the current local time zone, note that if 0 = UTC