Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jun 11, 2024
1 parent 60b17f2 commit 97cb093
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
7 changes: 5 additions & 2 deletions examples/thread/argv.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

if (empty($args)) {
var_dump($GLOBALS['argv']);
$thread = Thread::exec(__FILE__, 'thread-1', $argc, $argv);
$thread->join();
$n = 2;
while ($n--) {
$thread = Thread::exec(__FILE__, 'thread-' . $n, $argc, $argv);
$thread->join();
}
} else {
var_dump($args[0], $args[1], $args[2]);
sleep(1);
Expand Down
6 changes: 4 additions & 2 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ zend_class_entry *swoole_error_ce;
zend_object_handlers swoole_error_handlers;

#ifdef COMPILE_DL_SWOOLE
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
ZEND_GET_MODULE(swoole)
#endif

Expand Down Expand Up @@ -1089,8 +1092,7 @@ PHP_RSHUTDOWN_FUNCTION(swoole) {
if (!zstream) {
return;
}
stream =
(php_stream *) zend_fetch_resource2_ex((zstream), NULL, php_file_le_stream(), php_file_le_pstream());
stream = (php_stream *) zend_fetch_resource2_ex((zstream), NULL, php_file_le_stream(), php_file_le_pstream());
if (!stream) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion ext-src/php_swoole_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ zend_string *php_swoole_thread_argv_serialize(zval *zdata);
bool php_swoole_thread_argv_unserialize(zend_string *data, zval *zv);
zend_string *php_swoole_serialize(zval *zdata);
bool php_swoole_unserialize(zend_string *data, zval *zv);
void php_swoole_thread_argv_dtor(zval *zdata);
void php_swoole_thread_argv_clean(zval *zdata);
void php_swoole_thread_bailout(void);

zval *php_swoole_thread_get_arguments();
Expand Down
13 changes: 7 additions & 6 deletions ext-src/swoole_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ zend_string *php_swoole_serialize(zval *zdata) {
result = zend_string_init(serialized_data.s->val, serialized_data.s->len, 1);
}
smart_str_free(&serialized_data);

return result;
}

Expand All @@ -324,7 +323,7 @@ bool php_swoole_unserialize(zend_string *data, zval *zv) {
return unserialized;
}

void php_swoole_thread_argv_dtor(zval *zdata) {
void php_swoole_thread_argv_clean(zval *zdata) {
if (!ZVAL_IS_ARRAY(zdata)) {
return;
}
Expand All @@ -338,7 +337,6 @@ void php_swoole_thread_argv_dtor(zval *zdata) {
}
}
ZEND_HASH_FOREACH_END();
zval_dtor(zdata);
}

void php_swoole_thread_rinit() {
Expand All @@ -356,6 +354,7 @@ void php_swoole_thread_rinit() {
}

void php_swoole_thread_rshutdown() {
zval_dtor(&thread_argv);
if (tsrm_is_main_thread()) {
if (request_info.path_translated) {
free((void *) request_info.path_translated);
Expand Down Expand Up @@ -451,7 +450,9 @@ static void php_swoole_thread_create(INTERNAL_FUNCTION_PARAMETERS, zval *zobject

void php_swoole_thread_start(zend_string *file, zend_string *argv_serialized) {
ts_resource(0);
TSRMLS_CACHE_UPDATE();
#if defined(COMPILE_DL_SWOOLE) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
zend_file_handle file_handle{};
zval global_argc, global_argv;

Expand Down Expand Up @@ -498,8 +499,8 @@ void php_swoole_thread_start(zend_string *file, zend_string *argv_serialized) {
}
zend_end_try();

php_swoole_thread_argv_dtor(&thread_argv);
php_swoole_thread_argv_dtor(&global_argv);
php_swoole_thread_argv_clean(&thread_argv);
php_swoole_thread_argv_clean(&global_argv);
zend_destroy_file_handle(&file_handle);

php_request_shutdown(NULL);
Expand Down

0 comments on commit 97cb093

Please sign in to comment.