diff options
Diffstat (limited to 'pjlib/include/pj')
-rw-r--r-- | pjlib/include/pj/assert.h | 20 | ||||
-rw-r--r-- | pjlib/include/pj/os.h | 69 | ||||
-rw-r--r-- | pjlib/include/pj/sock.h | 4 | ||||
-rw-r--r-- | pjlib/include/pj/types.h | 3 |
4 files changed, 94 insertions, 2 deletions
diff --git a/pjlib/include/pj/assert.h b/pjlib/include/pj/assert.h index 5a842477..6814e4cd 100644 --- a/pjlib/include/pj/assert.h +++ b/pjlib/include/pj/assert.h @@ -67,6 +67,26 @@ # define PJ_ASSERT_RETURN(expr,retval) pj_assert(expr) #endif +/** + * @hideinitializer + * If #PJ_ENABLE_EXTRA_CHECK is declared and non-zero, then + * #PJ_ASSERT_ON_FAIL macro will evaluate the expression in @a expr during + * run-time. If the expression yields false, assertion will be triggered + * and @a exec_on_fail will be executed. + * + * If #PJ_ENABLE_EXTRA_CHECK is not declared or is zero, then no run-time + * checking will be performed. The macro simply evaluates to pj_assert(expr). + */ +#if defined(PJ_ENABLE_EXTRA_CHECK) && PJ_ENABLE_EXTRA_CHECK != 0 +# define PJ_ASSERT_ON_FAIL(expr,exec_on_fail) \ + do { \ + pj_assert(expr); \ + if (!(expr)) exec_on_fail; \ + } while (0) +#else +# define PJ_ASSERT_ON_FAIL(expr,exec_on_fail) pj_assert(expr) +#endif + /** @} */ #endif /* __PJ_ASSERT_H__ */ diff --git a/pjlib/include/pj/os.h b/pjlib/include/pj/os.h index 2917a2ab..8c04364d 100644 --- a/pjlib/include/pj/os.h +++ b/pjlib/include/pj/os.h @@ -507,6 +507,75 @@ PJ_DECL(pj_status_t) pj_mutex_destroy(pj_mutex_t *mutex); /////////////////////////////////////////////////////////////////////////////// /** + * @defgroup PJ_RW_MUTEX Reader/Writer Mutex + * @ingroup PJ_OS + * @{ + * Reader/writer mutex is a classic synchronization object where multiple + * readers can acquire the mutex, but only a single writer can acquire the + * mutex. + */ +typedef struct pj_rwmutex_t pj_rwmutex_t; + +/** + * Create reader/writer mutex. + * + * @param pool Pool to allocate memory for the mutex. + * @param name Name to be assigned to the mutex. + * @param mutex Pointer to receive the newly created mutex. + * + * @return PJ_SUCCESS on success, or the error code. + */ +PJ_DECL(pj_status_t) pj_rwmutex_create(pj_pool_t *pool, const char *name, + pj_rwmutex_t **mutex); + +/** + * Lock the mutex for reading. + * + * @param mutex The mutex. + * @return PJ_SUCCESS on success, or the error code. + */ +PJ_DECL(pj_status_t) pj_rwmutex_lock_read(pj_rwmutex_t *mutex); + +/** + * Lock the mutex for writing. + * + * @param mutex The mutex. + * @return PJ_SUCCESS on success, or the error code. + */ +PJ_DECL(pj_status_t) pj_rwmutex_lock_write(pj_rwmutex_t *mutex); + +/** + * Release read lock. + * + * @param mutex The mutex. + * @return PJ_SUCCESS on success, or the error code. + */ +PJ_DECL(pj_status_t) pj_rwmutex_unlock_read(pj_rwmutex_t *mutex); + +/** + * Release write lock. + * + * @param mutex The mutex. + * @return PJ_SUCCESS on success, or the error code. + */ +PJ_DECL(pj_status_t) pj_rwmutex_unlock_write(pj_rwmutex_t *mutex); + +/** + * Destroy reader/writer mutex. + * + * @param mutex The mutex. + * @return PJ_SUCCESS on success, or the error code. + */ +PJ_DECL(pj_status_t) pj_rwmutex_destroy(pj_rwmutex_t *mutex); + + +/** + * @} + */ + + +/////////////////////////////////////////////////////////////////////////////// +/** * @defgroup PJ_CRIT_SEC Critical sections. * @ingroup PJ_OS * @{ diff --git a/pjlib/include/pj/sock.h b/pjlib/include/pj/sock.h index 02d88c1e..89883495 100644 --- a/pjlib/include/pj/sock.h +++ b/pjlib/include/pj/sock.h @@ -176,13 +176,13 @@ typedef struct pj_in_addr /** * This structure describes Internet socket address. */ -typedef struct pj_sockaddr_in +struct pj_sockaddr_in { pj_uint16_t sin_family; /**< Address family. */ pj_uint16_t sin_port; /**< Transport layer port number. */ pj_in_addr sin_addr; /**< IP address. */ char sin_zero[8]; /**< Padding. */ -} pj_sockaddr_in; +}; /** diff --git a/pjlib/include/pj/types.h b/pjlib/include/pj/types.h index 62e2c0f4..0099255f 100644 --- a/pjlib/include/pj/types.h +++ b/pjlib/include/pj/types.h @@ -218,6 +218,9 @@ typedef long pj_sock_t; /** Generic socket address. */ typedef void pj_sockaddr_t; +/** Forward declaration. */ +typedef struct pj_sockaddr_in pj_sockaddr_in; + /** Color type. */ typedef unsigned int pj_color_t; |