Skip to content

Commit 8bebdb2

Browse files
committed
Merge branch 'true-async-api' into true-async
2 parents a89b322 + ebfecef commit 8bebdb2

File tree

8 files changed

+1531
-30
lines changed

8 files changed

+1531
-30
lines changed

Zend/zend_async_API.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,31 @@ static void shutdown_stub(void) {}
4848

4949
static zend_array* get_coroutines_stub(void) { return NULL; }
5050

51-
static zend_future_t* future_create_stub(bool thread_safe, size_t extra_size)
51+
static zend_future_t* new_future_stub(bool thread_safe, size_t extra_size)
5252
{
5353
ASYNC_THROW_ERROR("Async API is not enabled");
5454
return NULL;
5555
}
5656

57-
static zend_async_channel_t* channel_create_stub(size_t buffer_size, bool resizable, bool thread_safe, size_t extra_size)
57+
static zend_async_channel_t* new_channel_stub(size_t buffer_size, bool resizable, bool thread_safe, size_t extra_size)
58+
{
59+
ASYNC_THROW_ERROR("Async API is not enabled");
60+
return NULL;
61+
}
62+
63+
static zend_async_group_t* new_group_stub(size_t extra_size)
64+
{
65+
ASYNC_THROW_ERROR("Async API is not enabled");
66+
return NULL;
67+
}
68+
69+
static zend_object* new_future_obj_stub(zend_future_t *future)
70+
{
71+
ASYNC_THROW_ERROR("Async API is not enabled");
72+
return NULL;
73+
}
74+
75+
static zend_object* new_channel_obj_stub(zend_async_channel_t *channel)
5876
{
5977
ASYNC_THROW_ERROR("Async API is not enabled");
6078
return NULL;
@@ -109,8 +127,13 @@ zend_async_get_coroutines_t zend_async_get_coroutines_fn = get_coroutines_stub;
109127
zend_async_add_microtask_t zend_async_add_microtask_fn = add_microtask_stub;
110128
zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn = get_awaiting_info_stub;
111129
zend_async_get_class_ce_t zend_async_get_class_ce_fn = get_class_ce;
112-
zend_async_future_create_t zend_async_future_create_fn = future_create_stub;
113-
zend_async_channel_create_t zend_async_channel_create_fn = channel_create_stub;
130+
zend_async_new_future_t zend_async_new_future_fn = new_future_stub;
131+
zend_async_new_channel_t zend_async_new_channel_fn = new_channel_stub;
132+
zend_async_new_future_obj_t zend_async_new_future_obj_fn = new_future_obj_stub;
133+
zend_async_new_channel_obj_t zend_async_new_channel_obj_fn = new_channel_obj_stub;
134+
135+
/* GROUP API */
136+
zend_async_new_group_t zend_async_new_group_fn = new_group_stub;
114137

115138
static zend_atomic_bool reactor_lock = {0};
116139
static char * reactor_module_name = NULL;
@@ -243,6 +266,11 @@ ZEND_API bool zend_async_scheduler_register(
243266
zend_async_get_awaiting_info_t get_awaiting_info_fn,
244267
zend_async_get_class_ce_t get_class_ce_fn,
245268
zend_async_new_iterator_t new_iterator_fn,
269+
zend_async_new_future_t new_future_fn,
270+
zend_async_new_channel_t new_channel_fn,
271+
zend_async_new_future_obj_t new_future_obj_fn,
272+
zend_async_new_channel_obj_t new_channel_obj_fn,
273+
zend_async_new_group_t new_group_fn,
246274
zend_async_engine_shutdown_t engine_shutdown_fn
247275
)
248276
{
@@ -280,6 +308,11 @@ ZEND_API bool zend_async_scheduler_register(
280308
zend_async_get_awaiting_info_fn = get_awaiting_info_fn;
281309
zend_async_get_class_ce_fn = get_class_ce_fn;
282310
zend_async_new_iterator_fn = new_iterator_fn;
311+
zend_async_new_future_fn = new_future_fn;
312+
zend_async_new_channel_fn = new_channel_fn;
313+
zend_async_new_future_obj_fn = new_future_obj_fn;
314+
zend_async_new_channel_obj_fn = new_channel_obj_fn;
315+
zend_async_new_group_fn = new_group_fn;
283316
zend_async_engine_shutdown_fn = engine_shutdown_fn;
284317

285318
zend_atomic_bool_store(&scheduler_lock, 0);

Zend/zend_async_API.h

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
#include "zend_fibers.h"
2020
#include "zend_globals.h"
2121

22-
#define ZEND_ASYNC_API "TrueAsync API v0.4.0"
22+
#define ZEND_ASYNC_API "TrueAsync API v0.5.0"
2323
#define ZEND_ASYNC_API_VERSION_MAJOR 0
24-
#define ZEND_ASYNC_API_VERSION_MINOR 4
24+
#define ZEND_ASYNC_API_VERSION_MINOR 5
2525
#define ZEND_ASYNC_API_VERSION_PATCH 0
2626

2727
#define ZEND_ASYNC_API_VERSION_NUMBER \
@@ -106,6 +106,7 @@ typedef enum
106106

107107
ZEND_ASYNC_CLASS_CHANNEL = 10,
108108
ZEND_ASYNC_CLASS_FUTURE = 11,
109+
ZEND_ASYNC_CLASS_GROUP = 12,
109110

110111
ZEND_ASYNC_EXCEPTION_DEFAULT = 30,
111112
ZEND_ASYNC_EXCEPTION_CANCELLATION = 31,
@@ -134,6 +135,7 @@ typedef struct _zend_async_waker_s zend_async_waker_t;
134135
typedef struct _zend_async_microtask_s zend_async_microtask_t;
135136
typedef struct _zend_async_scope_s zend_async_scope_t;
136137
typedef struct _zend_async_iterator_s zend_async_iterator_t;
138+
typedef struct _zend_async_group_s zend_async_group_t;
137139
typedef struct _zend_fcall_s zend_fcall_t;
138140
typedef void (*zend_coroutine_entry_t)(void);
139141

@@ -217,8 +219,13 @@ typedef zend_array* (*zend_async_get_coroutines_t)(void);
217219
typedef void (*zend_async_add_microtask_t)(zend_async_microtask_t *microtask);
218220
typedef zend_array* (*zend_async_get_awaiting_info_t)(zend_coroutine_t * coroutine);
219221
typedef zend_class_entry* (*zend_async_get_class_ce_t)(zend_async_class type);
220-
typedef zend_future_t* (*zend_async_future_create_t)(bool thread_safe, size_t extra_size);
221-
typedef zend_async_channel_t* (*zend_async_channel_create_t)(size_t buffer_size, bool resizable, bool thread_safe, size_t extra_size);
222+
typedef zend_future_t* (*zend_async_new_future_t)(bool thread_safe, size_t extra_size);
223+
typedef zend_async_channel_t* (*zend_async_new_channel_t)(size_t buffer_size, bool resizable, bool thread_safe, size_t extra_size);
224+
225+
typedef zend_async_group_t* (*zend_async_new_group_t)(size_t extra_size);
226+
227+
typedef zend_object* (*zend_async_new_future_obj_t)(zend_future_t *future);
228+
typedef zend_object* (*zend_async_new_channel_obj_t)(zend_async_channel_t *channel);
222229

223230
typedef void (*zend_async_reactor_startup_t)(void);
224231
typedef void (*zend_async_reactor_shutdown_t)(void);
@@ -286,6 +293,8 @@ typedef int (* zend_async_exec_t) (
286293

287294
typedef void (*zend_async_queue_task_t)(zend_async_task_t *task);
288295

296+
typedef void (*zend_async_task_run_t)(zend_async_task_t *task);
297+
289298
typedef void (*zend_async_microtask_handler_t)(zend_async_microtask_t *microtask);
290299

291300
struct _zend_fcall_s {
@@ -732,6 +741,7 @@ struct _zend_async_listen_event_s {
732741

733742
struct _zend_async_task_s {
734743
zend_async_event_t base;
744+
zend_async_task_run_t run;
735745
};
736746

737747
struct _zend_async_trigger_event_s {
@@ -1259,8 +1269,13 @@ ZEND_API extern zend_async_get_coroutines_t zend_async_get_coroutines_fn;
12591269
ZEND_API extern zend_async_add_microtask_t zend_async_add_microtask_fn;
12601270
ZEND_API extern zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn;
12611271
ZEND_API extern zend_async_get_class_ce_t zend_async_get_class_ce_fn;
1262-
ZEND_API extern zend_async_future_create_t zend_async_future_create_fn;
1263-
ZEND_API extern zend_async_channel_create_t zend_async_channel_create_fn;
1272+
ZEND_API extern zend_async_new_future_t zend_async_new_future_fn;
1273+
ZEND_API extern zend_async_new_channel_t zend_async_new_channel_fn;
1274+
ZEND_API extern zend_async_new_future_obj_t zend_async_new_future_obj_fn;
1275+
ZEND_API extern zend_async_new_channel_obj_t zend_async_new_channel_obj_fn;
1276+
1277+
/* GROUP API */
1278+
ZEND_API extern zend_async_new_group_t zend_async_new_group_fn;
12641279

12651280
/* Iterator API */
12661281
ZEND_API extern zend_async_new_iterator_t zend_async_new_iterator_fn;
@@ -1335,6 +1350,11 @@ ZEND_API bool zend_async_scheduler_register(
13351350
zend_async_get_awaiting_info_t get_awaiting_info_fn,
13361351
zend_async_get_class_ce_t get_class_ce_fn,
13371352
zend_async_new_iterator_t new_iterator_fn,
1353+
zend_async_new_future_t new_future_fn,
1354+
zend_async_new_channel_t new_channel_fn,
1355+
zend_async_new_future_obj_t new_future_obj_fn,
1356+
zend_async_new_channel_obj_t new_channel_obj_fn,
1357+
zend_async_new_group_t new_group_fn,
13381358
zend_async_engine_shutdown_t engine_shutdown_fn
13391359
);
13401360

@@ -1446,12 +1466,18 @@ ZEND_API void zend_async_add_main_coroutine_start_handler(
14461466
ZEND_API void zend_async_call_main_coroutine_start_handlers(zend_coroutine_t *main_coroutine);
14471467

14481468
/* Future API Functions */
1449-
#define ZEND_ASYNC_NEW_FUTURE(thread_safe) zend_async_future_create_fn(thread_safe, 0)
1450-
#define ZEND_ASYNC_NEW_FUTURE_EX(thread_safe, extra_size) zend_async_future_create_fn(thread_safe, extra_size)
1469+
#define ZEND_ASYNC_NEW_FUTURE(thread_safe) zend_async_new_future_fn(thread_safe, 0)
1470+
#define ZEND_ASYNC_NEW_FUTURE_EX(thread_safe, extra_size) zend_async_new_future_fn(thread_safe, extra_size)
1471+
#define ZEND_ASYNC_NEW_FUTURE_OBJ(future) zend_async_new_future_obj_fn(future)
14511472

14521473
/* Channel API Functions */
1453-
#define ZEND_ASYNC_NEW_CHANNEL(buffer_size, resizable, thread_safe) zend_async_channel_create_fn(buffer_size, resizable, thread_safe, 0)
1454-
#define ZEND_ASYNC_NEW_CHANNEL_EX(buffer_size, resizable, thread_safe, extra_size) zend_async_channel_create_fn(buffer_size, resizable, thread_safe, extra_size)
1474+
#define ZEND_ASYNC_NEW_CHANNEL(buffer_size, resizable, thread_safe) zend_async_new_channel_fn(buffer_size, resizable, thread_safe, 0)
1475+
#define ZEND_ASYNC_NEW_CHANNEL_EX(buffer_size, resizable, thread_safe, extra_size) zend_async_new_channel_fn(buffer_size, resizable, thread_safe, extra_size)
1476+
#define ZEND_ASYNC_NEW_CHANNEL_OBJ(channel) zend_async_new_channel_obj_fn(channel)
1477+
1478+
/* GROUP API Functions */
1479+
#define ZEND_ASYNC_NEW_GROUP() zend_async_new_group_fn(0)
1480+
#define ZEND_ASYNC_NEW_GROUP_EX(extra_size) zend_async_new_group_fn(extra_size)
14551481

14561482
END_EXTERN_C()
14571483

docs/source/miscellaneous/writing-tests.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ might use a variation tests to test boundary conditions.
9595
How big is a test case?
9696
=======================
9797

98-
Small. Really — the smaller the better, a good guide is no more than 10 lines of output. The reason
99-
for this is that if we break something in PHP and it breaks your test case we need to be able to
100-
find out quite quickly what we broke, going through 1000s of line of test case output is not easy.
101-
Having said that it's sometimes just not practical to stay within the 10 line guideline, in this
102-
case you can help a lot by commenting the output. You may find plenty of much longer tests in PHP -
103-
the small tests message is something that we learnt over time, in fact we are slowly going through
104-
and splitting tests up when we need to.
98+
Small. Really — the smaller the better, a good guide is no more than 10 lines of output. The
99+
reason for this is that if we break something in PHP and it breaks your test case we need to be able
100+
to find out quite quickly what we broke, going through 1000s of line of test case output is not
101+
easy. Having said that it's sometimes just not practical to stay within the 10 line guideline, in
102+
this case you can help a lot by commenting the output. You may find plenty of much longer tests in
103+
PHP - the small tests message is something that we learnt over time, in fact we are slowly going
104+
through and splitting tests up when we need to.
105105

106106
Comments
107107
========
@@ -183,10 +183,10 @@ Testing your test cases
183183

184184
Most people who write tests for PHP don't have access to a huge number of operating systems but the
185185
tests are run on every system that runs PHP. It's good to test your test on as many platforms as you
186-
can — Linux and Windows are the most important, it's increasingly important to make sure that tests
187-
run on 64 bit as well as 32 bit platforms. If you only have access to one operating system — don't
188-
worry, if you have karma, commit the test but watch php-qa@lists.php.net for reports of failures on
189-
other platforms. If you don't have karma to commit have a look at the next section.
186+
can — Linux and Windows are the most important, it's increasingly important to make sure that
187+
tests run on 64 bit as well as 32 bit platforms. If you only have access to one operating system —
188+
don't worry, if you have karma, commit the test but watch php-qa@lists.php.net for reports of
189+
failures on other platforms. If you don't have karma to commit have a look at the next section.
190190

191191
When you are testing your test case it's really important to make sure that you clean up any
192192
temporary resources (eg files) that you used in the test. There is a special ``--CLEAN--`` section

0 commit comments

Comments
 (0)