Codebase list libcoro-perl / 23746ca
Merge tag 'upstream/6.370' Upstream version 6.370 Xavier Guimard 10 years ago
30 changed file(s) with 137 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
44 TODO: __GCC_HAVE_DWARF2_CFI_ASM
55 TODO: swap_sv, maybe add scope_swap_sv, andallow to unswap by repeat?
66 TODO: swap_sv not undone in pool
7
8 6.37 Tue Mar 4 13:27:33 CET 2014
9 - *sigh*, removed leftover dbeugging code from debugging a
10 perl bug, of all things.
11
12 6.36 Tue Mar 4 07:11:59 CET 2014
13 - semaphores would not clear the destroy hook when interrupted
14 by ->throw, causing segfaults or worse.
15 - ->throw on a thread waiting for a semaphore did not acquire
16 the semaphore, but also didn't wake up other waiters,
17 possibly causing a deadlock.
18 - "FATAL: $Coro::IDLE blocked itself" will now use Carp::confess
19 to report a full stacktrace, which should help find out
20 where the actual call is.
21 - "atomically" destroy data in slf_destroy, because it is
22 the right thing to do, just in case.
23 - disable ecb.h libm dependency, to compile on ancient systems
24 or under adverse conditions.
725
826 6.33 Mon Nov 18 11:26:27 CET 2013
927 - do not crash when freeing padlists with holes (in 5.18).
6868
6969 use base Exporter::;
7070
71 our $VERSION = 6.33;
71 our $VERSION = 6.37;
7272
7373 our @EXPORT = (@IO::AIO::EXPORT, qw(aio_wait));
7474 our @EXPORT_OK = @IO::AIO::EXPORT_OK;
162162 use Coro;
163163 use AnyEvent ();
164164
165 our $VERSION = 6.33;
165 our $VERSION = 6.37;
166166
167167 #############################################################################
168168 # idle handler
253253
254254 my $long_calc = async {
255255 for (1..10000) {
256 Coro::AnyEvent::poll:
256 Coro::AnyEvent::poll;
257257 # do some stuff, make sure it takes at least 0.001s or so
258258 }
259259 }
4646
4747 use base Exporter::;
4848
49 our $VERSION = 6.33;
49 our $VERSION = 6.37;
5050 our $WATCHER;
5151
5252 BDB::set_sync_prepare {
3434 use Coro ();
3535 use Coro::Semaphore ();
3636
37 our $VERSION = 6.33;
37 our $VERSION = 6.37;
3838
3939 sub DATA (){ 0 }
4040 sub SGET (){ 1 }
119119 use Coro::AnyEvent ();
120120 use Coro::Timer ();
121121
122 our $VERSION = 6.33;
122 our $VERSION = 6.37;
123123
124124 our %log;
125125 our $SESLOGLEVEL = exists $ENV{PERL_CORO_DEFAULT_LOGLEVEL} ? $ENV{PERL_CORO_DEFAULT_LOGLEVEL} : -1;
276276 for my $coro (reverse Coro::State::list) {
277277 my @bt;
278278 Coro::State::call ($coro, sub {
279 # we try to find *the* definite frame that gives msot useful info
279 # we try to find *the* definite frame that gives most useful info
280280 # by skipping Coro frames and pseudo-frames.
281281 for my $frame (1..10) {
282282 my @frame = caller $frame;
4545
4646 use base 'Exporter';
4747
48 our $VERSION = 6.33;
48 our $VERSION = 6.37;
4949 our @EXPORT = qw(unblock);
5050
5151 =item $fh = new_from_fh Coro::Handle $fhandle [, arg => value...]
125125 use Net::FTP ();
126126 use Net::NNTP ();
127127
128 our $VERSION = 6.33;
128 our $VERSION = 6.37;
129129
130130 *Socket::inet_aton = \&Coro::Util::inet_aton;
131131
66
77 our $installsitearch;
88
9 our $VERSION = 6.33;
9 our $VERSION = 6.37;
1010 our @EXPORT_OK = qw(&coro_args $installsitearch);
1111
1212 my %opt;
320320
321321 EOF
322322
323 my $valgrind = prompt ("Enable valgrind support (y/n)?",
324 -r "/usr/include/valgrind/valgrind.h" ? "y" : "n");
323 my $valgrind = -r "/usr/include/valgrind/valgrind.h" ? "y" : "n";
324 $valgrind = $ENV{CORO_USE_VALGRIND} if exists $ENV{CORO_USE_VALGRIND};
325 $valgrind = prompt ("Enable valgrind support (y/n)?", $valgrind);
325326 $DEFINE .= " -DCORO_USE_VALGRIND=1" if $valgrind =~ /[yY]/;
326327
327328
3737
3838 use Coro ();
3939
40 our $VERSION = 6.33;
40 our $VERSION = 6.37;
4141
4242 =item $l = new Coro::RWLock;
4343
6666
6767 use base Exporter::;
6868
69 our $VERSION = 6.33;
69 our $VERSION = 6.37;
7070 our @EXPORT_OK = "select";
7171
7272 sub import {
4141
4242 use Coro ();
4343
44 our $VERSION = 6.33;
44 our $VERSION = 6.37;
4545
4646 =item new [inital count]
4747
5252
5353 =item $sem->count
5454
55 Returns the current semaphore count.
55 Returns the current semaphore count. The semaphore can be down'ed without
56 blocking when the count is strictly higher than C<0>.
5657
5758 =item $sem->adjust ($diff)
5859
6364 =item $sem->down
6465
6566 Decrement the counter, therefore "locking" the semaphore. This method
66 waits until the semaphore is available if the counter is zero.
67 waits until the semaphore is available if the counter is zero or less.
6768
6869 =item $sem->wait
6970
3434
3535 use common::sense;
3636
37 our $VERSION = 6.33;
37 our $VERSION = 6.37;
3838
3939 use Coro::Semaphore ();
4040
3737
3838 use Coro::Semaphore ();
3939
40 our $VERSION = 6.33;
40 our $VERSION = 6.37;
4141
4242 =item $sig = new Coro::Signal;
4343
4848 Wait for the signal to occur (via either C<send> or C<broadcast>). Returns
4949 immediately if the signal has been sent before.
5050
51 =item $sem->wait ($callback)
51 =item $sig->wait ($callback)
5252
5353 If you pass a callback argument to C<wait>, it will not wait, but
5454 immediately return. The callback will be called under the same conditions
7272
7373 use base qw(Coro::Handle IO::Socket::INET);
7474
75 our $VERSION = 6.33;
75 our $VERSION = 6.37;
7676
7777 our (%_proto, %_port);
7878
3535
3636 use common::sense;
3737
38 our $VERSION = 6.33;
38 our $VERSION = 6.37;
3939
4040 =item new
4141
9292 use XSLoader;
9393
9494 BEGIN {
95 our $VERSION = 6.33;
95 our $VERSION = 6.37;
9696
9797 # must be done here because the xs part expects it to exist
9898 # it might exist already because Coro::Specific created it.
389389 =item $old = Coro::State::cctx_stacksize [$new_stacksize]
390390
391391 Returns the current C stack size and optionally sets the new I<minimum>
392 stack size to C<$new_stacksize> I<pointers>s. Existing stacks will not
393 be changed, but Coro will try to replace smaller stacks as soon as
394 possible. Any Coro::State that starts to use a stack after this call is
395 guaranteed this minimum stack size.
392 stack size to C<$new_stacksize> (in units of pointer sizes, i.e. typically
393 4 on 32 bit and 8 on 64 bit hosts). Existing stacks will not be changed,
394 but Coro will try to replace smaller stacks as soon as possible. Any
395 Coro::State that starts to use a stack after this call is guaranteed this
396 minimum stack size.
396397
397398 Please note that coros will only need to use a C-level stack if the
398399 interpreter recurses or calls a function in a module that calls back into
1515 #include "schmorp.h"
1616
1717 #define ECB_NO_THREADS 1
18 #define ECB_NO_LIBM 1
1819 #include "ecb.h"
1920
2021 #include <stddef.h>
19171918 && SvOBJECT (SvRV (sv_idle)))
19181919 {
19191920 if (SvRV (sv_idle) == SvRV (coro_current))
1920 croak ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught");
1921 {
1922 require_pv ("Carp");
1923
1924 {
1925 dSP;
1926
1927 ENTER;
1928 SAVETMPS;
1929
1930 PUSHMARK (SP);
1931 XPUSHs (sv_2mortal (newSVpv ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught", 0)));
1932 PUTBACK;
1933 call_pv ("Carp::confess", G_VOID | G_DISCARD);
1934
1935 FREETMPS;
1936 LEAVE;
1937 }
1938 }
19211939
19221940 ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */
19231941 api_ready (aTHX_ SvRV (sv_idle));
25822600 static void
25832601 slf_destroy (pTHX_ struct coro *coro)
25842602 {
2585 /* this callback is reserved for slf functions needing to do cleanup */
2586 if (coro->slf_frame.destroy && coro->slf_frame.prepare && !PL_dirty)
2587 coro->slf_frame.destroy (aTHX_ &coro->slf_frame);
2603 struct CoroSLF frame = coro->slf_frame;
25882604
25892605 /*
2590 * The on_destroy above most likely is from an SLF call.
2606 * The on_destroy below most likely is from an SLF call.
25912607 * Since by definition the SLF call will not finish when we destroy
25922608 * the coro, we will have to force-finish it here, otherwise
25932609 * cleanup functions cannot call SLF functions.
25942610 */
25952611 coro->slf_frame.prepare = 0;
2612
2613 /* this callback is reserved for slf functions needing to do cleanup */
2614 if (frame.destroy && frame.prepare && !PL_dirty)
2615 frame.destroy (aTHX_ &frame);
25962616 }
25972617
25982618 /*
29422962 SV *count_sv = AvARRAY (av)[0];
29432963 SV *coro_hv = SvRV (coro_current);
29442964
2965 frame->destroy = 0;
2966
29452967 /* if we are about to throw, don't actually acquire the lock, just throw */
2946 if (CORO_THROW)
2947 return 0;
2968 if (ecb_expect_false (CORO_THROW))
2969 {
2970 /* we still might be responsible for the semaphore, so wake up others */
2971 coro_semaphore_adjust (aTHX_ av, 0);
2972
2973 return 0;
2974 }
29482975 else if (SvIVX (count_sv) > 0)
29492976 {
2950 frame->destroy = 0;
2951
29522977 if (acquire)
29532978 SvIVX (count_sv) = SvIVX (count_sv) - 1;
29542979 else
8383 use Storable;
8484 use base "Exporter";
8585
86 our $VERSION = 6.33;
86 our $VERSION = 6.37;
8787 our @EXPORT = qw(thaw freeze nfreeze blocking_thaw blocking_freeze blocking_nfreeze);
8888
8989 our $GRANULARITY = 0.01;
2727 use Coro ();
2828 use Coro::AnyEvent ();
2929
30 our $VERSION = 6.33;
30 our $VERSION = 6.37;
3131 our @EXPORT_OK = qw(timeout sleep);
3232
3333 # compatibility with older programs
4040 our @EXPORT = qw(gethostbyname gethostbyaddr);
4141 our @EXPORT_OK = qw(inet_aton fork_eval);
4242
43 our $VERSION = 6.33;
43 our $VERSION = 6.37;
4444
4545 our $MAXPARALLEL = 16; # max. number of parallel jobs
4646
6565 #endif
6666
6767 /* work around x32 idiocy by defining proper macros */
68 #if __x86_64 || _M_AMD64
68 #if __amd64 || __x86_64 || _M_AMD64 || _M_X64
6969 #if _ILP32
7070 #define ECB_AMD64_X32 1
7171 #else
8888 #endif
8989 #endif
9090
91 #define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */
92 #define ECB_C99 (__STDC_VERSION__ >= 199901L)
93 #define ECB_C11 (__STDC_VERSION__ >= 201112L)
9491 #define ECB_CPP (__cplusplus+0)
9592 #define ECB_CPP11 (__cplusplus >= 201103L)
93
94 #if ECB_CPP
95 #define ECB_C 0
96 #define ECB_STDC_VERSION 0
97 #else
98 #define ECB_C 1
99 #define ECB_STDC_VERSION __STDC_VERSION__
100 #endif
101
102 #define ECB_C99 (ECB_STDC_VERSION >= 199901L)
103 #define ECB_C11 (ECB_STDC_VERSION >= 201112L)
96104
97105 #if ECB_CPP
98106 #define ECB_EXTERN_C extern "C"
135143 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \
136144 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__
137145 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
138 #elif __sparc || __sparc__
146 #elif (__sparc || __sparc__) && !__sparcv8
139147 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory")
140148 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
141149 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
166174 #if ECB_GCC_VERSION(4,7)
167175 /* see comment below (stdatomic.h) about the C11 memory model. */
168176 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
177 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
178 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE)
169179
170180 /* The __has_feature syntax from clang is so misdesigned that we cannot use it
171181 * without risking compile time errors with other compilers. We *could*
174184 * #elif defined __clang && __has_feature (cxx_atomic)
175185 * // see comment below (stdatomic.h) about the C11 memory model.
176186 * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
187 * #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
188 * #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE)
177189 */
178190
179191 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
180192 #define ECB_MEMORY_FENCE __sync_synchronize ()
193 #elif _MSC_VER >= 1500 /* VC++ 2008 */
194 /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */
195 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
196 #define ECB_MEMORY_FENCE _ReadWriteBarrier (); MemoryBarrier()
197 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier (); MemoryBarrier() /* according to msdn, _ReadBarrier is not a load fence */
198 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier (); MemoryBarrier()
181199 #elif _MSC_VER >= 1400 /* VC++ 2005 */
182200 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
183201 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
207225 /* for most usages, or gcc and clang have a bug */
208226 /* I *currently* lean towards the latter, and inefficiently implement */
209227 /* all three of ecb's fences as a seq_cst fence */
228 /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */
229 /* for all __atomic_thread_fence's except seq_cst */
210230 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst)
211231 #endif
212232 #endif
273293 #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality)
274294 #else
275295 #define ecb_attribute(attrlist)
296
297 /* possible C11 impl for integral types
298 typedef struct ecb_is_constant_struct ecb_is_constant_struct;
299 #define ecb_is_constant(expr) _Generic ((1 ? (struct ecb_is_constant_struct *)0 : (void *)((expr) - (expr)), ecb_is_constant_struct *: 0, default: 1)) */
300
276301 #define ecb_is_constant(expr) 0
277302 #define ecb_expect(expr,value) (expr)
278303 #define ecb_prefetch(addr,rw,locality)
367367 our $main; # main coro
368368 our $current; # current coro
369369
370 our $VERSION = 6.33;
370 our $VERSION = 6.37;
371371
372372 our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait);
373373 our %EXPORT_TAGS = (
653653 $SIG{VTALRM} = sub { cede };
654654 # and then start the interval timer
655655 Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0.01, 0.01;
656 };
656 };
657657 Coro::on_leave {
658658 # on leaving the thread, we stop the interval timer again
659659 Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0, 0;
660 };
660 };
661661
662662 &{+shift};
663 }
663 }
664664
665665 # use like this:
666666 timeslice {
668668 # monopolise the process. Since it runs in a timesliced
669669 # environment, it will regularly cede to other threads.
670670 while () { }
671 };
671 };
672672
673673
674674 =item killall
915915 not> die, under any circumstances.
916916
917917 There can be any number of C<on_destroy> callbacks per coro, and there is
918 no way currently to remove a callback once added.
918 currently no way to remove a callback once added.
919919
920920 =item $oldprio = $coro->prio ($newprio)
921921
5959 use XSLoader;
6060
6161 BEGIN {
62 our $VERSION = 6.33;
62 our $VERSION = 6.37;
6363
6464 local $^W = 0; # avoid redefine warning for Coro::ready;
6565 XSLoader::load __PACKAGE__, $VERSION;
9191 our @EXPORT = qw(loop unloop sweep);
9292
9393 BEGIN {
94 our $VERSION = 6.33;
94 our $VERSION = 6.37;
9595
9696 local $^W = 0; # avoid redefine warning for Coro::ready;
9797 XSLoader::load __PACKAGE__, $VERSION;
33 "unknown"
44 ],
55 "dynamic_config" : 1,
6 "generated_by" : "ExtUtils::MakeMaker version 6.8, CPAN::Meta::Converter version 2.120921",
6 "generated_by" : "ExtUtils::MakeMaker version 6.86, CPAN::Meta::Converter version 2.133380",
77 "license" : [
88 "unknown"
99 ],
4949 }
5050 },
5151 "release_status" : "stable",
52 "version" : "6.33"
52 "version" : "6.37"
5353 }
66 configure_requires:
77 ExtUtils::MakeMaker: 0
88 dynamic_config: 1
9 generated_by: 'ExtUtils::MakeMaker version 6.8, CPAN::Meta::Converter version 2.120921'
9 generated_by: 'ExtUtils::MakeMaker version 6.86, CPAN::Meta::Converter version 2.133380'
1010 license: unknown
1111 meta-spec:
1212 url: http://module-build.sourceforge.net/META-spec-v1.4.html
3030 Scalar::Util: 0
3131 Storable: 2.15
3232 common::sense: 0
33 version: 6.33
33 version: 6.37
550550 $SIG{VTALRM} = sub { cede };
551551 # and then start the interval timer
552552 Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0.01, 0.01;
553 };
553 };
554554 Coro::on_leave {
555555 # on leaving the thread, we stop the interval timer again
556556 Time::HiRes::setitimer &Time::HiRes::ITIMER_VIRTUAL, 0, 0;
557 };
557 };
558558
559559 &{+shift};
560 }
560 }
561561
562562 # use like this:
563563 timeslice {
779779 arguments, if any, and *must not* die, under any circumstances.
780780
781781 There can be any number of "on_destroy" callbacks per coro, and
782 there is no way currently to remove a callback once added.
782 there is currently no way to remove a callback once added.
783783
784784 $oldprio = $coro->prio ($newprio)
785785 Sets (or gets, if the argument is missing) the priority of the coro
4040 $as1 = async {
4141 my $g = $sem->guard;
4242 print "not ok 2\n";
43 };
43 };
4444
4545 $as2 = async {
4646 my $g = $sem->guard;
4747 print "ok 2\n";
48 };
48 };
4949
5050 cede;
5151
6464 $sem->guard;
6565 };
6666 print $@ ? "" : "not ", "ok 3\n";
67 };
67 };
6868
6969 $as2 = async {
7070 my $g = $sem->guard;
7171 print "ok 4\n";
72 };
72 };
7373
7474 cede;
7575
8686 $as1 = async {
8787 $sem->wait;
8888 print "ok 5\n";
89 };
89 };
9090
9191 $as2 = async {
9292 my $g = $sem->guard;
9393 print "ok 6\n";
94 };
94 };
9595
9696 cede;
9797