|
|
|
@@ -11,15 +11,15 @@
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
static zend_function_entry posix_semaphores_functions[] = {
|
|
|
|
|
PHP_FE(posix_sem_open, NULL)
|
|
|
|
|
PHP_FE(posix_sem_close, NULL)
|
|
|
|
|
PHP_FE(posix_sem_unlink, NULL)
|
|
|
|
|
PHP_FE(posix_sem_getvalue, NULL)
|
|
|
|
|
PHP_FE(posix_sem_post, NULL)
|
|
|
|
|
PHP_FE(posix_sem_wait, NULL)
|
|
|
|
|
PHP_FE(posix_sem_trywait, NULL)
|
|
|
|
|
PHP_FE(posix_sem_timedwait, NULL)
|
|
|
|
|
PHP_FE(posix_sem_error, NULL)
|
|
|
|
|
PHP_FE(posix_sem_open, arginfo_posix_sem_open)
|
|
|
|
|
PHP_FE(posix_sem_close, arginfo_posix_sem_close)
|
|
|
|
|
PHP_FE(posix_sem_unlink, arginfo_posix_sem_unlink)
|
|
|
|
|
PHP_FE(posix_sem_getvalue, arginfo_posix_sem_getvalue)
|
|
|
|
|
PHP_FE(posix_sem_post, arginfo_posix_sem_post)
|
|
|
|
|
PHP_FE(posix_sem_wait, arginfo_posix_sem_wait)
|
|
|
|
|
PHP_FE(posix_sem_trywait, arginfo_posix_sem_trywait)
|
|
|
|
|
PHP_FE(posix_sem_timedwait, arginfo_posix_sem_timedwait)
|
|
|
|
|
PHP_FE(posix_sem_error, arginfo_posix_sem_error)
|
|
|
|
|
{NULL, NULL, NULL}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -51,7 +51,7 @@ typedef struct _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)
|
|
|
|
|
{
|
|
|
|
|
php_posix_semaphore *s = (php_posix_semaphore*)rsrc->ptr;
|
|
|
|
|
if (s)
|
|
|
|
@@ -92,11 +92,11 @@ PHP_MSHUTDOWN_FUNCTION(posix_semaphores)
|
|
|
|
|
PHP_FUNCTION(posix_sem_open)
|
|
|
|
|
{
|
|
|
|
|
char *name;
|
|
|
|
|
int name_length;
|
|
|
|
|
long flags;
|
|
|
|
|
long mode = 0666;
|
|
|
|
|
long value = 0;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ll", &name, &name_length, &flags, &mode, &value) == FAILURE)
|
|
|
|
|
size_t name_length;
|
|
|
|
|
zend_long flags;
|
|
|
|
|
zend_long mode = 0666;
|
|
|
|
|
zend_long value = 0;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|ll", &name, &name_length, &flags, &mode, &value) == FAILURE)
|
|
|
|
|
{
|
|
|
|
|
RETURN_NULL();
|
|
|
|
|
}
|
|
|
|
@@ -108,19 +108,18 @@ PHP_FUNCTION(posix_sem_open)
|
|
|
|
|
}
|
|
|
|
|
php_posix_semaphore *semaphore = emalloc(sizeof(php_posix_semaphore));
|
|
|
|
|
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_posix_semaphore *semaphore;
|
|
|
|
|
zval *zsemaphore;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsemaphore) == FAILURE)
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zsemaphore) == FAILURE)
|
|
|
|
|
{
|
|
|
|
|
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 (sem_close(semaphore->sem) == -1)
|
|
|
|
@@ -137,8 +136,8 @@ PHP_FUNCTION(posix_sem_close)
|
|
|
|
|
PHP_FUNCTION(posix_sem_unlink)
|
|
|
|
|
{
|
|
|
|
|
char *name;
|
|
|
|
|
int name_length;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_length) == FAILURE)
|
|
|
|
|
size_t name_length;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_length) == FAILURE)
|
|
|
|
|
{
|
|
|
|
|
RETURN_NULL();
|
|
|
|
|
}
|
|
|
|
@@ -154,12 +153,12 @@ PHP_FUNCTION(posix_sem_getvalue)
|
|
|
|
|
{
|
|
|
|
|
php_posix_semaphore *semaphore;
|
|
|
|
|
zval *zsemaphore;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsemaphore) == FAILURE)
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zsemaphore) == FAILURE)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
int value;
|
|
|
|
@@ -183,12 +182,12 @@ PHP_FUNCTION(posix_sem_post)
|
|
|
|
|
{
|
|
|
|
|
php_posix_semaphore *semaphore;
|
|
|
|
|
zval *zsemaphore;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsemaphore) == FAILURE)
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zsemaphore) == FAILURE)
|
|
|
|
|
{
|
|
|
|
|
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 (sem_post(semaphore->sem) == -1)
|
|
|
|
@@ -211,12 +210,12 @@ PHP_FUNCTION(posix_sem_wait)
|
|
|
|
|
{
|
|
|
|
|
php_posix_semaphore *semaphore;
|
|
|
|
|
zval *zsemaphore;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsemaphore) == FAILURE)
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zsemaphore) == FAILURE)
|
|
|
|
|
{
|
|
|
|
|
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 (sem_wait(semaphore->sem) == -1)
|
|
|
|
@@ -239,12 +238,12 @@ PHP_FUNCTION(posix_sem_trywait)
|
|
|
|
|
{
|
|
|
|
|
php_posix_semaphore *semaphore;
|
|
|
|
|
zval *zsemaphore;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsemaphore) == FAILURE)
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zsemaphore) == FAILURE)
|
|
|
|
|
{
|
|
|
|
|
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 (sem_trywait(semaphore->sem) == -1)
|
|
|
|
@@ -267,14 +266,14 @@ PHP_FUNCTION(posix_sem_timedwait)
|
|
|
|
|
{
|
|
|
|
|
php_posix_semaphore *semaphore;
|
|
|
|
|
zval *zsemaphore;
|
|
|
|
|
long timeout_sec;
|
|
|
|
|
long timeout_nsec = 0;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &zsemaphore, &timeout_sec, &timeout_nsec) == FAILURE)
|
|
|
|
|
zend_long timeout_sec;
|
|
|
|
|
zend_long timeout_nsec = 0;
|
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &zsemaphore, &timeout_sec, &timeout_nsec) == FAILURE)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
struct timespec tm;
|
|
|
|
|