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

Comparing Coro-Multicore/perlmulticore.h (file contents):
Revision 1.4 by root, Sat Jun 27 19:47:45 2015 UTC vs.
Revision 1.6 by root, Sun Jun 28 18:30:48 2015 UTC

6 6
7#ifndef PERL_MULTICORE_H 7#ifndef PERL_MULTICORE_H
8#define PERL_MULTICORE_H 8#define PERL_MULTICORE_H
9 9
10/* 10/*
11
11=head1 NAME 12=head1 NAME
12 13
13perlmulticore.h - release the perl interpreter for other uses while doing hard work 14perlmulticore.h - the Perl Multicore Specification and Implementation
14 15
15=head1 SYNOPSIS 16=head1 SYNOPSIS
16 17
17 #include "perlmultiore.h" 18 #include "perlmultiore.h"
18 19
33applicability. 34applicability.
34 35
35The newest version of this document can be found at 36The newest version of this document can be found at
36L<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>.
37 38
38The nwest version of the header fgile itself, which 39The newest version of the header file itself, which
39includes this documentation, can be downloaded from 40includes this documentation, can be downloaded from
40L<http://cvs.schmorp.de/Coro-Multicore/perlmulticore.h>. 41L<http://cvs.schmorp.de/Coro-Multicore/perlmulticore.h>.
41 42
42=head1 HOW DO I USE THIS IN MY MODULES? 43=head1 HOW DO I USE THIS IN MY MODULES?
43 44
117 if (res) 118 if (res)
118 { 119 {
119 // 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
120 perlinterp_release (); 121 perlinterp_release ();
121 res = fcntl (fd, F_SETLKW, &flock); 122 res = fcntl (fd, F_SETLKW, &flock);
122 perlinterp_release (); 123 perlinterp_acquire ();
123 } 124 }
124 125
125=head1 THE HARD AND FAST RULES 126=head1 THE HARD AND FAST RULES
126 127
127As with everything, there are a number of rules to follow. 128As with everything, there are a number of rules to follow.
197 pthread_mutex_lock (&my_mutex); 198 pthread_mutex_lock (&my_mutex);
198 do_your_non_thread_safe_thing (); 199 do_your_non_thread_safe_thing ();
199 pthread_mutex_unlock (&my_mutex); 200 pthread_mutex_unlock (&my_mutex);
200 perlinterp_acquire (); 201 perlinterp_acquire ();
201 202
202This isn't as trivial as it looks though, as you need to find out which
203threading system is in use (with L<Coro::Multicore>, it currently is
204always pthreads).
205
206=item I<Don't> get confused by having to release first. 203=item I<Don't> get confused by having to release first.
207 204
208In many real world scenarios, you acquire a resource, do something, then 205In many real world scenarios, you acquire a resource, do something, then
209release 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
210the 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
306=back 303=back
307 304
308=head1 AUTHOR 305=head1 AUTHOR
309 306
310 Marc A. Lehmann <perlmulticore@schmorp.de> 307 Marc A. Lehmann <perlmulticore@schmorp.de>
308 http://perlmulticore.schmorp.de/
311 309
312=head1 LICENSE 310=head1 LICENSE
313 311
314The F<perlmulticore.h> is put into the public domain. Where this is legally 312The F<perlmulticore.h> header file is put into the public
313domain. Where this is legally not possible, or at your
315not possible, or at your option, it can be licensed under creativecommons 314option, it can be licensed under creativecommons CC0
316CC0 license: L<https://creativecommons.org/publicdomain/zero/1.0/>. 315license: L<https://creativecommons.org/publicdomain/zero/1.0/>.
317 316
318=cut 317=cut
318
319*/ 319*/
320 320
321/* this struct is shared between all modules, and currently */
322/* contain only the two function pointers for release/acquire */
321struct perl_multicore_api 323struct perl_multicore_api
322{ 324{
323 void (*pmapi_release)(void); 325 void (*pmapi_release)(void);
324 void (*pmapi_acquire)(void); 326 void (*pmapi_acquire)(void);
325}; 327};
332 = (struct perl_multicore_api *)&perl_multicore_api_init; 334 = (struct perl_multicore_api *)&perl_multicore_api_init;
333 335
334#define perlinterp_release() perl_multicore_api->pmapi_release () 336#define perlinterp_release() perl_multicore_api->pmapi_release ()
335#define perlinterp_acquire() perl_multicore_api->pmapi_acquire () 337#define perlinterp_acquire() perl_multicore_api->pmapi_acquire ()
336 338
339/* this is the release/acquire implementation used as fallback */
337static void 340static void
338perl_multicore_nop (void) 341perl_multicore_nop (void)
339{ 342{
340} 343}
341 344
345/* this is the initial implementation of "release" - it initialises */
346/* the api and then calls the real release function */
342static void 347static void
343perl_multicore_init (void) 348perl_multicore_init (void)
344{ 349{
345 dTHX; 350 dTHX;
346 351

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines