… | |
… | |
25 | |
25 | |
26 | perlinterp_release (); |
26 | perlinterp_release (); |
27 | do_the_C_thing (); |
27 | do_the_C_thing (); |
28 | perlinterp_acquire (); |
28 | perlinterp_acquire (); |
29 | |
29 | |
|
|
30 | // optional, in BOOT section: |
|
|
31 | |
|
|
32 | perlmulticore_support (); |
|
|
33 | |
30 | =head1 DESCRIPTION |
34 | =head1 DESCRIPTION |
31 | |
35 | |
32 | This documentation is the abridged version of the full documention at |
36 | This documentation is the abridged version of the full documention at |
33 | L<http://perlmulticore.schmorp.de/>. It's recommended to go there instead |
37 | L<http://perlmulticore.schmorp.de/>. It's recommended to go there instead |
34 | of reading this document. |
38 | of reading this document. |
… | |
… | |
118 | |
122 | |
119 | This could be added to perl's C<CPPFLAGS> when configuring perl on |
123 | This could be added to perl's C<CPPFLAGS> when configuring perl on |
120 | platforms that do not support threading at all for example. |
124 | platforms that do not support threading at all for example. |
121 | |
125 | |
122 | |
126 | |
|
|
127 | =head1 ADVERTISING MULTICORE API SUPPORT |
|
|
128 | |
|
|
129 | To help users find out whether a particular build of your module is, in |
|
|
130 | fact, multicore enabled, you can invoke the C<perlmulticore_support> |
|
|
131 | macro in your C<BOOT:> section, e.g.: |
|
|
132 | |
|
|
133 | |
|
|
134 | MODULE = My::Mod PACKAGE = My::Mod::Pkg |
|
|
135 | |
|
|
136 | BOOT: |
|
|
137 | perlmulticore_support (); |
|
|
138 | |
|
|
139 | What this does is set the C<$My::Mod::PERLMULTICORE_SUPPORT> variable to |
|
|
140 | the major API version * 1000 + minor version, for example, version C<1002> |
|
|
141 | introduced this feature. |
|
|
142 | |
|
|
143 | For this to work, the C<cv> parameter passed to C<BOOT:> must still be |
|
|
144 | in scope. To ensure this, either invoke the macro early in your C<BOOT:> |
|
|
145 | section, or don't declare a local variable called C<cv>, either of which |
|
|
146 | should be easy to do. |
|
|
147 | |
|
|
148 | Note that this is I<optional>, so you don't have to do that. |
|
|
149 | |
|
|
150 | |
123 | =head1 AUTHOR |
151 | =head1 AUTHOR |
124 | |
152 | |
125 | Marc A. Lehmann <perlmulticore@schmorp.de> |
153 | Marc A. Lehmann <perlmulticore@schmorp.de> |
126 | http://perlmulticore.schmorp.de/ |
154 | http://perlmulticore.schmorp.de/ |
127 | |
155 | |
… | |
… | |
134 | |
162 | |
135 | =cut |
163 | =cut |
136 | |
164 | |
137 | */ |
165 | */ |
138 | |
166 | |
|
|
167 | /* version history |
|
|
168 | * 1.1 (1001) 2015-07-03: initial release. |
|
|
169 | * 1.2 (1002) 2019-03-03: introduce optional perlmulticore_support macro. |
|
|
170 | */ |
139 | #define PERL_MULTICORE_MAJOR 1 /* bumped on incompatible changes */ |
171 | #define PERL_MULTICORE_MAJOR 1 /* bumped on incompatible changes */ |
140 | #define PERL_MULTICORE_MINOR 0 /* bumped on every change */ |
172 | #define PERL_MULTICORE_MINOR 2 /* bumped on every change */ |
141 | |
173 | |
142 | #if PERL_MULTICORE_DISABLE |
174 | #if PERL_MULTICORE_DISABLE |
143 | |
175 | |
144 | #define perlinterp_release() do { } while (0) |
176 | #define perlinterp_release() do { } while (0) |
145 | #define perlinterp_acquire() do { } while (0) |
177 | #define perlinterp_acquire() do { } while (0) |
|
|
178 | #define perlmulticore_support() do { } while (0) |
146 | |
179 | |
147 | #else |
180 | #else |
148 | |
181 | |
149 | START_EXTERN_C |
182 | START_EXTERN_C |
150 | |
183 | |
… | |
… | |
189 | if (SvPOKp (*api_svp)) |
222 | if (SvPOKp (*api_svp)) |
190 | perl_multicore_api = (struct perl_multicore_api *)SvPVX (*api_svp); /* we have one, use the existing one */ |
223 | perl_multicore_api = (struct perl_multicore_api *)SvPVX (*api_svp); /* we have one, use the existing one */ |
191 | else |
224 | else |
192 | { |
225 | { |
193 | /* create a new one with a dummy nop implementation */ |
226 | /* create a new one with a dummy nop implementation */ |
|
|
227 | #ifdef NEWSV |
194 | SV *api_sv = NEWSV (0, sizeof (*perl_multicore_api)); |
228 | SV *api_sv = NEWSV (0, sizeof (*perl_multicore_api)); |
|
|
229 | #else |
|
|
230 | SV *api_sv = newSV ( sizeof (*perl_multicore_api)); |
|
|
231 | #endif |
195 | SvCUR_set (api_sv, sizeof (*perl_multicore_api)); |
232 | SvCUR_set (api_sv, sizeof (*perl_multicore_api)); |
196 | SvPOK_only (api_sv); |
233 | SvPOK_only (api_sv); |
197 | perl_multicore_api = (struct perl_multicore_api *)SvPVX (api_sv); |
234 | perl_multicore_api = (struct perl_multicore_api *)SvPVX (api_sv); |
198 | perl_multicore_api->pmapi_release = |
235 | perl_multicore_api->pmapi_release = |
199 | perl_multicore_api->pmapi_acquire = perl_multicore_nop; |
236 | perl_multicore_api->pmapi_acquire = perl_multicore_nop; |
… | |
… | |
202 | |
239 | |
203 | /* call the real (or dummy) implementation now */ |
240 | /* call the real (or dummy) implementation now */ |
204 | perlinterp_release (); |
241 | perlinterp_release (); |
205 | } |
242 | } |
206 | |
243 | |
|
|
244 | #define perlmulticore_support() \ |
|
|
245 | sv_setiv (get_sv ( \ |
|
|
246 | form ("%s::PERLMULTICORE_SUPPORT", HvNAME (GvSTASH (CvGV (cv)))), \ |
|
|
247 | GV_ADD | GV_ADDMULTI), \ |
|
|
248 | PERL_MULTICORE_MAJOR * 1000 + PERL_MULTICORE_MINOR); \ |
|
|
249 | |
207 | END_EXTERN_C |
250 | END_EXTERN_C |
208 | |
251 | |
209 | #endif |
252 | #endif |
210 | |
253 | |
211 | #endif |
254 | #endif |
|
|
255 | |