Qore Programming Language  0.8.7
 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;
40 
42 typedef void (*qtdest_t)(void *);
43 
45 typedef void (*qtrdest_t)(void *, ExceptionSink *);
46 
48 
54 DLLEXPORT bool is_valid_qore_thread();
55 
57 DLLEXPORT int gettid();
58 
60 DLLEXPORT QoreProgram *getProgram();
61 
63 DLLEXPORT const AbstractQoreZoneInfo *currentTZ();
64 
66 
68 DLLEXPORT void set_thread_resource(AbstractThreadResource *atr);
69 
71 
75 
77 
83 DLLEXPORT void set_thread_resource_id(q_trid_t trid, AbstractThreadResource *atr);
84 
86 
91 DLLEXPORT int remove_thread_resource_id(q_trid_t trid);
92 
94 
97 DLLEXPORT bool check_thread_resource_id(q_trid_t trid);
98 
100 DLLEXPORT q_trid_t qore_get_trid();
101 
103 
111 private:
112  static ThreadCleanupNode *head;
113 
114 public:
115  DLLLOCAL ThreadCleanupList();
116  DLLLOCAL ~ThreadCleanupList();
117  DLLLOCAL void exec();
118 
120 
123  DLLEXPORT void push(qtdest_t func, void *arg);
124 
126 
128  DLLEXPORT void pop(bool exec = true);
129 };
130 
132 DLLEXPORT extern ThreadCleanupList tclist;
133 
137 #define QFT_OK 0
138 #define QFT_ERROR -1
139 #define QFT_REGISTERED -2
140 
141 
142 
143 
154 DLLEXPORT int q_register_foreign_thread();
155 
157 
166 DLLEXPORT int q_deregister_foreign_thread();
167 
169 
173 DLLEXPORT int q_reserve_foreign_thread_id();
174 
176 
182 DLLEXPORT int q_release_reserved_foreign_thread_id(int tid);
183 
185 
191 DLLEXPORT int q_register_reserved_foreign_thread(int tid);
192 
194 
199 
201 
204 private:
206  DLLLOCAL QoreForeignThreadHelper& operator=(const QoreForeignThreadHelper&);
208  DLLLOCAL void* operator new(size_t);
209 
210 protected:
211  class qore_foreign_thread_priv* priv;
212 
213 public:
215  DLLEXPORT QoreForeignThreadHelper();
216 
218  DLLEXPORT explicit QoreForeignThreadHelper(int tid);
219 
221  DLLEXPORT ~QoreForeignThreadHelper();
222 };
223 
224 #endif // ifndef _QORE_THREAD_H