summaryrefslogtreecommitdiff
path: root/pjlib/include/pj
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2005-11-09 15:37:19 +0000
committerBenny Prijono <bennylp@teluu.com>2005-11-09 15:37:19 +0000
commit6e1024262b48b57b771331b8c19e988e43627bd7 (patch)
treea43fdaeb6d7b22cc7afab1633622bf55d39dfd67 /pjlib/include/pj
parentfb9e3b3a6649cc5cbe0c6747cb1918f3be71ba06 (diff)
Rework pjlib++
git-svn-id: http://svn.pjsip.org/repos/pjproject/main@36 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/include/pj')
-rw-r--r--pjlib/include/pj/errno.h5
-rw-r--r--pjlib/include/pj/ioqueue.h50
-rw-r--r--pjlib/include/pj/os.h29
-rw-r--r--pjlib/include/pj/timer.h59
4 files changed, 118 insertions, 25 deletions
diff --git a/pjlib/include/pj/errno.h b/pjlib/include/pj/errno.h
index 11fab3e7..e7b3ab93 100644
--- a/pjlib/include/pj/errno.h
+++ b/pjlib/include/pj/errno.h
@@ -210,6 +210,11 @@ PJ_DECL(pj_str_t) pj_strerror( pj_status_t statcode,
* Invalid operation.
*/
#define PJ_EINVALIDOP (PJ_ERRNO_START_STATUS + 13)
+/**
+ * @hideinitializer
+ * Operation is cancelled.
+ */
+#define PJ_ECANCELLED (PJ_ERRNO_START_STATUS + 14)
/** @} */ /* pj_errnum */
diff --git a/pjlib/include/pj/ioqueue.h b/pjlib/include/pj/ioqueue.h
index 1ecec1b4..c44b7ced 100644
--- a/pjlib/include/pj/ioqueue.h
+++ b/pjlib/include/pj/ioqueue.h
@@ -297,14 +297,19 @@ PJ_DECL(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
/**
* Unregister from the I/O Queue framework. Caller must make sure that
- * the key doesn't have any pending operation before calling this function,
- * or otherwise the behaviour is undefined (either callback will be called
- * later when the data is sent/received, or the callback will not be called,
- * or even something else).
+ * the key doesn't have any pending operations before calling this function,
+ * by calling #pj_ioqueue_is_pending() for all previously submitted
+ * operations except asynchronous connect, and if necessary call
+ * #pj_ioqueue_post_completion() to cancel the pending operations.
+ *
+ * Note that asynchronous connect operation will automatically be
+ * cancelled during the unregistration.
*
* @param key The key that was previously obtained from registration.
*
- * @return PJ_SUCCESS on success or the error code.
+ * @return PJ_SUCCESS on success or the error code.
+ *
+ * @see pj_ioqueue_is_pending
*/
PJ_DECL(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key );
@@ -334,6 +339,41 @@ PJ_DECL(pj_status_t) pj_ioqueue_set_user_data( pj_ioqueue_key_t *key,
void *user_data,
void **old_data);
+
+/**
+ * Check if operation is pending on the specified operation key.
+ * The \c op_key must have been submitted as pending operation before,
+ * or otherwise the result is undefined.
+ *
+ * @param key The key.
+ * @param op_key The operation key, previously submitted to any of
+ * the I/O functions and has returned PJ_EPENDING.
+ *
+ * @return Non-zero if operation is still pending.
+ */
+PJ_DECL(pj_bool_t) pj_ioqueue_is_pending( pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key );
+
+
+/**
+ * Post completion status to the specified operation key and call the
+ * appropriate callback. When the callback is called, the number of bytes
+ * received in read/write callback or the status in accept/connect callback
+ * will be set from the \c bytes_status parameter.
+ *
+ * @param key The key.
+ * @param op_key Pending operation key.
+ * @param bytes_status Number of bytes or status to be set. A good value
+ * to put here is -PJ_ECANCELLED.
+ *
+ * @return PJ_SUCCESS if completion status has been successfully
+ * sent.
+ */
+PJ_DECL(pj_status_t) pj_ioqueue_post_completion( pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
+ pj_ssize_t bytes_status );
+
+
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP != 0
/**
diff --git a/pjlib/include/pj/os.h b/pjlib/include/pj/os.h
index 536992f2..a1fef6b8 100644
--- a/pjlib/include/pj/os.h
+++ b/pjlib/include/pj/os.h
@@ -324,12 +324,30 @@ PJ_DECL(pj_atomic_value_t) pj_atomic_get(pj_atomic_t *atomic_var);
*/
PJ_DECL(void) pj_atomic_inc(pj_atomic_t *atomic_var);
+/**
+ * Increment the value of an atomic type and get the result.
+ *
+ * @param atomic_var the atomic variable.
+ *
+ * @return The incremented value.
+ */
+PJ_DECL(pj_atomic_value_t) pj_atomic_inc_and_get(pj_atomic_t *atomic_var);
+
/**
* Decrement the value of an atomic type.
*
* @param atomic_var the atomic variable.
*/
PJ_DECL(void) pj_atomic_dec(pj_atomic_t *atomic_var);
+
+/**
+ * Decrement the value of an atomic type and get the result.
+ *
+ * @param atomic_var the atomic variable.
+ *
+ * @return The decremented value.
+ */
+PJ_DECL(pj_atomic_value_t) pj_atomic_dec_and_get(pj_atomic_t *atomic_var);
/**
* Add a value to an atomic type.
@@ -339,6 +357,17 @@ PJ_DECL(void) pj_atomic_dec(pj_atomic_t *atomic_var);
*/
PJ_DECL(void) pj_atomic_add( pj_atomic_t *atomic_var,
pj_atomic_value_t value);
+
+/**
+ * Add a value to an atomic type and get the result.
+ *
+ * @param atomic_var The atomic variable.
+ * @param value Value to be added.
+ *
+ * @return The result after the addition.
+ */
+PJ_DECL(pj_atomic_value_t) pj_atomic_add_and_get( pj_atomic_t *atomic_var,
+ pj_atomic_value_t value);
/**
* @}
diff --git a/pjlib/include/pj/timer.h b/pjlib/include/pj/timer.h
index 3f1402ab..e8772f22 100644
--- a/pjlib/include/pj/timer.h
+++ b/pjlib/include/pj/timer.h
@@ -110,18 +110,6 @@ struct pj_timer_entry
/**
- * Default flag for timer heap, indicates that synchronization will be
- * used.
- */
-#define PJ_TIMER_HEAP_SYNCHRONIZE (0)
-
-/**
- * Flag to indicate that thread synchronization is NOT needed for the
- * timer heap.
- */
-#define PJ_TIMER_HEAP_NO_SYNCHRONIZE (1)
-
-/**
* Calculate memory size required to create a timer heap.
*
* @param count Number of timer entries to be supported.
@@ -140,16 +128,45 @@ PJ_DECL(pj_size_t) pj_timer_heap_mem_size(pj_size_t count);
* @param count The maximum number of timer entries to be supported
* initially. If the application registers more entries
* during runtime, then the timer heap will resize.
- * @param flag Creation flag, currently only PJ_TIMER_HEAP_NO_SYNCHRONIZE
- * is recognized..
* @param ht Pointer to receive the created timer heap.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_timer_heap_create( pj_pool_t *pool,
pj_size_t count,
- unsigned flag,
pj_timer_heap_t **ht);
+
+/**
+ * Destroy the timer heap.
+ *
+ * @param ht The timer heap.
+ */
+PJ_DECL(void) pj_timer_heap_destroy( pj_timer_heap_t *ht );
+
+
+/**
+ * Set lock object to be used by the timer heap. By default, the timer heap
+ * uses dummy synchronization.
+ *
+ * @param ht The timer heap.
+ * @param lock The lock object to be used for synchronization.
+ * @param auto_del If nonzero, the lock object will be destroyed when
+ * the timer heap is destroyed.
+ */
+PJ_DECL(void) pj_timer_heap_set_lock( pj_timer_heap_t *ht,
+ pj_lock_t *lock,
+ pj_bool_t auto_del );
+
+/**
+ * Set maximum number of timed out entries to process in a single poll.
+ *
+ * @param ht The timer heap.
+ * @param count Number of entries.
+ *
+ * @return The old number.
+ */
+PJ_DECL(unsigned) pj_timer_heap_set_max_timed_out_per_poll(pj_timer_heap_t *ht,
+ unsigned count );
/**
* Initialize a timer entry. Application should call this function at least
@@ -215,19 +232,21 @@ PJ_DECL(pj_size_t) pj_timer_heap_count( pj_timer_heap_t *ht );
* @return PJ_SUCCESS, or PJ_ENOTFOUND if no entry is scheduled.
*/
PJ_DECL(pj_status_t) pj_timer_heap_earliest_time( pj_timer_heap_t *ht,
- pj_time_val *timeval);
+ pj_time_val *timeval);
/**
* Poll the timer heap, check for expired timers and call the callback for
* each of the expired timers.
*
- * @param ht The timer heap.
+ * @param ht The timer heap.
* @param next_delay If this parameter is not NULL, it will be filled up with
* the time delay until the next timer elapsed, or -1 in
- * the sec part if no entry exist.
- * @return The number of timers expired.
+ * the sec part if no entry exist.
+ *
+ * @return The number of timers expired.
*/
-PJ_DECL(int) pj_timer_heap_poll( pj_timer_heap_t *ht, pj_time_val *next_delay);
+PJ_DECL(unsigned) pj_timer_heap_poll( pj_timer_heap_t *ht,
+ pj_time_val *next_delay);
/**
* @}