Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Sep 10, 2024
1 parent 5e226cd commit 5f6d0e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions ext-src/php_swoole_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "swoole_lock.h"

typedef uint32_t ThreadResourceId;
struct ThreadResource;
class ThreadResource;
struct ZendArray;

extern zend_class_entry *swoole_thread_ce;
Expand Down Expand Up @@ -145,7 +145,8 @@ struct ArrayItem {
}
};

struct ZendArray : ThreadResource {
class ZendArray : public ThreadResource {
protected:
swoole::RWLock lock_;
zend_array ht;

Expand All @@ -154,6 +155,7 @@ struct ZendArray : ThreadResource {
delete item;
}

public:
ZendArray() : ThreadResource(), lock_(0) {
zend_hash_init(&ht, 0, NULL, item_dtor, 1);
}
Expand Down
16 changes: 8 additions & 8 deletions ext-src/swoole_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,6 @@ static int coro_exit_handler(zend_execute_data *execute_data) {
#else
extern ZEND_FUNCTION(exit);
PHP_FUNCTION(swoole_exit) {
zend_string *message = NULL;
zend_long status = 0;

ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_STR_OR_LONG(message, status)
ZEND_PARSE_PARAMETERS_END();

zend_long flags = 0;
if (Coroutine::get_current()) {
flags |= SW_EXIT_IN_COROUTINE;
Expand All @@ -244,6 +236,14 @@ PHP_FUNCTION(swoole_exit) {
}

if (flags) {
zend_string *message = NULL;
zend_long status = 0;

ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_STR_OR_LONG(message, status)
ZEND_PARSE_PARAMETERS_END();

zval ex = {};
zend_object *obj = zend_throw_exception(swoole_exit_exception_ce, (message ? ZSTR_VAL(message) : "swoole exit"), 0);
ZVAL_OBJ(&ex, obj);
Expand Down

0 comments on commit 5f6d0e2

Please sign in to comment.