Skip to content

Commit 71ba6c0

Browse files
authored
Fix SW_LOCK_CHECK_RETURN (swoole#4302)
* Fix SW_LOCK_CHECK_RETURN * Optimize code * Optimize code * Optimize code
1 parent e14072c commit 71ba6c0

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

ext-src/php_swoole_private.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ extern PHPAPI int php_array_merge(zend_array *dest, zend_array *src);
6161
} else { \
6262
RETURN_TRUE; \
6363
}
64-
#define SW_LOCK_CHECK_RETURN(s) \
65-
if (s == 0) { \
64+
#define SW_LOCK_CHECK_RETURN(s) \
65+
zend_long ___tmp_return_value = s; \
66+
if (___tmp_return_value == 0) { \
6667
RETURN_TRUE; \
6768
} else { \
68-
zend_update_property_long(NULL, SW_Z8_OBJ_P(ZEND_THIS), SW_STRL("errCode"), s); \
69+
zend_update_property_long(NULL, SW_Z8_OBJ_P(ZEND_THIS), SW_STRL("errCode"), ___tmp_return_value ); \
6970
RETURN_FALSE; \
7071
}
7172

tests/swoole_lock/lockwait_twice.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
swoole_lock: test lock twice
3+
--SKIPIF--
4+
<?php require __DIR__ . '/../include/skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
require __DIR__ . '/../include/bootstrap.php';
8+
9+
$lock = new Swoole\Lock();
10+
var_dump($lock->lock());
11+
12+
13+
$start = microtime(true);
14+
$ret = $lock->lockwait(0.2);
15+
Assert::false($ret);
16+
$end = microtime(true);
17+
18+
Assert::eq($lock->errCode, SOCKET_ETIMEDOUT);
19+
Assert::lessThan($end - $start, 0.2);
20+
21+
?>
22+
--EXPECT--
23+
bool(true)

0 commit comments

Comments
 (0)