… | |
… | |
2040 | slf_check_semaphore_down (pTHX_ struct CoroSLF *frame) |
2040 | slf_check_semaphore_down (pTHX_ struct CoroSLF *frame) |
2041 | { |
2041 | { |
2042 | AV *av = (AV *)frame->data; |
2042 | AV *av = (AV *)frame->data; |
2043 | SV *count_sv = AvARRAY (av)[0]; |
2043 | SV *count_sv = AvARRAY (av)[0]; |
2044 | |
2044 | |
|
|
2045 | /* if we are about to throw, don't actually acquire the lock, just throw */ |
|
|
2046 | if (coro_throw && 0)//D |
|
|
2047 | return 0; |
2045 | if (SvIVX (count_sv) > 0) |
2048 | else if (SvIVX (count_sv) > 0) |
2046 | { |
2049 | { |
2047 | SvSTATE_current->on_destroy = 0; |
2050 | SvSTATE_current->on_destroy = 0; |
2048 | SvIVX (count_sv) = SvIVX (count_sv) - 1; |
2051 | SvIVX (count_sv) = SvIVX (count_sv) - 1; |
2049 | return 0; |
2052 | return 0; |
2050 | } |
2053 | } |
… | |
… | |
2071 | |
2074 | |
2072 | if (SvIVX (AvARRAY (av)[0]) > 0) |
2075 | if (SvIVX (AvARRAY (av)[0]) > 0) |
2073 | { |
2076 | { |
2074 | frame->data = (void *)av; |
2077 | frame->data = (void *)av; |
2075 | frame->prepare = prepare_nop; |
2078 | frame->prepare = prepare_nop; |
2076 | SvSTATE_current->on_destroy = coro_semaphore_on_destroy; |
|
|
2077 | } |
2079 | } |
2078 | else |
2080 | else |
2079 | { |
2081 | { |
2080 | av_push (av, SvREFCNT_inc (SvRV (coro_current))); |
2082 | av_push (av, SvREFCNT_inc (SvRV (coro_current))); |
2081 | |
2083 | |
2082 | frame->data = (void *)sv_2mortal (SvREFCNT_inc ((SV *)av)); |
2084 | frame->data = (void *)sv_2mortal (SvREFCNT_inc ((SV *)av)); |
2083 | frame->prepare = prepare_schedule; |
2085 | frame->prepare = prepare_schedule; |
2084 | |
2086 | |
2085 | /* to avoid race conditions when a woken-up coro gets terminated */ |
2087 | /* to avoid race conditions when a woken-up coro gets terminated */ |
2086 | /* we arrange for a temporary on_destroy that calls adjust (0) */ |
2088 | /* we arrange for a temporary on_destroy that calls adjust (0) */ |
2087 | assert (!SvSTATE_current->on_destroy);//D |
|
|
2088 | SvSTATE_current->on_destroy = coro_semaphore_on_destroy; |
2089 | SvSTATE_current->on_destroy = coro_semaphore_on_destroy; |
2089 | } |
2090 | } |
2090 | |
2091 | |
2091 | frame->check = slf_check_semaphore_down; |
2092 | frame->check = slf_check_semaphore_down; |
2092 | |
2093 | |