-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscope.h
More file actions
91 lines (74 loc) · 3.08 KB
/
scope.h
File metadata and controls
91 lines (74 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Edmond |
+----------------------------------------------------------------------+
*/
#ifndef SCOPE_H
#define SCOPE_H
#include "php_async.h"
PHP_ASYNC_API extern zend_class_entry *async_ce_scope;
PHP_ASYNC_API extern zend_class_entry *async_ce_scope_provider;
PHP_ASYNC_API extern zend_class_entry *async_ce_spawn_strategy;
#define ASYNC_SCOPE_MAX_RECURSION_DEPTH 64
typedef struct _async_scope_s async_scope_t;
typedef struct async_coroutines_vector_t
{
uint32_t length; /* current number of items */
uint32_t capacity; /* allocated slots in the array */
async_coroutine_t **data; /* dynamically allocated array */
} async_coroutines_vector_t;
struct _async_scope_s
{
zend_async_scope_t scope;
async_coroutines_vector_t coroutines;
uint32_t active_coroutines_count; /* Number of active (non-zombie) coroutines */
uint32_t zombie_coroutines_count; /* Number of zombie coroutines */
/* Spawned file and line number */
zend_string *filename;
uint32_t lineno;
/* Exception handlers */
zend_fcall_info *exception_fci;
zend_fcall_info_cache *exception_fcc;
zend_fcall_info *child_exception_fci;
zend_fcall_info_cache *child_exception_fcc;
/* Finally handlers array (zval callables) - lazy initialization */
HashTable *finally_handlers;
};
typedef struct _async_scope_object_s
{
union
{
/* PHP object handle. */
zend_object std;
struct
{
char _padding[sizeof(zend_object) - sizeof(zval)];
async_scope_t *scope;
bool is_cancelled; /* Indicates if the scope is cancelled */
};
};
} async_scope_object_t;
typedef struct
{
zend_coroutine_event_callback_t callback;
zend_fcall_info *error_fci;
zend_fcall_info_cache *error_fci_cache;
} scope_coroutine_callback_t;
zend_async_scope_t *async_new_scope(zend_async_scope_t *parent_scope, const bool with_zend_object);
void async_register_scope_ce(void);
/* Check if coroutine belongs to this scope or any of its child scopes */
bool async_scope_contains_coroutine(async_scope_t *scope, zend_coroutine_t *coroutine, uint32_t depth);
void async_scope_notify_coroutine_finished(async_coroutine_t *coroutine);
/* Mark coroutine as zombie and update active count */
void async_scope_mark_coroutine_zombie(async_coroutine_t *coroutine);
#endif // SCOPE_H