Skip to content

Commit

Permalink
Fix SW_LOCK_CHECK_RETURN (#4302)
Browse files Browse the repository at this point in the history
* Fix SW_LOCK_CHECK_RETURN

* Optimize code

* Optimize code

* Optimize code
  • Loading branch information
zmyWL authored Jul 6, 2021
1 parent e14072c commit 71ba6c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ext-src/php_swoole_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ extern PHPAPI int php_array_merge(zend_array *dest, zend_array *src);
} else { \
RETURN_TRUE; \
}
#define SW_LOCK_CHECK_RETURN(s) \
if (s == 0) { \
#define SW_LOCK_CHECK_RETURN(s) \
zend_long ___tmp_return_value = s; \
if (___tmp_return_value == 0) { \
RETURN_TRUE; \
} else { \
zend_update_property_long(NULL, SW_Z8_OBJ_P(ZEND_THIS), SW_STRL("errCode"), s); \
zend_update_property_long(NULL, SW_Z8_OBJ_P(ZEND_THIS), SW_STRL("errCode"), ___tmp_return_value ); \
RETURN_FALSE; \
}

Expand Down
23 changes: 23 additions & 0 deletions tests/swoole_lock/lockwait_twice.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
swoole_lock: test lock twice
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

$lock = new Swoole\Lock();
var_dump($lock->lock());


$start = microtime(true);
$ret = $lock->lockwait(0.2);
Assert::false($ret);
$end = microtime(true);

Assert::eq($lock->errCode, SOCKET_ETIMEDOUT);
Assert::lessThan($end - $start, 0.2);

?>
--EXPECT--
bool(true)

0 comments on commit 71ba6c0

Please sign in to comment.