Compare commits
2
Commits
213cf2d810
...
php7.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0db3806d6 | ||
|
|
2b0d36a268 |
@@ -1,14 +1,13 @@
|
|||||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
Copyright 2019 Denis "ftc" Denisov
|
||||||
|
|
||||||
Version 2, December 2004
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim or modified copies of
|
Unless required by applicable law or agreed to in writing, software
|
||||||
this license document, and changing it is allowed as long as the name is changed.
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
|
||||||
@@ -69,10 +69,64 @@ Returns `true` on success, `false` otherwise.
|
|||||||
|
|
||||||
### posix_sem_post($semaphore)
|
### posix_sem_post($semaphore)
|
||||||
|
|
||||||
|
Unlocks semaphore. If the semaphore's value consequently becomes greater than zero, then
|
||||||
|
another process or thread blocked in a sem_wait call will be woken
|
||||||
|
up and proceed to lock the semaphore.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
* $semaphore - semaphore resource to unlock (acquired via `posix_sem_open`).
|
||||||
|
|
||||||
|
Returns `true` on success, `false` otherwise.
|
||||||
|
|
||||||
|
|
||||||
### posix_sem_wait($semaphore)
|
### posix_sem_wait($semaphore)
|
||||||
|
|
||||||
|
Locks a semaphore. If
|
||||||
|
the semaphore's value is greater than zero, then the decrement
|
||||||
|
proceeds, and the function returns, immediately. If the semaphore
|
||||||
|
currently has the value zero, then the call blocks until either it
|
||||||
|
becomes possible to perform the decrement (i.e., the semaphore value
|
||||||
|
rises above zero), or a signal handler interrupts the call.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
* $semaphore - semaphore resource to unlock (acquired via `posix_sem_open`).
|
||||||
|
|
||||||
|
Returns `true` on success, `false` otherwise.
|
||||||
|
|
||||||
|
### posix_sem_trywait($semaphore)
|
||||||
|
|
||||||
|
The same as `posix_sem_wait`, except that if the decrement
|
||||||
|
cannot be immediately performed, then call returns an error (last error
|
||||||
|
set to EAGAIN) instead of blocking.
|
||||||
|
|
||||||
|
### posix_sem_timedwait($semaphore, $timeout_sec, $timeout_nsec = 0)
|
||||||
|
|
||||||
|
Tries to lock a semaphore (as `posix_sem_wait`), but if lock could not
|
||||||
|
be performed in a specified timeout, returns and sets last error to ETIMEDOUT.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
* $semaphore - semaphore resource to unlock (acquired via `posix_sem_open`).
|
||||||
|
* $timeout_sec - part of the timeout in seconds.
|
||||||
|
* $timeout_nsec - part of the timeout in nanoseconds.
|
||||||
|
|
||||||
|
Total timeout is computed as `$timeout_sec * 1000000000 + $timeout_nsec` and is
|
||||||
|
measured in nanoseconds.
|
||||||
|
|
||||||
### posix_sem_getvalue($semaphore)
|
### posix_sem_getvalue($semaphore)
|
||||||
|
|
||||||
|
Gets value of specified semaphore.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
* $semaphore - semaphore resource which value to get (acquired via `posix_sem_open`).
|
||||||
|
|
||||||
|
Returns semaphore value on success and `null` on error.
|
||||||
|
|
||||||
|
Please note that underlying function `sem_getvalue` can behave differently according to
|
||||||
|
POSIX specification, so please read your OS documentation on that.
|
||||||
|
|
||||||
|
### posix_sem_error()
|
||||||
|
|
||||||
|
Returns value of last error occured during call of another semaphore-related function.
|
||||||
|
|
||||||
## Notes for PHP users
|
## Notes for PHP users
|
||||||
|
|
||||||
|
|||||||
+15
-16
@@ -51,7 +51,7 @@ typedef struct _php_posix_semaphore {
|
|||||||
} php_posix_semaphore;
|
} php_posix_semaphore;
|
||||||
|
|
||||||
|
|
||||||
static void php_posix_semaphore_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
static void php_posix_semaphore_dtor(zend_resource *rsrc TSRMLS_DC)
|
||||||
{
|
{
|
||||||
php_posix_semaphore *s = (php_posix_semaphore*)rsrc->ptr;
|
php_posix_semaphore *s = (php_posix_semaphore*)rsrc->ptr;
|
||||||
if (s)
|
if (s)
|
||||||
@@ -92,10 +92,10 @@ PHP_MSHUTDOWN_FUNCTION(posix_semaphores)
|
|||||||
PHP_FUNCTION(posix_sem_open)
|
PHP_FUNCTION(posix_sem_open)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
int name_length;
|
size_t name_length;
|
||||||
long flags;
|
zend_long flags;
|
||||||
long mode = 0666;
|
zend_long mode = 0666;
|
||||||
long value = 0;
|
zend_long value = 0;
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ll", &name, &name_length, &flags, &mode, &value) == FAILURE)
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ll", &name, &name_length, &flags, &mode, &value) == FAILURE)
|
||||||
{
|
{
|
||||||
RETURN_NULL();
|
RETURN_NULL();
|
||||||
@@ -108,7 +108,7 @@ PHP_FUNCTION(posix_sem_open)
|
|||||||
}
|
}
|
||||||
php_posix_semaphore *semaphore = emalloc(sizeof(php_posix_semaphore));
|
php_posix_semaphore *semaphore = emalloc(sizeof(php_posix_semaphore));
|
||||||
semaphore->sem = sem;
|
semaphore->sem = sem;
|
||||||
ZEND_REGISTER_RESOURCE(return_value, semaphore, le_posix_semaphore);
|
ZVAL_RES(return_value, zend_register_resource(semaphore, le_posix_semaphore));
|
||||||
}
|
}
|
||||||
|
|
||||||
PHP_FUNCTION(posix_sem_close)
|
PHP_FUNCTION(posix_sem_close)
|
||||||
@@ -119,8 +119,7 @@ PHP_FUNCTION(posix_sem_close)
|
|||||||
{
|
{
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
semaphore = (php_posix_semaphore*)zend_fetch_resource(Z_RES_P(zsemaphore), PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
||||||
ZEND_FETCH_RESOURCE(semaphore, php_posix_semaphore*, &zsemaphore, -1, PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
|
||||||
if (semaphore->sem)
|
if (semaphore->sem)
|
||||||
{
|
{
|
||||||
if (sem_close(semaphore->sem) == -1)
|
if (sem_close(semaphore->sem) == -1)
|
||||||
@@ -137,7 +136,7 @@ PHP_FUNCTION(posix_sem_close)
|
|||||||
PHP_FUNCTION(posix_sem_unlink)
|
PHP_FUNCTION(posix_sem_unlink)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
int name_length;
|
size_t name_length;
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_length) == FAILURE)
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_length) == FAILURE)
|
||||||
{
|
{
|
||||||
RETURN_NULL();
|
RETURN_NULL();
|
||||||
@@ -159,7 +158,7 @@ PHP_FUNCTION(posix_sem_getvalue)
|
|||||||
RETURN_NULL();
|
RETURN_NULL();
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_FETCH_RESOURCE(semaphore, php_posix_semaphore*, &zsemaphore, -1, PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
semaphore = (php_posix_semaphore*)zend_fetch_resource(Z_RES_P(zsemaphore), PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
||||||
if (semaphore->sem)
|
if (semaphore->sem)
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
@@ -188,7 +187,7 @@ PHP_FUNCTION(posix_sem_post)
|
|||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_FETCH_RESOURCE(semaphore, php_posix_semaphore*, &zsemaphore, -1, PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
semaphore = (php_posix_semaphore*)zend_fetch_resource(Z_RES_P(zsemaphore), PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
||||||
if (semaphore->sem)
|
if (semaphore->sem)
|
||||||
{
|
{
|
||||||
if (sem_post(semaphore->sem) == -1)
|
if (sem_post(semaphore->sem) == -1)
|
||||||
@@ -216,7 +215,7 @@ PHP_FUNCTION(posix_sem_wait)
|
|||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_FETCH_RESOURCE(semaphore, php_posix_semaphore*, &zsemaphore, -1, PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
semaphore = (php_posix_semaphore*)zend_fetch_resource(Z_RES_P(zsemaphore), PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
||||||
if (semaphore->sem)
|
if (semaphore->sem)
|
||||||
{
|
{
|
||||||
if (sem_wait(semaphore->sem) == -1)
|
if (sem_wait(semaphore->sem) == -1)
|
||||||
@@ -244,7 +243,7 @@ PHP_FUNCTION(posix_sem_trywait)
|
|||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_FETCH_RESOURCE(semaphore, php_posix_semaphore*, &zsemaphore, -1, PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
semaphore = (php_posix_semaphore*)zend_fetch_resource(Z_RES_P(zsemaphore), PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
||||||
if (semaphore->sem)
|
if (semaphore->sem)
|
||||||
{
|
{
|
||||||
if (sem_trywait(semaphore->sem) == -1)
|
if (sem_trywait(semaphore->sem) == -1)
|
||||||
@@ -267,14 +266,14 @@ PHP_FUNCTION(posix_sem_timedwait)
|
|||||||
{
|
{
|
||||||
php_posix_semaphore *semaphore;
|
php_posix_semaphore *semaphore;
|
||||||
zval *zsemaphore;
|
zval *zsemaphore;
|
||||||
long timeout_sec;
|
zend_long timeout_sec;
|
||||||
long timeout_nsec = 0;
|
zend_long timeout_nsec = 0;
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &zsemaphore, &timeout_sec, &timeout_nsec) == FAILURE)
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &zsemaphore, &timeout_sec, &timeout_nsec) == FAILURE)
|
||||||
{
|
{
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_FETCH_RESOURCE(semaphore, php_posix_semaphore*, &zsemaphore, -1, PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
semaphore = (php_posix_semaphore*)zend_fetch_resource(Z_RES_P(zsemaphore), PHP_POSIX_SEMAPHORES_RES_NAME, le_posix_semaphore);
|
||||||
if (semaphore->sem)
|
if (semaphore->sem)
|
||||||
{
|
{
|
||||||
struct timespec tm;
|
struct timespec tm;
|
||||||
|
|||||||
Reference in New Issue
Block a user