Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Dec 13, 2024
1 parent 74af57d commit 8038be4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ext-src/swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2033,8 +2033,10 @@ static void hook_func(const char *name, size_t l_name, zif_handler handler, zend
rf->ori_handler = zf->internal_function.handler;
rf->ori_arg_info = zf->internal_function.arg_info;

ori_func_handlers.set(fn_name, rf->ori_handler);
ori_func_arg_infos.set(fn_name, rf->ori_arg_info);
if (sw_is_main_thread()) {
ori_func_handlers.set(fn_name, rf->ori_handler);
ori_func_arg_infos.set(fn_name, rf->ori_arg_info);
}

zf->internal_function.handler = handler;
if (arg_info) {
Expand Down
12 changes: 10 additions & 2 deletions thirdparty/php/standard/proc_open.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
static int le_proc_open;
static const char *le_proc_name = "process/coroutine";

static pid_t _co_waitpid(__pid_t __pid, int *__stat_loc, int __options) {
#ifdef SW_THREAD
return System::waitpid_safe(__pid, __stat_loc, __options);
#else
return System::waitpid(__pid, __stat_loc, __options);
#endif
}

/* {{{ _php_array_to_envp
* Process the `environment` argument to `proc_open`
* Convert into data structures which can be passed to underlying OS APIs like `exec` on POSIX or
Expand Down Expand Up @@ -170,7 +178,7 @@ static void proc_co_rsrc_dtor(zend_resource *rsrc) {
}

if (proc->running) {
System::waitpid_safe(proc->child, &wstatus, 0);
_co_waitpid(proc->child, &wstatus, 0);
}
if (proc->wstatus) {
*proc->wstatus = wstatus;
Expand Down Expand Up @@ -255,7 +263,7 @@ PHP_FUNCTION(swoole_proc_get_status) {
add_assoc_long(return_value, "pid", (zend_long) proc->child);

errno = 0;
wait_pid = System::waitpid_safe(proc->child, &wstatus, WNOHANG | WUNTRACED);
wait_pid = _co_waitpid(proc->child, &wstatus, WNOHANG | WUNTRACED);

if (wait_pid == proc->child) {
if (WIFEXITED(wstatus)) {
Expand Down

0 comments on commit 8038be4

Please sign in to comment.