27
27
#include " zend_builtin_functions.h"
28
28
#include " ext/spl/spl_array.h"
29
29
30
- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
31
30
#include " zend_observer.h"
32
- #endif
33
31
34
32
#include < unordered_map>
35
33
#include < chrono>
@@ -45,17 +43,6 @@ using swoole::PHPCoroutine;
45
43
using swoole::coroutine::Socket;
46
44
using swoole::coroutine::System;
47
45
48
- #if PHP_VERSION_ID < 80100
49
- static zend_always_inline zend_vm_stack zend_vm_stack_new_page (size_t size, zend_vm_stack prev) {
50
- zend_vm_stack page = (zend_vm_stack) emalloc (size);
51
-
52
- page->top = ZEND_VM_STACK_ELEMENTS (page);
53
- page->end = (zval *) ((char *) page + size);
54
- page->prev = prev;
55
- return page;
56
- }
57
- #endif
58
-
59
46
enum sw_exit_flags { SW_EXIT_IN_COROUTINE = 1 << 1 , SW_EXIT_IN_SERVER = 1 << 2 };
60
47
61
48
SW_THREAD_LOCAL bool PHPCoroutine::activated = false ;
@@ -302,9 +289,6 @@ static void coro_interrupt_function(zend_execute_data *execute_data) {
302
289
PHPContext *PHPCoroutine::create_context (Args *args) {
303
290
PHPContext *ctx = (PHPContext *) emalloc (sizeof (PHPContext));
304
291
ctx->output_ptr = nullptr ;
305
- #if PHP_VERSION_ID < 80100
306
- ctx->array_walk_fci = nullptr ;
307
- #endif
308
292
ctx->in_silence = false ;
309
293
310
294
ctx->co = Coroutine::get_current ();
@@ -317,10 +301,8 @@ PHPContext *PHPCoroutine::create_context(Args *args) {
317
301
ctx->on_close = nullptr ;
318
302
ctx->enable_scheduler = true ;
319
303
320
- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
321
304
fiber_context_try_init (ctx);
322
305
ctx->fiber_init_notified = false ;
323
- #endif
324
306
325
307
EG (vm_stack) = zend_vm_stack_new_page (SW_DEFAULT_PHP_STACK_PAGE_SIZE, nullptr );
326
308
EG (vm_stack_top) = EG (vm_stack)->top + ZEND_CALL_FRAME_SLOT;
@@ -522,15 +504,6 @@ inline void PHPCoroutine::save_vm_stack(PHPContext *ctx) {
522
504
ctx->error_handling = EG (error_handling);
523
505
ctx->exception_class = EG (exception_class);
524
506
ctx->exception = EG (exception);
525
- #if PHP_VERSION_ID < 80100
526
- if (UNEXPECTED (BG (array_walk_fci).size != 0 )) {
527
- if (!ctx->array_walk_fci ) {
528
- ctx->array_walk_fci = (zend::Function *) emalloc (sizeof (*ctx->array_walk_fci ));
529
- }
530
- memcpy (ctx->array_walk_fci , &BG (array_walk_fci), sizeof (*ctx->array_walk_fci ));
531
- memset (&BG (array_walk_fci), 0 , sizeof (*ctx->array_walk_fci ));
532
- }
533
- #endif
534
507
if (UNEXPECTED (ctx->in_silence )) {
535
508
ctx->tmp_error_reporting = EG (error_reporting);
536
509
EG (error_reporting) = ctx->ori_error_reporting ;
@@ -552,12 +525,6 @@ inline void PHPCoroutine::restore_vm_stack(PHPContext *ctx) {
552
525
EG (error_handling) = ctx->error_handling ;
553
526
EG (exception_class) = ctx->exception_class ;
554
527
EG (exception) = ctx->exception ;
555
- #if PHP_VERSION_ID < 80100
556
- if (UNEXPECTED (ctx->array_walk_fci && ctx->array_walk_fci ->fci .size != 0 )) {
557
- memcpy (&BG (array_walk_fci), ctx->array_walk_fci , sizeof (*ctx->array_walk_fci ));
558
- ctx->array_walk_fci ->fci .size = 0 ;
559
- }
560
- #endif
561
528
if (UNEXPECTED (ctx->in_silence )) {
562
529
EG (error_reporting) = ctx->tmp_error_reporting ;
563
530
}
@@ -614,9 +581,7 @@ void PHPCoroutine::on_yield(void *arg) {
614
581
PHPContext *ctx = (PHPContext *) arg;
615
582
PHPContext *origin_ctx = get_origin_context (ctx);
616
583
617
- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
618
584
fiber_context_switch_try_notify (ctx, origin_ctx);
619
- #endif
620
585
save_context (ctx);
621
586
restore_context (origin_ctx);
622
587
@@ -631,9 +596,7 @@ void PHPCoroutine::on_resume(void *arg) {
631
596
PHPContext *ctx = (PHPContext *) arg;
632
597
PHPContext *current_ctx = get_context ();
633
598
634
- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
635
599
fiber_context_switch_try_notify (current_ctx, ctx);
636
- #endif
637
600
save_context (current_ctx);
638
601
restore_context (ctx);
639
602
record_last_msec (ctx);
@@ -676,11 +639,6 @@ void PHPCoroutine::destroy_context(PHPContext *ctx) {
676
639
php_output_activate ();
677
640
SG (request_info).no_headers = no_headers;
678
641
}
679
- #if PHP_VERSION_ID < 80100
680
- if (ctx->array_walk_fci ) {
681
- efree (ctx->array_walk_fci );
682
- }
683
- #endif
684
642
685
643
if (ctx->defer_tasks ) {
686
644
while (!ctx->defer_tasks ->empty ()) {
@@ -706,10 +664,8 @@ void PHPCoroutine::destroy_context(PHPContext *ctx) {
706
664
707
665
Z_TRY_DELREF (ctx->return_value );
708
666
709
- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
710
667
fiber_context_switch_try_notify (ctx, origin_ctx);
711
668
fiber_context_try_destroy (ctx);
712
- #endif
713
669
714
670
swoole_trace_log (SW_TRACE_COROUTINE,
715
671
" coro close cid=%ld and resume to %ld, %zu remained. usage size: %zu. malloc size: %zu" ,
@@ -740,8 +696,7 @@ void PHPCoroutine::main_func(void *_args) {
740
696
swoole_call_hook (SW_GLOBAL_HOOK_ON_CORO_START, ctx);
741
697
}
742
698
743
- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
744
- if (EXPECTED (SWOOLE_G (enable_fiber_mock) && ctx->fci_cache .function_handler ->type == ZEND_USER_FUNCTION)) {
699
+ if (UNEXPECTED (SWOOLE_G (enable_fiber_mock) && ctx->fci_cache .function_handler ->type == ZEND_USER_FUNCTION)) {
745
700
zend_execute_data *tmp = EG (current_execute_data);
746
701
zend_execute_data call = {};
747
702
EG (current_execute_data) = &call;
@@ -750,7 +705,7 @@ void PHPCoroutine::main_func(void *_args) {
750
705
fiber_context_switch_try_notify (get_origin_context (ctx), ctx);
751
706
EG (current_execute_data) = tmp;
752
707
}
753
- # endif
708
+
754
709
zend_call_function (&ctx->fci , &ctx->fci_cache );
755
710
756
711
// Catch exception in main function of the coroutine
@@ -828,8 +783,6 @@ void PHPCoroutine::defer(zend::Function *fci) {
828
783
ctx->defer_tasks ->push (fci);
829
784
}
830
785
831
- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
832
-
833
786
void PHPCoroutine::fiber_context_init (PHPContext *ctx) {
834
787
zend_fiber_context *fiber_context = (zend_fiber_context *) emalloc (sizeof (*fiber_context));
835
788
fiber_context->handle = (void *) -1 ;
@@ -907,7 +860,6 @@ void PHPCoroutine::fiber_context_switch_try_notify(PHPContext *from, PHPContext
907
860
}
908
861
fiber_context_switch_notify (from, to);
909
862
}
910
- #endif /* SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT */
911
863
912
864
#ifdef ZEND_CHECK_STACK_LIMIT
913
865
void *PHPCoroutine::stack_limit (PHPContext *ctx) {
0 commit comments