From 4d57292d8db71990bd204160714eb87e5ec816e1 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Sun, 17 Jun 2012 21:11:16 +0900 Subject: [PATCH] for now, add rwlock functions --- TODO.md | 7 ------- php_uv.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/TODO.md b/TODO.md index b4a4a69..9616eeb 100644 --- a/TODO.md +++ b/TODO.md @@ -88,13 +88,6 @@ * UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle); * UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle); -* UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock); -* UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock); -* UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock); -* UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock); -* UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock); -* UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock); - * UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void)); * UV_EXTERN int uv_thread_create(uv_thread_t *tid,void (*entry)(void *arg), void *arg); * UV_EXTERN int uv_thread_join(uv_thread_t *tid); diff --git a/php_uv.c b/php_uv.c index ba12050..52823af 100644 --- a/php_uv.c +++ b/php_uv.c @@ -2779,6 +2779,38 @@ PHP_FUNCTION(uv_rwlock_wrlock) } /* }}} */ +/* {{{ */ +PHP_FUNCTION(uv_rwlock_trywrlock) +{ + uv_rwlock_t *lock; + zval *handle; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "z", &handle) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(lock, uv_rwlock_t *, &handle, -1, PHP_UV_RWLOCK_RESOURCE_NAME, uv_rwlock_handle); + RETURN_LONG(uv_rwlock_trywrlock(lock)); +} +/* }}} */ + +/* {{{ */ +PHP_FUNCTION(uv_rwlock_wrunlock) +{ + uv_rwlock_t *lock; + zval *handle; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "z", &handle) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(lock, uv_rwlock_t *, &handle, -1, PHP_UV_RWLOCK_RESOURCE_NAME, uv_rwlock_handle); + uv_rwlock_wrunlock(lock); +} +/* }}} */ + static zend_function_entry uv_functions[] = { /* general */ @@ -2851,6 +2883,8 @@ static zend_function_entry uv_functions[] = { PHP_FE(uv_rwlock_tryrdlock, NULL) PHP_FE(uv_rwlock_rdunlock, NULL) PHP_FE(uv_rwlock_wrlock, NULL) + PHP_FE(uv_rwlock_trywrlock, NULL) + PHP_FE(uv_rwlock_wrunlock, NULL) /* info */ PHP_FE(uv_loadavg, NULL) PHP_FE(uv_uptime, NULL)