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

krakjoe / parallel / 13891678545

14 Mar 2025 04:24PM UTC coverage: 96.923%. Remained the same
13891678545

push

github

web-flow
Update docs (#340)

2992 of 3087 relevant lines covered (96.92%)

5766.32 hits per line

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

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

30
    object_init_ex(&rt, php_parallel_runtime_ce);
405✔
31

32
    runtime = 
405✔
33
        php_parallel_runtime_from(&rt);
405✔
34

35
    php_parallel_scheduler_start(runtime, bootstrap);
405✔
36

37
    if (!EG(exception)) {
405✔
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,365✔
50
{
51
    php_parallel_runtime_t *runtime = php_parallel_runtime_from(getThis());
1,365✔
52
    zend_string            *bootstrap = NULL;
1,365✔
53

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

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

73
    ZEND_PARSE_PARAMETERS_START(1, 2)
1,670✔
74
        Z_PARAM_OBJECT_OF_CLASS(closure, zend_ce_closure)
3,340✔
75
        Z_PARAM_OPTIONAL
1,670✔
76
        Z_PARAM_ARRAY(argv)
2,205✔
77
    ZEND_PARSE_PARAMETERS_END();
1,670✔
78

79
    if (php_parallel_monitor_check(runtime->monitor, PHP_PARALLEL_CLOSED)) {
1,670✔
80
        php_parallel_exception_ex(
15✔
81
            php_parallel_runtime_error_closed_ce,
82
            "Runtime closed");
83
        return;
15✔
84
    }
85

86
    php_parallel_scheduler_push(runtime, closure, argv, return_value);
1,655✔
87
}
88

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

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

97
    PARALLEL_PARAMETERS_NONE(return);
95✔
98

99
    php_parallel_scheduler_join(runtime, 0);
95✔
100
}
101

102
PHP_METHOD(Parallel_Runtime, kill)
60✔
103
{
104
    php_parallel_runtime_t *runtime =
60✔
105
        php_parallel_runtime_from(getThis());
60✔
106

107
    PARALLEL_PARAMETERS_NONE(return);
60✔
108

109
    php_parallel_scheduler_join(runtime, 1);
60✔
110
}
111

112
zend_function_entry php_parallel_runtime_methods[] = {
113
    PHP_ME(Parallel_Runtime, __construct, php_parallel_runtime_construct_arginfo, ZEND_ACC_PUBLIC)
114
    PHP_ME(Parallel_Runtime, run, php_parallel_runtime_run_arginfo, ZEND_ACC_PUBLIC)
115
    PHP_ME(Parallel_Runtime, close, php_parallel_runtime_close_or_kill_arginfo, ZEND_ACC_PUBLIC)
116
    PHP_ME(Parallel_Runtime, kill, php_parallel_runtime_close_or_kill_arginfo, ZEND_ACC_PUBLIC)
117
    PHP_FE_END
118
};
119

120
zend_object* php_parallel_runtime_create(zend_class_entry *type) {
1,770✔
121
    php_parallel_runtime_t *runtime = ecalloc(1,
1,770✔
122
            sizeof(php_parallel_runtime_t) + zend_object_properties_size(type));
123

124
    zend_object_std_init(&runtime->std, type);
1,770✔
125

126
    runtime->std.handlers = &php_parallel_runtime_handlers;
1,770✔
127

128
    php_parallel_scheduler_init(runtime);
1,770✔
129

130
    runtime->parent.server = SG(server_context);
1,770✔
131
    runtime->parent.request_info = &SG(request_info);
1,770✔
132

133
    return &runtime->std;
1,770✔
134
}
135

136
void php_parallel_runtime_destroy(zend_object *o) {
1,770✔
137
    php_parallel_runtime_t *runtime =
1,770✔
138
        php_parallel_runtime_fetch(o);
1,770✔
139

140
    php_parallel_scheduler_stop(runtime);
1,770✔
141

142
    php_parallel_scheduler_destroy(runtime);
1,770✔
143

144
    zend_object_std_dtor(o);
1,770✔
145
}
1,770✔
146

147
PHP_MINIT_FUNCTION(PARALLEL_RUNTIME)
2,660✔
148
{
149
    zend_class_entry ce;
2,660✔
150

151
    memcpy(&php_parallel_runtime_handlers, php_parallel_standard_handlers(), sizeof(zend_object_handlers));
2,660✔
152

153
    php_parallel_runtime_handlers.offset = XtOffsetOf(php_parallel_runtime_t, std);
2,660✔
154
    php_parallel_runtime_handlers.free_obj = php_parallel_runtime_destroy;
2,660✔
155

156
    INIT_NS_CLASS_ENTRY(ce, "parallel", "Runtime", php_parallel_runtime_methods);
2,660✔
157

158
    php_parallel_runtime_ce = zend_register_internal_class(&ce);
2,660✔
159
    php_parallel_runtime_ce->create_object = php_parallel_runtime_create;
2,660✔
160
    php_parallel_runtime_ce->ce_flags |= ZEND_ACC_FINAL;
2,660✔
161

162
    #ifdef ZEND_ACC_NOT_SERIALIZABLE
163
        php_parallel_runtime_ce->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
1,828✔
164
    #else
165
        php_parallel_runtime_ce->serialize = zend_class_serialize_deny;
832✔
166
        php_parallel_runtime_ce->unserialize = zend_class_unserialize_deny;
832✔
167
    #endif
168

169
    PHP_MINIT(PARALLEL_FUTURE)(INIT_FUNC_ARGS_PASSTHRU);
2,660✔
170

171
    return SUCCESS;
2,660✔
172
}
173

174
PHP_MSHUTDOWN_FUNCTION(PARALLEL_RUNTIME)
2,660✔
175
{
176
    PHP_MSHUTDOWN(PARALLEL_FUTURE)(INIT_FUNC_ARGS_PASSTHRU);
2,660✔
177

178
    return SUCCESS;
2,660✔
179
}
180
#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