ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Compress-LZF/perlmulticore.h
(Generate patch)

Comparing Compress-LZF/perlmulticore.h (file contents):
Revision 1.2 by root, Sun Jun 28 17:40:38 2015 UTC vs.
Revision 1.3 by root, Mon Jun 29 23:51:28 2015 UTC

34applicability. 34applicability.
35 35
36The newest version of this document can be found at 36The newest version of this document can be found at
37L<http://pod.tst.eu/http://cvs.schmorp.de/Coro-Multicore/perlmulticore.h>. 37L<http://pod.tst.eu/http://cvs.schmorp.de/Coro-Multicore/perlmulticore.h>.
38 38
39The nwest version of the header fgile itself, which 39The newest version of the header file itself, which
40includes this documentation, can be downloaded from 40includes this documentation, can be downloaded from
41L<http://cvs.schmorp.de/Coro-Multicore/perlmulticore.h>. 41L<http://cvs.schmorp.de/Coro-Multicore/perlmulticore.h>.
42 42
43=head1 HOW DO I USE THIS IN MY MODULES? 43=head1 HOW DO I USE THIS IN MY MODULES?
44 44
118 if (res) 118 if (res)
119 { 119 {
120 // error, assume lock is held by another process and do it the slow way 120 // error, assume lock is held by another process and do it the slow way
121 perlinterp_release (); 121 perlinterp_release ();
122 res = fcntl (fd, F_SETLKW, &flock); 122 res = fcntl (fd, F_SETLKW, &flock);
123 perlinterp_release (); 123 perlinterp_acquire ();
124 } 124 }
125 125
126=head1 THE HARD AND FAST RULES 126=head1 THE HARD AND FAST RULES
127 127
128As with everything, there are a number of rules to follow. 128As with everything, there are a number of rules to follow.
198 pthread_mutex_lock (&my_mutex); 198 pthread_mutex_lock (&my_mutex);
199 do_your_non_thread_safe_thing (); 199 do_your_non_thread_safe_thing ();
200 pthread_mutex_unlock (&my_mutex); 200 pthread_mutex_unlock (&my_mutex);
201 perlinterp_acquire (); 201 perlinterp_acquire ();
202 202
203This isn't as trivial as it looks though, as you need to find out which
204threading system is in use (with L<Coro::Multicore>, it currently is
205always pthreads).
206
207=item I<Don't> get confused by having to release first. 203=item I<Don't> get confused by having to release first.
208 204
209In many real world scenarios, you acquire a resource, do something, then 205In many real world scenarios, you acquire a resource, do something, then
210release it again. Don't let this confuse you, with this, you already own 206release it again. Don't let this confuse you, with this, you already own
211the resource (the perl interpreter) so you have to I<release> first, and 207the resource (the perl interpreter) so you have to I<release> first, and
304efficient when not needed, low code and data size overhead and broad 300efficient when not needed, low code and data size overhead and broad
305applicability. 301applicability.
306 302
307=back 303=back
308 304
305
306=head1 DISABLING PERL MULTICORE AT COMPILE TIME
307
308You can disable the complete perl multicore API by defining the
309symbol C<PERL_MULTICORE_DISABLE> to C<1> (e.g. by specifying
310F<-DPERL_MULTICORE_DISABLE> as compiler argument).
311
312This will leave no traces of the API in the compiled code, suitable
313"empty" C<perl_release> and C<perl_acquire> definitions will be provided.
314
315This could be added to perl's C<CPPFLAGS> when configuring perl on
316platforms that do not support threading at all for example.
317
318
309=head1 AUTHOR 319=head1 AUTHOR
310 320
311 Marc A. Lehmann <perlmulticore@schmorp.de> 321 Marc A. Lehmann <perlmulticore@schmorp.de>
322 http://perlmulticore.schmorp.de/
312 323
313=head1 LICENSE 324=head1 LICENSE
314 325
315The F<perlmulticore.h> is put into the public domain. Where this is legally 326The F<perlmulticore.h> header file is put into the public
327domain. Where this is legally not possible, or at your
316not possible, or at your option, it can be licensed under creativecommons 328option, it can be licensed under creativecommons CC0
317CC0 license: L<https://creativecommons.org/publicdomain/zero/1.0/>. 329license: L<https://creativecommons.org/publicdomain/zero/1.0/>.
318 330
319=cut 331=cut
332
320*/ 333*/
321 334
335#define PERL_MULTICORE_MAJOR 1 /* bumped on incompatible changes */
336#define PERL_MULTICORE_MINOR 0 /* bumped on every change */
337
338#if PERL_MULTICORE_DISABLE
339
340#define perlinterp_release() do { } while (0)
341#define perlinterp_acquire() do { } while (0)
342
343#else
344
345/* this struct is shared between all modules, and currently */
346/* contain only the two function pointers for release/acquire */
322struct perl_multicore_api 347struct perl_multicore_api
323{ 348{
324 void (*pmapi_release)(void); 349 void (*pmapi_release)(void);
325 void (*pmapi_acquire)(void); 350 void (*pmapi_acquire)(void);
326}; 351};
333 = (struct perl_multicore_api *)&perl_multicore_api_init; 358 = (struct perl_multicore_api *)&perl_multicore_api_init;
334 359
335#define perlinterp_release() perl_multicore_api->pmapi_release () 360#define perlinterp_release() perl_multicore_api->pmapi_release ()
336#define perlinterp_acquire() perl_multicore_api->pmapi_acquire () 361#define perlinterp_acquire() perl_multicore_api->pmapi_acquire ()
337 362
363/* this is the release/acquire implementation used as fallback */
338static void 364static void
339perl_multicore_nop (void) 365perl_multicore_nop (void)
340{ 366{
341} 367}
342 368
369/* this is the initial implementation of "release" - it initialises */
370/* the api and then calls the real release function */
343static void 371static void
344perl_multicore_init (void) 372perl_multicore_init (void)
345{ 373{
346 dTHX; 374 dTHX;
347 375
365 /* call the real (or dummy) implementation now */ 393 /* call the real (or dummy) implementation now */
366 perlinterp_release (); 394 perlinterp_release ();
367} 395}
368 396
369#endif 397#endif
398
399#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines