Skip to content

Commit fca8248

Browse files
committed
updates for Swoole 6.0.1
Signed-off-by: Demin Yin <deminy@deminy.net>
1 parent c118512 commit fca8248

File tree

5 files changed

+88
-16
lines changed

5 files changed

+88
-16
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Swoole\Coroutine;
6+
7+
/**
8+
* This Lock class provides a way to synchronize concurrent coroutines.
9+
*
10+
* @see \Swoole\Lock Use this instead when using locks accross processes.
11+
* @since 6.0.1
12+
*/
13+
class Lock
14+
{
15+
/**
16+
* The error code of the last operation. It is set to 0 if the last operation was successful.
17+
*/
18+
public int $errCode = 0;
19+
20+
/**
21+
* @param bool $shared Use preserved shared memory of Swoole to create the lock or not.
22+
*/
23+
public function __construct(bool $shared = false)
24+
{
25+
}
26+
27+
/**
28+
* Lock the lock.
29+
*
30+
* If the lock is already acquired by another coroutine, this method will block until the lock is released.
31+
*
32+
* @return bool TRUE on success, FALSE on failure.
33+
* @see Lock::trylock()
34+
*/
35+
public function lock(): bool
36+
{
37+
}
38+
39+
/**
40+
* Lock the lock in a non-blocking way.
41+
*
42+
* This method returns immediately even if the lock is not acquired. Thus, the caller should check the return value
43+
* to see if the lock is acquired or not.
44+
*
45+
* @return bool TRUE on success, FALSE on failure.
46+
* @see Lock::lock()
47+
*/
48+
public function trylock(): bool
49+
{
50+
}
51+
52+
/**
53+
* Unlock the lock.
54+
*
55+
* @return bool TRUE on success, FALSE on failure.
56+
*/
57+
public function unlock(): bool
58+
{
59+
}
60+
}

src/swoole/Swoole/Lock.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* cause memory leaks since memory usage could keep increasing as new requests keep coming in. In general, it's not
1515
* recommended to keep creating/destroying locks since this could cause memory leaks.
1616
*
17-
* Locks should not be used in coroutines, especially when there are coroutine switching between method calls to
18-
* \Swoole\Lock::lock() and \Swoole\Lock::unlock(). For example, the following example will cause deadlock:
17+
* This Lock class is not coroutine-friendly. It should not be used across different coroutines, especially when there
18+
* are coroutine switching between method calls to \Swoole\Lock::lock() and \Swoole\Lock::unlock(). For example, the
19+
* following example will cause deadlock:
1920
*
2021
* Swoole\Coroutine\run(function () {
2122
* $lock = new Swoole\Lock();
@@ -28,9 +29,12 @@
2829
* }
2930
* });
3031
*
31-
* If you think you need to use locks with coroutines, you can probably use channels instead.
32+
* If you think you need to use locks with coroutines, there are two options:
33+
* 1. use channels (before Swoole 6.0.1).
34+
* 2. use class \Swoole\Coroutine\Lock (since Swoole 6.0.1).
3235
*
3336
* @see \Swoole\Thread\Lock Use this instead when PHP is compiled with Zend Thread Safety (ZTS) enabled.
37+
* @see \Swoole\Coroutine\Lock Use this instead when using locks accross coroutines.
3438
* @see https://github.com/deminy/swoole-by-examples/blob/master/examples/csp/deadlocks/swoole-lock.php
3539
* @not-serializable Objects of this class cannot be serialized.
3640
*/
@@ -159,13 +163,4 @@ public function trylock_read(): bool
159163
public function unlock(): bool
160164
{
161165
}
162-
163-
/**
164-
* Destroy the lock and release any resources used by the lock.
165-
*
166-
* After calling this method, the lock object should not be used anymore.
167-
*/
168-
public function destroy(): void
169-
{
170-
}
171166
}

src/swoole/Swoole/Thread/ArrayList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,13 @@ public function count(): int
8484
public function toArray(): array
8585
{
8686
}
87+
88+
/**
89+
* Sort the list in ascending order, without maintaining index association.
90+
*
91+
* @since 6.0.1
92+
*/
93+
public function sort(): void
94+
{
95+
}
8796
}

src/swoole/Swoole/Thread/Map.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,13 @@ public function values(): array
9898
public function toArray(): array
9999
{
100100
}
101+
102+
/**
103+
* Sort the map in ascending order.
104+
*
105+
* @since 6.0.1
106+
*/
107+
public function sort(): void
108+
{
109+
}
101110
}

src/swoole/constants.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
/*
66
* Swoole version information.
77
*/
8-
define('SWOOLE_VERSION', '6.0.0');
9-
define('SWOOLE_VERSION_ID', 60000);
8+
define('SWOOLE_VERSION', '6.0.1');
9+
define('SWOOLE_VERSION_ID', 60001);
1010
define('SWOOLE_MAJOR_VERSION', 6);
1111
define('SWOOLE_MINOR_VERSION', 0);
12-
define('SWOOLE_RELEASE_VERSION', 0);
12+
define('SWOOLE_RELEASE_VERSION', 1);
1313
define('SWOOLE_EXTRA_VERSION', '');
1414

1515
/*
@@ -304,7 +304,6 @@
304304
#ifdef HAVE_SPINLOCK
305305
define('SWOOLE_SPINLOCK', 5); # Supported only if the Spin Locks option is provided in the POSIX thread (pthread) libraries.
306306
#endif
307-
define('SWOOLE_COROLOCK', 6); # @since v6.0.0
308307

309308
/*
310309
* Following SIG_* and PRIO_* constants are set only when PHP extension pcntl (to support Process Control) is not

0 commit comments

Comments
 (0)