Skip to content

Commit

Permalink
revert/staging previous working, not totally state
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Mar 10, 2023
1 parent 6570127 commit b8384b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
4 changes: 2 additions & 2 deletions test_thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ function main()
$index = c_array_type('int', 'ts', MAX_THREADS);
$status = 0;
$arrLen = 0;
$i = 0;

$arrLen = ffi_sizeof($arrPaintings);
$arrLen = ffi_sizeof($arrPaintings) * \count($arrPaintings);

srand(time()); /* initialize random seed */
for ($i = 0; $i < MAX_THREADS; $i++) {
Expand All @@ -59,6 +58,7 @@ function main()
$t->addr_of($i),
null,
function (CData $arg) {
echo '---> ';
$arrPaintings = [
"The Last Supper", "Mona Lisa", "Potato Eaters",
"Cypresses", "Starry Night", "Water Lilies"
Expand Down
37 changes: 8 additions & 29 deletions zend/ThreadsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ final class ThreadsModule extends \StandardModule
/** @var \Closure */
protected ?CData $original_sapi_output = null;

/** @var \pthread_mutex_t */
protected ?CData $output_mutex = null;

const MODULES_TO_RELOAD = ['filter', 'session'];

public function set_lifecycle(
callable $m_init = null,
callable $m_end = null,
Expand Down Expand Up @@ -74,9 +69,7 @@ public function set_lifecycle(
public function startup(): void
{
$module = $this->ze_other_ptr;
\ze_ffi()->php_output_end_all();
\ze_ffi()->php_output_deactivate();
// \ze_ffi()->php_output_shutdown();
\ze_ffi()->php_output_shutdown();

\ze_ffi()->sapi_flush();
\ze_ffi()->sapi_deactivate();
Expand All @@ -102,24 +95,16 @@ public function startup(): void
};
}

if (\is_null($this->output_mutex)) {
try {
$this->output_mutex = \ffi_ptr($this->get_globals('mutex'));
} catch (\Throwable $e) {
}

\bail_if_fail(
\ts_ffi()->pthread_mutex_init($this->output_mutex, null),
__FILE__,
__LINE__
);
}

$this->original_sapi_output = \ze_ffi()->sapi_module->ub_write;
\ze_ffi()->sapi_module->ub_write = function (string $str, int $len): int {
\ts_ffi()->pthread_mutex_lock($this->output_mutex);
$mutex = \Core::get_mutex();
if (!\is_cdata($mutex)) {
$mutex = \Core::reset_mutex();
}

\ze_ffi()->tsrm_mutex_lock($mutex);
$result = ($this->original_sapi_output)($str, $len);
\ts_ffi()->pthread_mutex_unlock($this->output_mutex);
\ze_ffi()->tsrm_mutex_unlock($mutex);

return $result;
};
Expand All @@ -133,8 +118,6 @@ public function startup(): void
\closure_from($this, 'module_destructor')
);

\ze_ffi()->php_output_activate();

$result = \IS_PHP82
? \ze_ffi()->php_module_startup(\FFI::addr(\ze_ffi()->sapi_module), null)
: \ze_ffi()->php_module_startup(\FFI::addr(\ze_ffi()->sapi_module), null, 0);
Expand Down Expand Up @@ -181,11 +164,7 @@ public function global_shutdown(CData $memory): void
if (!$this->target_persistent) {
if (\is_ze_ffi()) {
\ze_ffi()->sapi_module->ub_write = $this->original_sapi_output;
\ts_ffi()->pthread_mutex_destroy($this->output_mutex);

$this->original_sapi_output = null;
$this->output_mutex = null;
$this->get_globals('mutex', null);
}
}
}
Expand Down

0 comments on commit b8384b7

Please sign in to comment.