• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

krakjoe / parallel / 20284038403

16 Dec 2025 09:59PM UTC coverage: 96.75% (-0.07%) from 96.815%
20284038403

Pull #357

github

web-flow
Merge 108da3aef into 14042a874
Pull Request #357: Cleanup code formatting and docs

2672 of 2765 new or added lines in 27 files covered. (96.64%)

1 existing line in 1 file now uncovered.

2798 of 2892 relevant lines covered (96.75%)

6636.75 hits per line

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

97.14
/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)
486✔
27
{
28
        zval                    rt;
486✔
29
        php_parallel_runtime_t *runtime;
486✔
30

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

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

35
        php_parallel_scheduler_start(runtime, bootstrap);
486✔
36

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

NEW
41
        zval_ptr_dtor(&rt);
×
NEW
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,698✔
50
{
51
        php_parallel_runtime_t *runtime = php_parallel_runtime_from(getThis());
1,698✔
52
        zend_string            *bootstrap = NULL;
1,698✔
53

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

59
        php_parallel_scheduler_start(runtime, bootstrap);
1,698✔
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,064✔
68
{
69
        php_parallel_runtime_t *runtime = php_parallel_runtime_from(getThis());
2,064✔
70
        zval                   *closure = NULL;
2,064✔
71
        zval                   *argv = NULL;
2,064✔
72

73
        ZEND_PARSE_PARAMETERS_START(1, 2)
2,064✔
74
        Z_PARAM_OBJECT_OF_CLASS(closure, zend_ce_closure)
4,128✔
75
        Z_PARAM_OPTIONAL
2,064✔
76
        Z_PARAM_ARRAY(argv)
2,766✔
77
        ZEND_PARSE_PARAMETERS_END();
2,064✔
78

79
        if (php_parallel_monitor_check(runtime->monitor, PHP_PARALLEL_CLOSED)) {
2,064✔
80
                php_parallel_exception_ex(php_parallel_runtime_error_closed_ce, "Runtime closed");
18✔
81
                return;
18✔
82
        }
83

84
        php_parallel_scheduler_push(runtime, closure, argv, return_value);
2,046✔
85
}
86

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

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

94
        PARALLEL_PARAMETERS_NONE(return);
114✔
95

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

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

103
        PARALLEL_PARAMETERS_NONE(return);
72✔
104

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

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

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

118
        zend_object_std_init(&runtime->std, type);
2,184✔
119

120
        runtime->std.handlers = &php_parallel_runtime_handlers;
2,184✔
121

122
        php_parallel_scheduler_init(runtime);
2,184✔
123

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

128
        return &runtime->std;
2,184✔
129
}
130

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

135
        php_parallel_scheduler_stop(runtime);
2,184✔
136

137
        php_parallel_scheduler_destroy(runtime);
2,184✔
138

139
        zend_object_std_dtor(o);
2,184✔
140
}
2,184✔
141

142
PHP_MINIT_FUNCTION(PARALLEL_RUNTIME)
3,168✔
143
{
144
        zend_class_entry ce;
3,168✔
145

146
        memcpy(&php_parallel_runtime_handlers, php_parallel_standard_handlers(), sizeof(zend_object_handlers));
3,168✔
147

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

151
        INIT_NS_CLASS_ENTRY(ce, "parallel", "Runtime", php_parallel_runtime_methods);
3,168✔
152

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

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

164
        PHP_MINIT(PARALLEL_FUTURE)(INIT_FUNC_ARGS_PASSTHRU);
3,168✔
165

166
        return SUCCESS;
3,168✔
167
}
168

169
PHP_MSHUTDOWN_FUNCTION(PARALLEL_RUNTIME)
3,168✔
170
{
171
        PHP_MSHUTDOWN(PARALLEL_FUTURE)(INIT_FUNC_ARGS_PASSTHRU);
3,168✔
172

173
        return SUCCESS;
3,168✔
174
}
175
#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

© 2025 Coveralls, Inc