Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Dec 27, 2024
1 parent e825bfd commit 3d00538
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/swoole_coroutine_lock/lock.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
swoole_lock: coroutine lock
swoole_coroutine_lock: lock
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_coroutine_lock/trylock.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
swoole_lock: coroutine lock
swoole_coroutine_lock: trylock
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@
swoole_lock: coroutine try lock
--FILE--
<?php
use Swoole\Lock;

use Swoole\Coroutine\Lock;
use function Swoole\Coroutine\run;
use function Swoole\Coroutine\go;
use Swoole\Coroutine\WaitGroup;

if (defined('SWOOLE_IOURING_SQPOLL')) {
swoole_async_set([
'iouring_workers' => 32,
'iouring_entries' => 20000,
'iouring_flag' => SWOOLE_IOURING_SQPOLL
]);
swoole_async_set([
'iouring_workers' => 32,
'iouring_entries' => 20000,
'iouring_flag' => SWOOLE_IOURING_SQPOLL
]);
}

$lock = new Lock(SWOOLE_COROLOCK);
$lock = new Lock(false);

run(function () use ($argv, $lock) {
$waitGroup = new WaitGroup();
go(function () use ($waitGroup, $lock) {
$waitGroup->add();
$lock->lock();
$lock->lock();
sleep(2);
var_dump(1);
$lock->unlock();
var_dump(1);
$lock->unlock();
$waitGroup->done();
});

go(function () use ($waitGroup, $lock) {
$waitGroup->add();
if (!$lock->trylock() || !$lock->trylock_read()) {
var_dump('lock failed');
}
$waitGroup->add();
if (!$lock->trylock()) {
var_dump('lock failed');
}
$waitGroup->done();
});

Expand Down

0 comments on commit 3d00538

Please sign in to comment.