Skip to content

Commit ac1f0eb

Browse files
committed
php#19: * The ref_count logic for event callbacks has been improved. Special macros have been added for working with references.
1 parent 5fdaf59 commit ac1f0eb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Zend/zend_async_API.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,30 @@ struct _zend_async_event_callback_s {
363363
zend_async_event_callback_dispose_fn dispose;
364364
};
365365

366+
#define ZEND_ASYNC_EVENT_CALLBACK_ADD_REF(callback) \
367+
if (callback != NULL) { \
368+
callback->ref_count++; \
369+
}
370+
371+
//
372+
// For a callback,
373+
// it’s crucial that the reference count is always greater than zero,
374+
// because a value of zero is a special case triggered from a destructor.
375+
// If you need to “retain” ownership of the object,
376+
// you **MUST** use either this macro or ZEND_ASYNC_EVENT_CALLBACK_RELEASE.
377+
//
378+
#define ZEND_ASYNC_EVENT_CALLBACK_DEC_REF(callback) \
379+
if(callback != NULL && callback->ref_count > 1) { \
380+
callback->ref_count--; \
381+
}
382+
383+
#define ZEND_ASYNC_EVENT_CALLBACK_RELEASE(callback) \
384+
if (callback != NULL && callback->ref_count > 1) { \
385+
callback->ref_count--; \
386+
} else { \
387+
coroutine_event_callback_dispose(callback, NULL); \
388+
}
389+
366390
struct _zend_coroutine_event_callback_s {
367391
zend_async_event_callback_t base;
368392
zend_coroutine_t *coroutine;

0 commit comments

Comments
 (0)