flext 0.6.2
fldefs_meththr.h
Go to the documentation of this file.
1/*
2flext - C++ layer for Max and Pure Data externals
3
4Copyright (c) 2001-2015 Thomas Grill (gr@grrrr.org)
5For information on usage and redistribution, and for a DISCLAIMER OF ALL
6WARRANTIES, see the file, "license.txt," in this distribution.
7*/
8
14#ifndef __FLEXT_DEFS_METHTHR_H
15#define __FLEXT_DEFS_METHTHR_H
16
17
18#ifdef FLEXT_THREADS
19
20
26#define FLEXT_THREAD(M_FUN) \
27static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c) { \
28 thr_params *p = new thr_params; \
29 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
30} \
31static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
32 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
33 bool ok = th->PushThread(); \
34 delete p; \
35 if(ok) { \
36 th->M_FUN(); \
37 th->PopThread(); \
38 } \
39}
40
42#define FLEXT_THREAD_A(M_FUN) \
43static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,t_symbol *s,int argc,t_atom *argv) { \
44 thr_params *p = new thr_params; p->set_any(s,argc,argv); \
45 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
46} \
47static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
48 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
49 bool ok = th->PushThread(); \
50 AtomAnything *args = p->var[0]._any; \
51 delete p; \
52 if(ok) { \
53 th->M_FUN(args->Header(),args->Count(),args->Atoms()); \
54 th->PopThread(); \
55 } \
56 delete args; \
57}
58
60#define FLEXT_THREAD_V(M_FUN) \
61static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,int argc,t_atom *argv) { \
62 thr_params *p = new thr_params; p->set_list(argc,argv); \
63 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
64} \
65static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
66 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
67 bool ok = th->PushThread(); \
68 AtomList *args = p->var[0]._list; \
69 delete p; \
70 if(ok) { \
71 th->M_FUN(args->Count(),args->Atoms()); \
72 th->PopThread(); \
73 } \
74 delete args; \
75}
76
80#define FLEXT_THREAD_X(M_FUN) \
81static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,void *data) { \
82 thr_params *p = new thr_params; p->var[0]._ext = data; \
83 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
84} \
85static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
86 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
87 bool ok = th->PushThread(); \
88 void *data = p->var[0]._ext; \
89 delete p; \
90 if(ok) { \
91 th->M_FUN(data); \
92 th->PopThread(); \
93 } \
94 /* delete (char *)data; */ \
95}
96
98#define FLEXT_THREAD_B(M_FUN) \
99static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,int &arg1) { \
100 thr_params *p = new thr_params; p->var[0]._bool = arg1 != 0; \
101 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
102} \
103static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
104 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
105 bool ok = th->PushThread(); \
106 bool b = p->var[0]._bool; \
107 delete p; \
108 if(ok) { \
109 th->M_FUN(b); \
110 th->PopThread(); \
111 } \
112}
113
115#define FLEXT_THREAD_1(M_FUN,TP1) \
116static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,TP1 &arg1) { \
117 thr_params *p = new thr_params(1); \
118 p->var[0]._ ## TP1 = arg1; \
119 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
120} \
121static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
122 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
123 bool ok = th->PushThread(); \
124 const TP1 v1 = p->var[0]._ ## TP1; \
125 delete p; \
126 if(ok) { \
127 th->M_FUN(v1); \
128 th->PopThread(); \
129 } \
130}
131
133#define FLEXT_THREAD_2(M_FUN,TP1,TP2) \
134static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,TP1 &arg1,TP2 &arg2) { \
135 thr_params *p = new thr_params(2); \
136 p->var[0]._ ## TP1 = arg1; \
137 p->var[1]._ ## TP2 = arg2; \
138 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
139} \
140static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
141 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
142 bool ok = th->PushThread(); \
143 const TP1 v1 = p->var[0]._ ## TP1; \
144 const TP1 v2 = p->var[1]._ ## TP2; \
145 delete p; \
146 if(ok) { \
147 th->M_FUN(v1,v2); \
148 th->PopThread(); \
149 } \
150}
151
153#define FLEXT_THREAD_3(M_FUN,TP1,TP2,TP3) \
154static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,TP1 &arg1,TP2 &arg2,TP3 &arg3) { \
155 thr_params *p = new thr_params(3); \
156 p->var[0]._ ## TP1 = arg1; \
157 p->var[1]._ ## TP2 = arg2; \
158 p->var[2]._ ## TP3 = arg3; \
159 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
160} \
161static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
162 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
163 bool ok = th->PushThread(); \
164 const TP1 v1 = p->var[0]._ ## TP1; \
165 const TP2 v2 = p->var[1]._ ## TP2; \
166 const TP3 v3 = p->var[2]._ ## TP3; \
167 delete p; \
168 if(ok) { \
169 th->M_FUN(v1,v2,v3); \
170 th->PopThread(); \
171 } \
172}
173
175#define FLEXT_THREAD_4(M_FUN,TP1,TP2,TP3,TP4) \
176static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,TP1 &arg1,TP2 &arg2,TP3 &arg3,TP4 &arg4) { \
177 thr_params *p = new thr_params(4); \
178 p->var[0]._ ## TP1 = arg1; \
179 p->var[1]._ ## TP2 = arg2; \
180 p->var[2]._ ## TP3 = arg3; \
181 p->var[3]._ ## TP4 = arg4; \
182 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
183} \
184static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
185 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
186 bool ok = th->PushThread(); \
187 const TP1 v1 = p->var[0]._ ## TP1; \
188 const TP2 v2 = p->var[1]._ ## TP2; \
189 const TP3 v3 = p->var[2]._ ## TP3; \
190 const TP4 v4 = p->var[3]._ ## TP4; \
191 delete p; \
192 if(ok) { \
193 th->M_FUN(v1,v2,v3,v4); \
194 th->PopThread(); \
195 } \
196}
197
199#define FLEXT_THREAD_5(M_FUN,TP1,TP2,TP3,TP4,TP5) \
200static bool FLEXT_CALL_PRE(M_FUN)(flext_base *c,TP1 &arg1,TP2 &arg2,TP3 &arg3,TP4 &arg4,TP5 &arg5) { \
201 thr_params *p = new thr_params(5); \
202 p->var[0]._ ## TP1 = arg1; \
203 p->var[1]._ ## TP2 = arg2; \
204 p->var[2]._ ## TP3 = arg3; \
205 p->var[3]._ ## TP4 = arg4; \
206 p->var[4]._ ## TP5 = arg5; \
207 return c->StartThread(FLEXT_THR_PRE(M_FUN),p,#M_FUN); \
208} \
209static void FLEXT_THR_PRE(M_FUN)(thr_params *p) { \
210 thisType *th = FLEXT_CAST<thisType *>(p->cl); \
211 bool ok = th->PushThread(); \
212 const TP1 v1 = p->var[0]._ ## TP1; \
213 const TP2 v2 = p->var[1]._ ## TP2; \
214 const TP3 v3 = p->var[2]._ ## TP3; \
215 const TP4 v4 = p->var[3]._ ## TP4; \
216 const TP5 v5 = p->var[4]._ ## TP5; \
217 delete p; \
218 if(ok) { \
219 th->M_FUN(v1,v2,v3,v4,v5); \
220 th->PopThread(); \
221 } \
222}
223
224
226
228#define FLEXT_THREAD_F(M_FUN) \
229\
230FLEXT_THREAD_1(M_FUN,float)
231
233#define FLEXT_THREAD_FF(M_FUN) \
234\
235FLEXT_THREAD_2(M_FUN,float,float)
236
238#define FLEXT_THREAD_FFF(M_FUN) \
239\
240FLEXT_THREAD_3(M_FUN,float,float,float)
241
243#define FLEXT_THREAD_I(M_FUN) \
244\
245FLEXT_THREAD_1(M_FUN,int)
246
248#define FLEXT_THREAD_II(M_FUN) \
249\
250FLEXT_THREAD_2(M_FUN,int,int)
251
253#define FLEXT_THREAD_III(M_FUN) \
254\
255FLEXT_THREAD_3(M_FUN,int,int,int)
256
258#define FLEXT_THREAD_S(M_FUN) \
259\
260FLEXT_THREAD_1(M_FUN,t_symptr)
261
262// deprecated
263#define FLEXT_THREAD_G FLEXT_THREAD_V
264
266
267
268#endif // FLEXT_THREADS
269
270
271#endif