• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

krakjoe / parallel / 20316825147

17 Dec 2025 08:49PM UTC coverage: 94.99% (+4.1%) from 90.94%
20316825147

push

github

realFlowControl
fix build

2844 of 2994 relevant lines covered (94.99%)

6435.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.18
/src/runtime.c
1
/*
2
  +----------------------------------------------------------------------+
3
  | parallel                                                             |
4
  +----------------------------------------------------------------------+
5
  | Copyright (c) Joe Watkins 2019-2024                                  |
6
  +----------------------------------------------------------------------+
7
  | This source file is subject to version 3.01 of the PHP license,      |
8
  | that is bundled with this package in the file LICENSE, and is        |
9
  | available through the world-wide-web at the following url:           |
10
  | http://www.php.net/license/3_01.txt                                  |
11
  | If you did not receive a copy of the PHP license and are unable to   |
12
  | obtain it through the world-wide-web, please send a note to          |
13
  | license@php.net so we can mail you a copy immediately.               |
14
  +----------------------------------------------------------------------+
15
  | Author: krakjoe                                                      |
16
  +----------------------------------------------------------------------+
17
 */
18
#ifndef HAVE_PARALLEL_RUNTIME
19
#define HAVE_PARALLEL_RUNTIME
20

21
#include "parallel.h"
22

23
zend_class_entry       *php_parallel_runtime_ce;
24
zend_object_handlers    php_parallel_runtime_handlers;
25

26
php_parallel_runtime_t *php_parallel_runtime_construct(zend_string *bootstrap)
492✔
27
{
28
        zval                    rt;
492✔
29
        php_parallel_runtime_t *runtime;
492✔
30

31
        object_init_ex(&rt, php_parallel_runtime_ce);
492✔
32

33
        runtime = php_parallel_runtime_from(&rt);
492✔
34

35
        php_parallel_scheduler_start(runtime, bootstrap);
492✔
36

37
        if (!EG(exception)) {
492✔
38
                return runtime;
39
        }
40

41
        zval_ptr_dtor(&rt);
×
42
        return NULL;
×
43
}
44

45
ZEND_BEGIN_ARG_INFO_EX(php_parallel_runtime_construct_arginfo, 0, 0, 0)
46
ZEND_ARG_TYPE_INFO(0, bootstrap, IS_STRING, 0)
47
ZEND_END_ARG_INFO()
48

49
PHP_METHOD(Parallel_Runtime, __construct)
1,710✔
50
{
51
        php_parallel_runtime_t *runtime = php_parallel_runtime_from(getThis());
1,710✔
52
        zend_string            *bootstrap = NULL;
1,710✔
53

54
        ZEND_PARSE_PARAMETERS_START(0, 1)
1,710✔
55
        Z_PARAM_OPTIONAL
1,710✔
56
        Z_PARAM_STR(bootstrap)
1,980✔
57
        ZEND_PARSE_PARAMETERS_END();
1,710✔
58

59
        php_parallel_scheduler_start(runtime, bootstrap);
1,710✔
60
}
61

62
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(php_parallel_runtime_run_arginfo, 0, 1, \\parallel\\Future, 1)
63
ZEND_ARG_OBJ_INFO(0, task, Closure, 0)
64
ZEND_ARG_TYPE_INFO(0, argv, IS_ARRAY, 0)
65
ZEND_END_ARG_INFO()
66

67
PHP_METHOD(Parallel_Runtime, run)
2,076✔
68
{
69
        php_parallel_runtime_t *runtime = php_parallel_runtime_from(getThis());
2,076✔
70
        zval                   *closure = NULL;
2,076✔
71
        zval                   *argv = NULL;
2,076✔
72

73
        ZEND_PARSE_PARAMETERS_START(1, 2)
2,076✔
74
        Z_PARAM_OBJECT_OF_CLASS(closure, zend_ce_closure)
4,152✔
75
        Z_PARAM_OPTIONAL
2,076✔
76
        Z_PARAM_ARRAY(argv)
2,778✔
77
        ZEND_PARSE_PARAMETERS_END();
2,076✔
78

79
        if (php_parallel_monitor_check(runtime->monitor, PHP_PARALLEL_CLOSED) ||
4,134✔
80
            php_parallel_monitor_check(runtime->monitor, PHP_PARALLEL_DONE)) {
2,058✔
81
                php_parallel_exception_ex(php_parallel_runtime_error_closed_ce, "Runtime closed");
18✔
82
                return;
18✔
83
        }
84

85
        php_parallel_scheduler_push(runtime, closure, argv, return_value);
2,058✔
86
}
87

88
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(php_parallel_runtime_close_or_kill_arginfo, 0, 0, IS_VOID, 0)
89
ZEND_END_ARG_INFO()
90

91
PHP_METHOD(Parallel_Runtime, close)
114✔
92
{
93
        php_parallel_runtime_t *runtime = php_parallel_runtime_from(getThis());
114✔
94

95
        PARALLEL_PARAMETERS_NONE(return);
114✔
96

97
        php_parallel_scheduler_join(runtime, 0);
114✔
98
}
99

100
PHP_METHOD(Parallel_Runtime, kill)
72✔
101
{
102
        php_parallel_runtime_t *runtime = php_parallel_runtime_from(getThis());
72✔
103

104
        PARALLEL_PARAMETERS_NONE(return);
72✔
105

106
        php_parallel_scheduler_join(runtime, 1);
72✔
107
}
108

109
zend_function_entry php_parallel_runtime_methods[] = {
110
    PHP_ME(Parallel_Runtime, __construct, php_parallel_runtime_construct_arginfo, ZEND_ACC_PUBLIC)
111
        PHP_ME(Parallel_Runtime, run, php_parallel_runtime_run_arginfo, ZEND_ACC_PUBLIC)
112
            PHP_ME(Parallel_Runtime, close, php_parallel_runtime_close_or_kill_arginfo, ZEND_ACC_PUBLIC)
113
                PHP_ME(Parallel_Runtime, kill, php_parallel_runtime_close_or_kill_arginfo, ZEND_ACC_PUBLIC) PHP_FE_END};
114

115
zend_object *php_parallel_runtime_create(zend_class_entry *type)
2,202✔
116
{
117
        php_parallel_runtime_t *runtime = ecalloc(1, sizeof(php_parallel_runtime_t) + zend_object_properties_size(type));
2,202✔
118

119
        zend_object_std_init(&runtime->std, type);
2,202✔
120

121
        runtime->std.handlers = &php_parallel_runtime_handlers;
2,202✔
122

123
        php_parallel_scheduler_init(runtime);
2,202✔
124

125
        runtime->parent.server = SG(server_context);
2,202✔
126
        runtime->parent.argc = SG(request_info).argc;
2,202✔
127
        runtime->parent.argv = SG(request_info).argv;
2,202✔
128

129
        return &runtime->std;
2,202✔
130
}
131

132
void php_parallel_runtime_destroy(zend_object *o)
2,202✔
133
{
134
        php_parallel_runtime_t *runtime = php_parallel_runtime_fetch(o);
2,202✔
135

136
        php_parallel_scheduler_stop(runtime);
2,202✔
137

138
        php_parallel_scheduler_destroy(runtime);
2,202✔
139

140
        zend_object_std_dtor(o);
2,202✔
141
}
2,202✔
142

143
PHP_MINIT_FUNCTION(PARALLEL_RUNTIME)
3,210✔
144
{
145
        zend_class_entry ce;
3,210✔
146

147
        memcpy(&php_parallel_runtime_handlers, php_parallel_standard_handlers(), sizeof(zend_object_handlers));
3,210✔
148

149
        php_parallel_runtime_handlers.offset = XtOffsetOf(php_parallel_runtime_t, std);
3,210✔
150
        php_parallel_runtime_handlers.free_obj = php_parallel_runtime_destroy;
3,210✔
151

152
        INIT_NS_CLASS_ENTRY(ce, "parallel", "Runtime", php_parallel_runtime_methods);
3,210✔
153

154
        php_parallel_runtime_ce = zend_register_internal_class(&ce);
3,210✔
155
        php_parallel_runtime_ce->create_object = php_parallel_runtime_create;
3,210✔
156
        php_parallel_runtime_ce->ce_flags |= ZEND_ACC_FINAL;
3,210✔
157

158
#ifdef ZEND_ACC_NOT_SERIALIZABLE
159
        php_parallel_runtime_ce->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
2,360✔
160
#else
161
        php_parallel_runtime_ce->serialize = zend_class_serialize_deny;
850✔
162
        php_parallel_runtime_ce->unserialize = zend_class_unserialize_deny;
850✔
163
#endif
164

165
        PHP_MINIT(PARALLEL_FUTURE)(INIT_FUNC_ARGS_PASSTHRU);
3,210✔
166

167
        return SUCCESS;
3,210✔
168
}
169

170
PHP_MSHUTDOWN_FUNCTION(PARALLEL_RUNTIME)
3,210✔
171
{
172
        PHP_MSHUTDOWN(PARALLEL_FUTURE)(INIT_FUNC_ARGS_PASSTHRU);
3,210✔
173

174
        return SUCCESS;
3,210✔
175
}
176
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc