[ofa-general] [PATCH] complib: indentation changes
Sasha Khapyorsky
sashak at voltaire.com
Tue Aug 14 10:13:05 PDT 2007
Formatted with opensm/osm_indent
(indent -npro -kr -i8 -ts8 -sob -l80 -ss -ncs)
Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
opensm/complib/cl_complib.c | 37 +-
opensm/complib/cl_dispatcher.c | 526 +++++++--------
opensm/complib/cl_event.c | 144 ++---
opensm/complib/cl_event_wheel.c | 1090 +++++++++++++++----------------
opensm/complib/cl_list.c | 545 +++++++---------
opensm/complib/cl_log.c | 68 +--
opensm/complib/cl_map.c | 1369 +++++++++++++++++----------------------
opensm/complib/cl_pool.c | 544 ++++++++--------
opensm/complib/cl_ptr_vector.c | 277 ++++-----
opensm/complib/cl_spinlock.c | 65 +--
opensm/complib/cl_statustext.c | 5 +-
opensm/complib/cl_thread.c | 88 ++--
opensm/complib/cl_threadpool.c | 53 +-
opensm/complib/cl_timer.c | 594 ++++++++---------
opensm/complib/cl_vector.c | 420 ++++++-------
opensm/complib/ib_statustext.c | 22 +-
16 files changed, 2681 insertions(+), 3166 deletions(-)
diff --git a/opensm/complib/cl_complib.c b/opensm/complib/cl_complib.c
index 0677544..b9aca19 100644
--- a/opensm/complib/cl_complib.c
+++ b/opensm/complib/cl_complib.c
@@ -35,7 +35,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <complib/cl_types.h>
#include <complib/cl_debug.h>
@@ -50,48 +50,43 @@
*/
extern
-cl_status_t
-__cl_timer_prov_create( void );
+ cl_status_t __cl_timer_prov_create(void);
extern
-void
-__cl_timer_prov_destroy( void );
+void __cl_timer_prov_destroy(void);
cl_spinlock_t cl_atomic_spinlock;
-void
-complib_init(void)
+void complib_init(void)
{
- cl_status_t status = CL_SUCCESS;
+ cl_status_t status = CL_SUCCESS;
status = cl_spinlock_init(&cl_atomic_spinlock);
if (status != CL_SUCCESS)
goto _error;
status = __cl_timer_prov_create();
- if( status != CL_SUCCESS)
+ if (status != CL_SUCCESS)
goto _error;
return;
- _error:
- cl_msg_out( "__init: failed to create complib (%s)\n",
- CL_STATUS_MSG( status ) );
+ _error:
+ cl_msg_out("__init: failed to create complib (%s)\n",
+ CL_STATUS_MSG(status));
exit(1);
}
-void
-complib_exit(void)
+void complib_exit(void)
{
- __cl_timer_prov_destroy();
- cl_spinlock_destroy(&cl_atomic_spinlock);
+ __cl_timer_prov_destroy();
+ cl_spinlock_destroy(&cl_atomic_spinlock);
}
-boolean_t
-cl_is_debug( void )
+boolean_t cl_is_debug(void)
{
#if defined( _DEBUG_ )
- return TRUE;
+ return TRUE;
#else
- return FALSE;
-#endif /* defined( _DEBUG_ ) */
+ return FALSE;
+#endif /* defined( _DEBUG_ ) */
}
diff --git a/opensm/complib/cl_dispatcher.c b/opensm/complib/cl_dispatcher.c
index 4a1960c..1d865d5 100644
--- a/opensm/complib/cl_dispatcher.c
+++ b/opensm/complib/cl_dispatcher.c
@@ -45,7 +45,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <complib/cl_dispatcher.h>
@@ -76,330 +76,306 @@
Returns:
None
********************************************************************/
-void
-__cl_disp_worker(
- IN void* context )
+void __cl_disp_worker(IN void *context)
{
- cl_disp_msg_t *p_msg;
- cl_dispatcher_t *p_disp = (cl_dispatcher_t*)context;
-
- cl_spinlock_acquire( &p_disp->lock );
-
- /* Process the FIFO until we drain it dry. */
- while( cl_qlist_count( &p_disp->msg_fifo ) )
- {
- /* Pop the message at the head from the FIFO. */
- p_msg = (cl_disp_msg_t*)cl_qlist_remove_head( &p_disp->msg_fifo );
-
- /* we track the tim ethe last message spent in the queue */
- p_disp->last_msg_queue_time_us = cl_get_time_stamp() - p_msg->in_time;
-
- /*
- * Release the spinlock while the message is processed.
- * The user's callback may reenter the dispatcher
- * and cause the lock to be reaquired.
- */
- cl_spinlock_release( &p_disp->lock );
- p_msg->p_dest_reg->pfn_rcv_callback(
- (void*)p_msg->p_dest_reg->context, (void*)p_msg->p_data );
-
- cl_atomic_dec( &p_msg->p_dest_reg->ref_cnt );
-
- /* The client has seen the data. Notify the sender as appropriate. */
- if( p_msg->pfn_xmt_callback )
- {
- p_msg->pfn_xmt_callback( (void*)p_msg->context,
- (void*)p_msg->p_data );
- cl_atomic_dec( &p_msg->p_src_reg->ref_cnt );
- }
-
- /* Grab the lock for the next iteration through the list. */
- cl_spinlock_acquire(&p_disp->lock);
-
- /* Return this message to the pool. */
- cl_qpool_put( &p_disp->msg_pool, (cl_pool_item_t *)p_msg );
- }
-
- cl_spinlock_release( &p_disp->lock );
+ cl_disp_msg_t *p_msg;
+ cl_dispatcher_t *p_disp = (cl_dispatcher_t *) context;
+
+ cl_spinlock_acquire(&p_disp->lock);
+
+ /* Process the FIFO until we drain it dry. */
+ while (cl_qlist_count(&p_disp->msg_fifo)) {
+ /* Pop the message at the head from the FIFO. */
+ p_msg =
+ (cl_disp_msg_t *) cl_qlist_remove_head(&p_disp->msg_fifo);
+
+ /* we track the tim ethe last message spent in the queue */
+ p_disp->last_msg_queue_time_us =
+ cl_get_time_stamp() - p_msg->in_time;
+
+ /*
+ * Release the spinlock while the message is processed.
+ * The user's callback may reenter the dispatcher
+ * and cause the lock to be reaquired.
+ */
+ cl_spinlock_release(&p_disp->lock);
+ p_msg->p_dest_reg->pfn_rcv_callback((void *)p_msg->p_dest_reg->
+ context,
+ (void *)p_msg->p_data);
+
+ cl_atomic_dec(&p_msg->p_dest_reg->ref_cnt);
+
+ /* The client has seen the data. Notify the sender as appropriate. */
+ if (p_msg->pfn_xmt_callback) {
+ p_msg->pfn_xmt_callback((void *)p_msg->context,
+ (void *)p_msg->p_data);
+ cl_atomic_dec(&p_msg->p_src_reg->ref_cnt);
+ }
+
+ /* Grab the lock for the next iteration through the list. */
+ cl_spinlock_acquire(&p_disp->lock);
+
+ /* Return this message to the pool. */
+ cl_qpool_put(&p_disp->msg_pool, (cl_pool_item_t *) p_msg);
+ }
+
+ cl_spinlock_release(&p_disp->lock);
}
/********************************************************************
********************************************************************/
-void
-cl_disp_construct(
- IN cl_dispatcher_t* const p_disp )
+void cl_disp_construct(IN cl_dispatcher_t * const p_disp)
{
- CL_ASSERT( p_disp );
+ CL_ASSERT(p_disp);
- cl_qlist_init( &p_disp->reg_list );
- cl_ptr_vector_construct( &p_disp->reg_vec );
- cl_qlist_init( &p_disp->msg_fifo );
- cl_spinlock_construct( &p_disp->lock );
- cl_qpool_construct( &p_disp->msg_pool );
+ cl_qlist_init(&p_disp->reg_list);
+ cl_ptr_vector_construct(&p_disp->reg_vec);
+ cl_qlist_init(&p_disp->msg_fifo);
+ cl_spinlock_construct(&p_disp->lock);
+ cl_qpool_construct(&p_disp->msg_pool);
}
/********************************************************************
********************************************************************/
-void
-cl_disp_shutdown(
- IN cl_dispatcher_t* const p_disp )
+void cl_disp_shutdown(IN cl_dispatcher_t * const p_disp)
{
- CL_ASSERT( p_disp );
+ CL_ASSERT(p_disp);
- /* Stop the thread pool. */
- cl_thread_pool_destroy( &p_disp->worker_threads );
+ /* Stop the thread pool. */
+ cl_thread_pool_destroy(&p_disp->worker_threads);
- /* Process all outstanding callbacks. */
- __cl_disp_worker( p_disp );
+ /* Process all outstanding callbacks. */
+ __cl_disp_worker(p_disp);
- /* Free all registration info. */
- while( !cl_is_qlist_empty( &p_disp->reg_list ) )
- free( cl_qlist_remove_head( &p_disp->reg_list ) );
+ /* Free all registration info. */
+ while (!cl_is_qlist_empty(&p_disp->reg_list))
+ free(cl_qlist_remove_head(&p_disp->reg_list));
}
/********************************************************************
********************************************************************/
-void
-cl_disp_destroy(
- IN cl_dispatcher_t* const p_disp )
+void cl_disp_destroy(IN cl_dispatcher_t * const p_disp)
{
- CL_ASSERT( p_disp );
+ CL_ASSERT(p_disp);
- cl_spinlock_destroy( &p_disp->lock );
- /* Destroy the message pool */
- cl_qpool_destroy( &p_disp->msg_pool );
- /* Destroy the pointer vector of registrants. */
- cl_ptr_vector_destroy( &p_disp->reg_vec );
+ cl_spinlock_destroy(&p_disp->lock);
+ /* Destroy the message pool */
+ cl_qpool_destroy(&p_disp->msg_pool);
+ /* Destroy the pointer vector of registrants. */
+ cl_ptr_vector_destroy(&p_disp->reg_vec);
}
/********************************************************************
********************************************************************/
cl_status_t
-cl_disp_init(
- IN cl_dispatcher_t* const p_disp,
- IN const uint32_t thread_count,
- IN const char* const name )
+cl_disp_init(IN cl_dispatcher_t * const p_disp,
+ IN const uint32_t thread_count, IN const char *const name)
{
- cl_status_t status;
-
- CL_ASSERT( p_disp );
-
- cl_disp_construct( p_disp );
-
- status = cl_spinlock_init( &p_disp->lock );
- if( status != CL_SUCCESS )
- {
- cl_disp_destroy( p_disp );
- return( status );
- }
-
- /* Specify no upper limit to the number of messages in the pool */
- status = cl_qpool_init( &p_disp->msg_pool, CL_DISP_INITIAL_MSG_COUNT,
- 0, CL_DISP_MSG_GROW_SIZE, sizeof(cl_disp_msg_t), NULL,
- NULL, NULL );
- if( status != CL_SUCCESS )
- {
- cl_disp_destroy( p_disp );
- return( status );
- }
-
- status = cl_ptr_vector_init( &p_disp->reg_vec, CL_DISP_INITIAL_REG_COUNT,
- CL_DISP_REG_GROW_SIZE );
- if( status != CL_SUCCESS )
- {
- cl_disp_destroy( p_disp );
- return( status );
- }
-
- status = cl_thread_pool_init( &p_disp->worker_threads, thread_count,
- __cl_disp_worker, p_disp, name );
- if( status != CL_SUCCESS )
- cl_disp_destroy( p_disp );
-
- return( status );
+ cl_status_t status;
+
+ CL_ASSERT(p_disp);
+
+ cl_disp_construct(p_disp);
+
+ status = cl_spinlock_init(&p_disp->lock);
+ if (status != CL_SUCCESS) {
+ cl_disp_destroy(p_disp);
+ return (status);
+ }
+
+ /* Specify no upper limit to the number of messages in the pool */
+ status = cl_qpool_init(&p_disp->msg_pool, CL_DISP_INITIAL_MSG_COUNT,
+ 0, CL_DISP_MSG_GROW_SIZE, sizeof(cl_disp_msg_t),
+ NULL, NULL, NULL);
+ if (status != CL_SUCCESS) {
+ cl_disp_destroy(p_disp);
+ return (status);
+ }
+
+ status = cl_ptr_vector_init(&p_disp->reg_vec, CL_DISP_INITIAL_REG_COUNT,
+ CL_DISP_REG_GROW_SIZE);
+ if (status != CL_SUCCESS) {
+ cl_disp_destroy(p_disp);
+ return (status);
+ }
+
+ status = cl_thread_pool_init(&p_disp->worker_threads, thread_count,
+ __cl_disp_worker, p_disp, name);
+ if (status != CL_SUCCESS)
+ cl_disp_destroy(p_disp);
+
+ return (status);
}
/********************************************************************
********************************************************************/
cl_disp_reg_handle_t
-cl_disp_register(
- IN cl_dispatcher_t* const p_disp,
- IN const cl_disp_msgid_t msg_id,
- IN cl_pfn_msgrcv_cb_t pfn_callback OPTIONAL,
- IN const void* const context OPTIONAL )
+cl_disp_register(IN cl_dispatcher_t * const p_disp,
+ IN const cl_disp_msgid_t msg_id,
+ IN cl_pfn_msgrcv_cb_t pfn_callback OPTIONAL,
+ IN const void *const context OPTIONAL)
{
- cl_disp_reg_info_t *p_reg;
- cl_status_t status;
-
- CL_ASSERT( p_disp );
-
- /* Check that the requested registrant ID is available. */
- cl_spinlock_acquire( &p_disp->lock );
- if( (msg_id != CL_DISP_MSGID_NONE ) &&
- (msg_id < cl_ptr_vector_get_size( &p_disp->reg_vec )) &&
- (cl_ptr_vector_get( &p_disp->reg_vec, msg_id )) )
- {
- cl_spinlock_release( &p_disp->lock );
- return( NULL );
- }
-
- /* Get a registration info from the pool. */
- p_reg = (cl_disp_reg_info_t*)malloc( sizeof(cl_disp_reg_info_t) );
- if( !p_reg )
- {
- cl_spinlock_release( &p_disp->lock );
- return( NULL );
- }
- else
- {
- memset( p_reg, 0, sizeof(cl_disp_reg_info_t) );
- }
-
- p_reg->p_disp = p_disp;
- p_reg->ref_cnt = 0;
- p_reg->pfn_rcv_callback = pfn_callback;
- p_reg->context = context;
- p_reg->msg_id = msg_id;
-
- /* Insert the registration in the list. */
- cl_qlist_insert_tail( &p_disp->reg_list, (cl_list_item_t*)p_reg );
-
- /* Set the array entry to the registrant. */
- /* The ptr_vector grow automatically as necessary. */
- if( msg_id != CL_DISP_MSGID_NONE )
- {
- status = cl_ptr_vector_set( &p_disp->reg_vec, msg_id, p_reg );
- if( status != CL_SUCCESS )
- {
- free( p_reg );
- cl_spinlock_release( &p_disp->lock );
- return( NULL );
- }
- }
-
- cl_spinlock_release( &p_disp->lock );
-
- return( p_reg );
+ cl_disp_reg_info_t *p_reg;
+ cl_status_t status;
+
+ CL_ASSERT(p_disp);
+
+ /* Check that the requested registrant ID is available. */
+ cl_spinlock_acquire(&p_disp->lock);
+ if ((msg_id != CL_DISP_MSGID_NONE) &&
+ (msg_id < cl_ptr_vector_get_size(&p_disp->reg_vec)) &&
+ (cl_ptr_vector_get(&p_disp->reg_vec, msg_id))) {
+ cl_spinlock_release(&p_disp->lock);
+ return (NULL);
+ }
+
+ /* Get a registration info from the pool. */
+ p_reg = (cl_disp_reg_info_t *) malloc(sizeof(cl_disp_reg_info_t));
+ if (!p_reg) {
+ cl_spinlock_release(&p_disp->lock);
+ return (NULL);
+ } else {
+ memset(p_reg, 0, sizeof(cl_disp_reg_info_t));
+ }
+
+ p_reg->p_disp = p_disp;
+ p_reg->ref_cnt = 0;
+ p_reg->pfn_rcv_callback = pfn_callback;
+ p_reg->context = context;
+ p_reg->msg_id = msg_id;
+
+ /* Insert the registration in the list. */
+ cl_qlist_insert_tail(&p_disp->reg_list, (cl_list_item_t *) p_reg);
+
+ /* Set the array entry to the registrant. */
+ /* The ptr_vector grow automatically as necessary. */
+ if (msg_id != CL_DISP_MSGID_NONE) {
+ status = cl_ptr_vector_set(&p_disp->reg_vec, msg_id, p_reg);
+ if (status != CL_SUCCESS) {
+ free(p_reg);
+ cl_spinlock_release(&p_disp->lock);
+ return (NULL);
+ }
+ }
+
+ cl_spinlock_release(&p_disp->lock);
+
+ return (p_reg);
}
/********************************************************************
********************************************************************/
-void
-cl_disp_unregister(
- IN const cl_disp_reg_handle_t handle )
+void cl_disp_unregister(IN const cl_disp_reg_handle_t handle)
{
- cl_disp_reg_info_t *p_reg;
- cl_dispatcher_t *p_disp;
-
- if( handle == CL_DISP_INVALID_HANDLE )
- return;
-
- p_reg = (cl_disp_reg_info_t*)handle;
- p_disp = p_reg->p_disp;
- CL_ASSERT( p_disp );
-
- cl_spinlock_acquire( &p_disp->lock );
- /*
- * Clear the registrant vector entry. This will cause any further
- * post calls to fail.
- */
- if( p_reg->msg_id != CL_DISP_MSGID_NONE )
- {
- CL_ASSERT( p_reg->msg_id < cl_ptr_vector_get_size(&p_disp->reg_vec));
- cl_ptr_vector_set( &p_disp->reg_vec, p_reg->msg_id, NULL );
- }
- cl_spinlock_release( &p_disp->lock );
-
- while( p_reg->ref_cnt > 0)
- cl_thread_suspend( 1 );
-
- cl_spinlock_acquire(&p_disp->lock);
- /* Remove the registrant from the list. */
- cl_qlist_remove_item( &p_disp->reg_list, (cl_list_item_t*)p_reg );
- /* Return the registration info to the pool */
- free( p_reg );
-
- cl_spinlock_release( &p_disp->lock );
+ cl_disp_reg_info_t *p_reg;
+ cl_dispatcher_t *p_disp;
+
+ if (handle == CL_DISP_INVALID_HANDLE)
+ return;
+
+ p_reg = (cl_disp_reg_info_t *) handle;
+ p_disp = p_reg->p_disp;
+ CL_ASSERT(p_disp);
+
+ cl_spinlock_acquire(&p_disp->lock);
+ /*
+ * Clear the registrant vector entry. This will cause any further
+ * post calls to fail.
+ */
+ if (p_reg->msg_id != CL_DISP_MSGID_NONE) {
+ CL_ASSERT(p_reg->msg_id <
+ cl_ptr_vector_get_size(&p_disp->reg_vec));
+ cl_ptr_vector_set(&p_disp->reg_vec, p_reg->msg_id, NULL);
+ }
+ cl_spinlock_release(&p_disp->lock);
+
+ while (p_reg->ref_cnt > 0)
+ cl_thread_suspend(1);
+
+ cl_spinlock_acquire(&p_disp->lock);
+ /* Remove the registrant from the list. */
+ cl_qlist_remove_item(&p_disp->reg_list, (cl_list_item_t *) p_reg);
+ /* Return the registration info to the pool */
+ free(p_reg);
+
+ cl_spinlock_release(&p_disp->lock);
}
/********************************************************************
********************************************************************/
cl_status_t
-cl_disp_post(
- IN const cl_disp_reg_handle_t handle,
- IN const cl_disp_msgid_t msg_id,
- IN const void* const p_data,
- IN cl_pfn_msgdone_cb_t pfn_callback OPTIONAL,
- IN const void* const context OPTIONAL )
+cl_disp_post(IN const cl_disp_reg_handle_t handle,
+ IN const cl_disp_msgid_t msg_id,
+ IN const void *const p_data,
+ IN cl_pfn_msgdone_cb_t pfn_callback OPTIONAL,
+ IN const void *const context OPTIONAL)
{
- cl_disp_reg_info_t *p_src_reg = (cl_disp_reg_info_t*)handle;
- cl_disp_reg_info_t *p_dest_reg;
- cl_dispatcher_t *p_disp;
- cl_disp_msg_t *p_msg;
-
- p_disp = handle->p_disp;
- CL_ASSERT( p_disp );
- CL_ASSERT( msg_id != CL_DISP_MSGID_NONE );
-
- cl_spinlock_acquire( &p_disp->lock );
- /* Check that the recipient exists. */
- p_dest_reg = cl_ptr_vector_get( &p_disp->reg_vec, msg_id );
- if( !p_dest_reg )
- {
- cl_spinlock_release( &p_disp->lock );
- return( CL_NOT_FOUND );
- }
-
- /* Get a free message from the pool. */
- p_msg = (cl_disp_msg_t*)cl_qpool_get( &p_disp->msg_pool );
- if( !p_msg )
- {
- cl_spinlock_release( &p_disp->lock );
- return( CL_INSUFFICIENT_MEMORY );
- }
-
- /* Initialize the message */
- p_msg->p_src_reg = p_src_reg;
- p_msg->p_dest_reg = p_dest_reg;
- p_msg->p_data = p_data;
- p_msg->pfn_xmt_callback = pfn_callback;
- p_msg->context = context;
- p_msg->in_time = cl_get_time_stamp();
-
- /*
- * Increment the sender's reference count if they request a completion
- * notification.
- */
- if( pfn_callback )
- cl_atomic_inc( &p_src_reg->ref_cnt );
-
- /* Increment the recipient's reference count. */
- cl_atomic_inc( &p_dest_reg->ref_cnt );
-
- /* Queue the message in the FIFO. */
- cl_qlist_insert_tail( &p_disp->msg_fifo, (cl_list_item_t *)p_msg );
- cl_spinlock_release( &p_disp->lock );
-
- /* Signal the thread pool that there is work to be done. */
- cl_thread_pool_signal( &p_disp->worker_threads );
- return( CL_SUCCESS );
+ cl_disp_reg_info_t *p_src_reg = (cl_disp_reg_info_t *) handle;
+ cl_disp_reg_info_t *p_dest_reg;
+ cl_dispatcher_t *p_disp;
+ cl_disp_msg_t *p_msg;
+
+ p_disp = handle->p_disp;
+ CL_ASSERT(p_disp);
+ CL_ASSERT(msg_id != CL_DISP_MSGID_NONE);
+
+ cl_spinlock_acquire(&p_disp->lock);
+ /* Check that the recipient exists. */
+ p_dest_reg = cl_ptr_vector_get(&p_disp->reg_vec, msg_id);
+ if (!p_dest_reg) {
+ cl_spinlock_release(&p_disp->lock);
+ return (CL_NOT_FOUND);
+ }
+
+ /* Get a free message from the pool. */
+ p_msg = (cl_disp_msg_t *) cl_qpool_get(&p_disp->msg_pool);
+ if (!p_msg) {
+ cl_spinlock_release(&p_disp->lock);
+ return (CL_INSUFFICIENT_MEMORY);
+ }
+
+ /* Initialize the message */
+ p_msg->p_src_reg = p_src_reg;
+ p_msg->p_dest_reg = p_dest_reg;
+ p_msg->p_data = p_data;
+ p_msg->pfn_xmt_callback = pfn_callback;
+ p_msg->context = context;
+ p_msg->in_time = cl_get_time_stamp();
+
+ /*
+ * Increment the sender's reference count if they request a completion
+ * notification.
+ */
+ if (pfn_callback)
+ cl_atomic_inc(&p_src_reg->ref_cnt);
+
+ /* Increment the recipient's reference count. */
+ cl_atomic_inc(&p_dest_reg->ref_cnt);
+
+ /* Queue the message in the FIFO. */
+ cl_qlist_insert_tail(&p_disp->msg_fifo, (cl_list_item_t *) p_msg);
+ cl_spinlock_release(&p_disp->lock);
+
+ /* Signal the thread pool that there is work to be done. */
+ cl_thread_pool_signal(&p_disp->worker_threads);
+ return (CL_SUCCESS);
}
void
-cl_disp_get_queue_status(
- IN const cl_disp_reg_handle_t handle,
- OUT uint32_t *p_num_queued_msgs,
- OUT uint64_t *p_last_msg_queue_time_ms)
+cl_disp_get_queue_status(IN const cl_disp_reg_handle_t handle,
+ OUT uint32_t * p_num_queued_msgs,
+ OUT uint64_t * p_last_msg_queue_time_ms)
{
- cl_dispatcher_t *p_disp = ((cl_disp_reg_info_t*)handle)->p_disp;
+ cl_dispatcher_t *p_disp = ((cl_disp_reg_info_t *) handle)->p_disp;
- cl_spinlock_acquire( &p_disp->lock );
+ cl_spinlock_acquire(&p_disp->lock);
- if (p_last_msg_queue_time_ms)
- *p_last_msg_queue_time_ms = p_disp->last_msg_queue_time_us/1000;
+ if (p_last_msg_queue_time_ms)
+ *p_last_msg_queue_time_ms =
+ p_disp->last_msg_queue_time_us / 1000;
- if (p_num_queued_msgs)
- *p_num_queued_msgs = cl_qlist_count( &p_disp->msg_fifo );
+ if (p_num_queued_msgs)
+ *p_num_queued_msgs = cl_qlist_count(&p_disp->msg_fifo);
- cl_spinlock_release( &p_disp->lock );
+ cl_spinlock_release(&p_disp->lock);
}
diff --git a/opensm/complib/cl_event.c b/opensm/complib/cl_event.c
index 20f0992..1b38654 100644
--- a/opensm/complib/cl_event.c
+++ b/opensm/complib/cl_event.c
@@ -35,158 +35,142 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <complib/cl_event.h>
#include <complib/cl_debug.h>
#include <sys/time.h>
#include <sys/errno.h>
-void
-cl_event_construct(
- IN cl_event_t *p_event )
+void cl_event_construct(IN cl_event_t * p_event)
{
- CL_ASSERT( p_event );
+ CL_ASSERT(p_event);
- cl_spinlock_construct( &p_event->spinlock );
+ cl_spinlock_construct(&p_event->spinlock);
p_event->state = CL_UNINITIALIZED;
}
cl_status_t
-cl_event_init(
- IN cl_event_t* const p_event,
- IN const boolean_t manual_reset )
+cl_event_init(IN cl_event_t * const p_event, IN const boolean_t manual_reset)
{
- CL_ASSERT( p_event );
+ CL_ASSERT(p_event);
- cl_event_construct( p_event );
+ cl_event_construct(p_event);
- pthread_cond_init( &p_event->condvar, NULL );
- cl_spinlock_init( &p_event->spinlock );
+ pthread_cond_init(&p_event->condvar, NULL);
+ cl_spinlock_init(&p_event->spinlock);
p_event->signaled = FALSE;
p_event->manual_reset = manual_reset;
p_event->state = CL_INITIALIZED;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
-void
-cl_event_destroy(
- IN cl_event_t* const p_event )
+void cl_event_destroy(IN cl_event_t * const p_event)
{
- CL_ASSERT( cl_is_state_valid( p_event->state ) );
+ CL_ASSERT(cl_is_state_valid(p_event->state));
/* Destroy only if the event was constructed */
- if( p_event->state == CL_INITIALIZED )
- {
- pthread_cond_broadcast( &p_event->condvar );
- pthread_cond_destroy( &p_event->condvar );
+ if (p_event->state == CL_INITIALIZED) {
+ pthread_cond_broadcast(&p_event->condvar);
+ pthread_cond_destroy(&p_event->condvar);
}
- cl_spinlock_destroy( &p_event->spinlock );
+ cl_spinlock_destroy(&p_event->spinlock);
p_event->state = CL_UNINITIALIZED;
}
-cl_status_t
-cl_event_signal(
- IN cl_event_t* const p_event )
+cl_status_t cl_event_signal(IN cl_event_t * const p_event)
{
/* Make sure that the event was started */
- CL_ASSERT( p_event->state == CL_INITIALIZED );
+ CL_ASSERT(p_event->state == CL_INITIALIZED);
- cl_spinlock_acquire( &p_event->spinlock );
+ cl_spinlock_acquire(&p_event->spinlock);
p_event->signaled = TRUE;
/* Wake up one or all depending on whether the event is auto-resetting. */
- if( p_event->manual_reset )
- pthread_cond_broadcast( &p_event->condvar );
+ if (p_event->manual_reset)
+ pthread_cond_broadcast(&p_event->condvar);
else
- pthread_cond_signal( &p_event->condvar );
+ pthread_cond_signal(&p_event->condvar);
- cl_spinlock_release( &p_event->spinlock );
+ cl_spinlock_release(&p_event->spinlock);
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
-cl_status_t
-cl_event_reset(
- IN cl_event_t* const p_event )
+cl_status_t cl_event_reset(IN cl_event_t * const p_event)
{
/* Make sure that the event was started */
- CL_ASSERT( p_event->state == CL_INITIALIZED );
+ CL_ASSERT(p_event->state == CL_INITIALIZED);
- cl_spinlock_acquire( &p_event->spinlock );
+ cl_spinlock_acquire(&p_event->spinlock);
p_event->signaled = FALSE;
- cl_spinlock_release( &p_event->spinlock );
+ cl_spinlock_release(&p_event->spinlock);
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
cl_status_t
-cl_event_wait_on(
- IN cl_event_t* const p_event,
- IN const uint32_t wait_us,
- IN const boolean_t interruptible )
+cl_event_wait_on(IN cl_event_t * const p_event,
+ IN const uint32_t wait_us, IN const boolean_t interruptible)
{
- cl_status_t status;
- int wait_ret;
- struct timespec timeout;
- struct timeval curtime;
+ cl_status_t status;
+ int wait_ret;
+ struct timespec timeout;
+ struct timeval curtime;
/* Make sure that the event was Started */
- CL_ASSERT( p_event->state == CL_INITIALIZED );
+ CL_ASSERT(p_event->state == CL_INITIALIZED);
- cl_spinlock_acquire( &p_event->spinlock );
+ cl_spinlock_acquire(&p_event->spinlock);
/* Return immediately if the event is signalled. */
- if( p_event->signaled )
- {
- if( !p_event->manual_reset )
+ if (p_event->signaled) {
+ if (!p_event->manual_reset)
p_event->signaled = FALSE;
- cl_spinlock_release( &p_event->spinlock );
- return( CL_SUCCESS );
+ cl_spinlock_release(&p_event->spinlock);
+ return (CL_SUCCESS);
}
/* If just testing the state, return CL_TIMEOUT. */
- if( wait_us == 0 )
- {
- cl_spinlock_release( &p_event->spinlock );
- return( CL_TIMEOUT );
+ if (wait_us == 0) {
+ cl_spinlock_release(&p_event->spinlock);
+ return (CL_TIMEOUT);
}
- if( wait_us == EVENT_NO_TIMEOUT )
- {
+ if (wait_us == EVENT_NO_TIMEOUT) {
/* Wait for condition variable to be signaled or broadcast. */
- if( pthread_cond_wait( &p_event->condvar, &p_event->spinlock.mutex ) )
+ if (pthread_cond_wait
+ (&p_event->condvar, &p_event->spinlock.mutex))
status = CL_NOT_DONE;
else
status = CL_SUCCESS;
- }
- else
- {
+ } else {
/* Get the current time */
- if( gettimeofday( &curtime, NULL ) == 0 )
- {
+ if (gettimeofday(&curtime, NULL) == 0) {
timeout.tv_sec = curtime.tv_sec + (wait_us / 1000000);
- timeout.tv_nsec = (curtime.tv_usec + (wait_us % 1000000)) * 1000;
-
- wait_ret = pthread_cond_timedwait( &p_event->condvar,
- &p_event->spinlock.mutex, &timeout );
- if( wait_ret == 0 )
- status = (p_event->signaled ? CL_SUCCESS : CL_NOT_DONE);
- else if( wait_ret == ETIMEDOUT )
+ timeout.tv_nsec =
+ (curtime.tv_usec + (wait_us % 1000000)) * 1000;
+
+ wait_ret = pthread_cond_timedwait(&p_event->condvar,
+ &p_event->spinlock.
+ mutex, &timeout);
+ if (wait_ret == 0)
+ status =
+ (p_event->
+ signaled ? CL_SUCCESS : CL_NOT_DONE);
+ else if (wait_ret == ETIMEDOUT)
status = CL_TIMEOUT;
else
status = CL_NOT_DONE;
- }
- else
- {
+ } else {
status = CL_ERROR;
}
}
- if( !p_event->manual_reset )
+ if (!p_event->manual_reset)
p_event->signaled = FALSE;
- cl_spinlock_release( &p_event->spinlock );
- return( status );
+ cl_spinlock_release(&p_event->spinlock);
+ return (status);
}
diff --git a/opensm/complib/cl_event_wheel.c b/opensm/complib/cl_event_wheel.c
index d5f4142..4ad7817 100644
--- a/opensm/complib/cl_event_wheel.c
+++ b/opensm/complib/cl_event_wheel.c
@@ -35,7 +35,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <math.h>
#include <stdlib.h>
@@ -43,547 +43,527 @@
#include <complib/cl_debug.h>
cl_status_t
-__event_will_age_before(
- IN const cl_list_item_t* const p_list_item,
- IN void* context )
+__event_will_age_before(IN const cl_list_item_t * const p_list_item,
+ IN void *context)
{
- uint64_t aging_time = *((uint64_t*)context);
- cl_event_wheel_reg_info_t *p_event;
+ uint64_t aging_time = *((uint64_t *) context);
+ cl_event_wheel_reg_info_t *p_event;
- p_event =
- PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item);
+ p_event =
+ PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item);
- if (p_event->aging_time < aging_time)
- return CL_SUCCESS;
- else
- return CL_NOT_FOUND;
+ if (p_event->aging_time < aging_time)
+ return CL_SUCCESS;
+ else
+ return CL_NOT_FOUND;
}
-void
-__cl_event_wheel_callback( IN void* context )
+void __cl_event_wheel_callback(IN void *context)
{
- cl_event_wheel_t *p_event_wheel = (cl_event_wheel_t *)context;
- cl_list_item_t *p_list_item, *p_prev_event_list_item;
- cl_list_item_t *p_list_next_item;
- cl_event_wheel_reg_info_t *p_event;
- uint64_t current_time;
- uint64_t next_aging_time;
- uint32_t new_timeout;
- cl_status_t cl_status;
-
- OSM_LOG_ENTER( p_event_wheel->p_log, __cl_event_wheel_callback);
-
- /* might be during closing ... */
- if (p_event_wheel->closing)
- {
- goto JustExit;
- }
-
- current_time = cl_get_time_stamp();
-
- if (NULL != p_event_wheel->p_external_lock) {
-
- /* Take care of the order of acquiring locks to avoid the deadlock!
- * The external lock goes first.
- */
- CL_SPINLOCK_ACQUIRE(p_event_wheel->p_external_lock);
- }
-
- CL_SPINLOCK_ACQUIRE(&p_event_wheel->lock);
-
- p_list_item = cl_qlist_head(&p_event_wheel->events_wheel);
- if (p_list_item == cl_qlist_end(&p_event_wheel->events_wheel))
- {
- /* the list is empty - nothing to do */
- goto Exit;
- }
-
- /* we found such an item. get the p_event */
- p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item);
-
- while (p_event->aging_time <= current_time)
- {
- /* this object has aged - invoke it's callback */
- if (p_event->pfn_aged_callback)
- {
- next_aging_time =
- p_event->pfn_aged_callback(
- p_event->key, p_event->num_regs, p_event->context);
- }
- else
- {
- next_aging_time = 0;
- }
-
- /* point to the next object in the wheel */
- p_list_next_item = cl_qlist_next(p_list_item);
-
- /* We need to retire the event if the next aging time passed */
- if (next_aging_time < current_time)
- {
- /* remove it from the map */
- cl_qmap_remove_item(&p_event_wheel->events_map, &(p_event->map_item));
-
- /* pop p_event from the wheel */
- cl_qlist_remove_head(&p_event_wheel->events_wheel);
-
- /* delete the event info object - allocated by cl_event_wheel_reg */
- free(p_event);
- }
- else
- {
- /* update the required aging time */
- p_event->aging_time = next_aging_time;
- p_event->num_regs++;
-
- /* do not remove from the map - but remove from the list head and
- place in the correct position */
-
- /* pop p_event from the wheel */
- cl_qlist_remove_head(&p_event_wheel->events_wheel);
-
- /* find the event that ages just before */
- p_prev_event_list_item = cl_qlist_find_from_tail(
- &p_event_wheel->events_wheel,
- __event_will_age_before,
- &p_event->aging_time);
-
- /* insert just after */
- cl_qlist_insert_next(
- &p_event_wheel->events_wheel,
- p_prev_event_list_item ,
- &p_event->list_item);
-
- /* as we have modified the list - restart from first item: */
- p_list_next_item = cl_qlist_head(&p_event_wheel->events_wheel);
- }
-
- /* advance to next event */
- p_list_item = p_list_next_item;
- if (p_list_item == cl_qlist_end(&p_event_wheel->events_wheel))
- {
- /* the list is empty - nothing to do */
- break;
- }
-
- /* get the p_event */
- p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item);
- }
-
- /* We need to restart the timer only if the list is not empty now */
- if (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel))
- {
- /* get the p_event */
- p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item);
-
- /* start the timer to the timeout [msec] */
- new_timeout = (uint32_t)(((p_event->aging_time - current_time)/1000)+0.5);
- osm_log (p_event_wheel->p_log, OSM_LOG_DEBUG,
- "__cl_event_wheel_callback : "
- "Restart timer in : %u [msec]\n",
- new_timeout);
- cl_status = cl_timer_start(&p_event_wheel->timer, new_timeout);
- if (cl_status != CL_SUCCESS)
- {
- osm_log (p_event_wheel->p_log, OSM_LOG_ERROR,
- "__cl_event_wheel_callback : ERR 6100: "
- "Failed to start timer\n" );
- }
- }
-
- /* release the lock */
- Exit:
- CL_SPINLOCK_RELEASE( &p_event_wheel->lock );
- if (NULL != p_event_wheel->p_external_lock) {
- CL_SPINLOCK_RELEASE(p_event_wheel->p_external_lock);
- }
- JustExit:
- OSM_LOG_EXIT( p_event_wheel->p_log );
+ cl_event_wheel_t *p_event_wheel = (cl_event_wheel_t *) context;
+ cl_list_item_t *p_list_item, *p_prev_event_list_item;
+ cl_list_item_t *p_list_next_item;
+ cl_event_wheel_reg_info_t *p_event;
+ uint64_t current_time;
+ uint64_t next_aging_time;
+ uint32_t new_timeout;
+ cl_status_t cl_status;
+
+ OSM_LOG_ENTER(p_event_wheel->p_log, __cl_event_wheel_callback);
+
+ /* might be during closing ... */
+ if (p_event_wheel->closing) {
+ goto JustExit;
+ }
+
+ current_time = cl_get_time_stamp();
+
+ if (NULL != p_event_wheel->p_external_lock) {
+
+ /* Take care of the order of acquiring locks to avoid the deadlock!
+ * The external lock goes first.
+ */
+ CL_SPINLOCK_ACQUIRE(p_event_wheel->p_external_lock);
+ }
+
+ CL_SPINLOCK_ACQUIRE(&p_event_wheel->lock);
+
+ p_list_item = cl_qlist_head(&p_event_wheel->events_wheel);
+ if (p_list_item == cl_qlist_end(&p_event_wheel->events_wheel)) {
+ /* the list is empty - nothing to do */
+ goto Exit;
+ }
+
+ /* we found such an item. get the p_event */
+ p_event =
+ PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item);
+
+ while (p_event->aging_time <= current_time) {
+ /* this object has aged - invoke it's callback */
+ if (p_event->pfn_aged_callback) {
+ next_aging_time =
+ p_event->pfn_aged_callback(p_event->key,
+ p_event->num_regs,
+ p_event->context);
+ } else {
+ next_aging_time = 0;
+ }
+
+ /* point to the next object in the wheel */
+ p_list_next_item = cl_qlist_next(p_list_item);
+
+ /* We need to retire the event if the next aging time passed */
+ if (next_aging_time < current_time) {
+ /* remove it from the map */
+ cl_qmap_remove_item(&p_event_wheel->events_map,
+ &(p_event->map_item));
+
+ /* pop p_event from the wheel */
+ cl_qlist_remove_head(&p_event_wheel->events_wheel);
+
+ /* delete the event info object - allocated by cl_event_wheel_reg */
+ free(p_event);
+ } else {
+ /* update the required aging time */
+ p_event->aging_time = next_aging_time;
+ p_event->num_regs++;
+
+ /* do not remove from the map - but remove from the list head and
+ place in the correct position */
+
+ /* pop p_event from the wheel */
+ cl_qlist_remove_head(&p_event_wheel->events_wheel);
+
+ /* find the event that ages just before */
+ p_prev_event_list_item =
+ cl_qlist_find_from_tail(&p_event_wheel->
+ events_wheel,
+ __event_will_age_before,
+ &p_event->aging_time);
+
+ /* insert just after */
+ cl_qlist_insert_next(&p_event_wheel->events_wheel,
+ p_prev_event_list_item,
+ &p_event->list_item);
+
+ /* as we have modified the list - restart from first item: */
+ p_list_next_item =
+ cl_qlist_head(&p_event_wheel->events_wheel);
+ }
+
+ /* advance to next event */
+ p_list_item = p_list_next_item;
+ if (p_list_item == cl_qlist_end(&p_event_wheel->events_wheel)) {
+ /* the list is empty - nothing to do */
+ break;
+ }
+
+ /* get the p_event */
+ p_event =
+ PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t,
+ list_item);
+ }
+
+ /* We need to restart the timer only if the list is not empty now */
+ if (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel)) {
+ /* get the p_event */
+ p_event =
+ PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t,
+ list_item);
+
+ /* start the timer to the timeout [msec] */
+ new_timeout =
+ (uint32_t) (((p_event->aging_time - current_time) / 1000) +
+ 0.5);
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "__cl_event_wheel_callback : "
+ "Restart timer in : %u [msec]\n", new_timeout);
+ cl_status = cl_timer_start(&p_event_wheel->timer, new_timeout);
+ if (cl_status != CL_SUCCESS) {
+ osm_log(p_event_wheel->p_log, OSM_LOG_ERROR,
+ "__cl_event_wheel_callback : ERR 6100: "
+ "Failed to start timer\n");
+ }
+ }
+
+ /* release the lock */
+ Exit:
+ CL_SPINLOCK_RELEASE(&p_event_wheel->lock);
+ if (NULL != p_event_wheel->p_external_lock) {
+ CL_SPINLOCK_RELEASE(p_event_wheel->p_external_lock);
+ }
+ JustExit:
+ OSM_LOG_EXIT(p_event_wheel->p_log);
}
/*
* Construct and Initialize
*/
-void
-cl_event_wheel_construct(
- IN cl_event_wheel_t* const p_event_wheel )
+void cl_event_wheel_construct(IN cl_event_wheel_t * const p_event_wheel)
{
- cl_spinlock_construct( &(p_event_wheel->lock) );
- cl_timer_construct( &(p_event_wheel->timer) );
+ cl_spinlock_construct(&(p_event_wheel->lock));
+ cl_timer_construct(&(p_event_wheel->timer));
}
cl_status_t
-cl_event_wheel_init(
- IN cl_event_wheel_t* const p_event_wheel,
- IN osm_log_t *p_log)
+cl_event_wheel_init(IN cl_event_wheel_t * const p_event_wheel,
+ IN osm_log_t * p_log)
{
- cl_status_t cl_status = CL_SUCCESS;
-
- OSM_LOG_ENTER( p_log, cl_event_wheel_init );
-
- /* initialize */
- p_event_wheel->p_log = p_log;
- p_event_wheel->p_external_lock = NULL;
- p_event_wheel->closing = FALSE;
- cl_status = cl_spinlock_init( &(p_event_wheel->lock) );
- if (cl_status != CL_SUCCESS)
- {
- osm_log (p_event_wheel->p_log, OSM_LOG_ERROR,
- "cl_event_wheel_init : ERR 6101: "
- "Failed to initialize cl_spinlock\n" );
- goto Exit;
- }
- cl_qlist_init( &p_event_wheel->events_wheel);
- cl_qmap_init( &p_event_wheel->events_map );
-
- /* init the timer with timeout */
- cl_status = cl_timer_init(&p_event_wheel->timer,
- __cl_event_wheel_callback,
- p_event_wheel ); /* cb context */
-
- if (cl_status != CL_SUCCESS)
- {
- osm_log (p_event_wheel->p_log, OSM_LOG_ERROR,
- "cl_event_wheel_init : ERR 6102: "
- "Failed to initialize cl_timer\n" );
- goto Exit;
- }
- Exit:
- OSM_LOG_EXIT( p_event_wheel->p_log );
- return(cl_status);
+ cl_status_t cl_status = CL_SUCCESS;
+
+ OSM_LOG_ENTER(p_log, cl_event_wheel_init);
+
+ /* initialize */
+ p_event_wheel->p_log = p_log;
+ p_event_wheel->p_external_lock = NULL;
+ p_event_wheel->closing = FALSE;
+ cl_status = cl_spinlock_init(&(p_event_wheel->lock));
+ if (cl_status != CL_SUCCESS) {
+ osm_log(p_event_wheel->p_log, OSM_LOG_ERROR,
+ "cl_event_wheel_init : ERR 6101: "
+ "Failed to initialize cl_spinlock\n");
+ goto Exit;
+ }
+ cl_qlist_init(&p_event_wheel->events_wheel);
+ cl_qmap_init(&p_event_wheel->events_map);
+
+ /* init the timer with timeout */
+ cl_status = cl_timer_init(&p_event_wheel->timer, __cl_event_wheel_callback, p_event_wheel); /* cb context */
+
+ if (cl_status != CL_SUCCESS) {
+ osm_log(p_event_wheel->p_log, OSM_LOG_ERROR,
+ "cl_event_wheel_init : ERR 6102: "
+ "Failed to initialize cl_timer\n");
+ goto Exit;
+ }
+ Exit:
+ OSM_LOG_EXIT(p_event_wheel->p_log);
+ return (cl_status);
}
cl_status_t
-cl_event_wheel_init_ex(
- IN cl_event_wheel_t* const p_event_wheel,
- IN osm_log_t *p_log,
- IN cl_spinlock_t *p_external_lock)
+cl_event_wheel_init_ex(IN cl_event_wheel_t * const p_event_wheel,
+ IN osm_log_t * p_log, IN cl_spinlock_t * p_external_lock)
{
- cl_status_t cl_status;
+ cl_status_t cl_status;
- cl_status = cl_event_wheel_init(p_event_wheel, p_log);
- if (CL_SUCCESS != cl_status)
- {
- return cl_status;
- }
+ cl_status = cl_event_wheel_init(p_event_wheel, p_log);
+ if (CL_SUCCESS != cl_status) {
+ return cl_status;
+ }
- p_event_wheel->p_external_lock = p_external_lock;
- return cl_status;
+ p_event_wheel->p_external_lock = p_external_lock;
+ return cl_status;
}
-void
-cl_event_wheel_dump(
- IN cl_event_wheel_t* const p_event_wheel )
+void cl_event_wheel_dump(IN cl_event_wheel_t * const p_event_wheel)
{
- cl_list_item_t *p_list_item;
- cl_event_wheel_reg_info_t *p_event;
-
- OSM_LOG_ENTER( p_event_wheel->p_log, cl_event_wheel_dump );
-
- p_list_item = cl_qlist_head(&p_event_wheel->events_wheel);
- osm_log( p_event_wheel->p_log, OSM_LOG_DEBUG,
- "cl_event_wheel_dump: "
- "event_wheel ptr:%p\n",
- p_event_wheel);
-
- while (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel) )
- {
- p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item);
- osm_log( p_event_wheel->p_log, OSM_LOG_DEBUG,
- "cl_event_wheel_dump: "
- "Found event key:<0x%"PRIx64">, aging time:%" PRIu64"\n",
- p_event->key, p_event->aging_time );
- p_list_item = cl_qlist_next( p_list_item );
- }
- OSM_LOG_EXIT( p_event_wheel->p_log );
+ cl_list_item_t *p_list_item;
+ cl_event_wheel_reg_info_t *p_event;
+
+ OSM_LOG_ENTER(p_event_wheel->p_log, cl_event_wheel_dump);
+
+ p_list_item = cl_qlist_head(&p_event_wheel->events_wheel);
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "cl_event_wheel_dump: " "event_wheel ptr:%p\n", p_event_wheel);
+
+ while (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel)) {
+ p_event =
+ PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t,
+ list_item);
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "cl_event_wheel_dump: " "Found event key:<0x%" PRIx64
+ ">, aging time:%" PRIu64 "\n", p_event->key,
+ p_event->aging_time);
+ p_list_item = cl_qlist_next(p_list_item);
+ }
+ OSM_LOG_EXIT(p_event_wheel->p_log);
}
-void
-cl_event_wheel_destroy(
- IN cl_event_wheel_t* const p_event_wheel )
+void cl_event_wheel_destroy(IN cl_event_wheel_t * const p_event_wheel)
{
- cl_list_item_t *p_list_item;
- cl_map_item_t *p_map_item;
- cl_event_wheel_reg_info_t *p_event;
-
- OSM_LOG_ENTER( p_event_wheel->p_log, cl_event_wheel_destroy );
-
- /* we need to get a lock */
- CL_SPINLOCK_ACQUIRE( &p_event_wheel->lock );
-
- cl_event_wheel_dump( p_event_wheel);
-
- /* go over all the items in the list and remove them */
- p_list_item = cl_qlist_remove_head(&p_event_wheel->events_wheel);
- while ( p_list_item != cl_qlist_end(&p_event_wheel->events_wheel) )
- {
- p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item);
-
- osm_log( p_event_wheel->p_log, OSM_LOG_DEBUG,
- "cl_event_wheel_destroy: "
- "Found outstanding event key:<0x%"PRIx64">\n",
- p_event->key );
-
- /* remove it from the map */
- p_map_item = &(p_event->map_item);
- cl_qmap_remove_item(&p_event_wheel->events_map, p_map_item);
- free(p_event); /* allocated by cl_event_wheel_reg */
- p_list_item = cl_qlist_remove_head(&p_event_wheel->events_wheel);
- }
-
- /* destroy the timer */
- cl_timer_destroy( &p_event_wheel->timer );
-
- /* destroy the lock (this should be done without releasing - we don't want
- any other run to grab the lock at this point. */
- CL_SPINLOCK_RELEASE( &p_event_wheel->lock );
- cl_spinlock_destroy( &(p_event_wheel->lock) );
-
- OSM_LOG_EXIT( p_event_wheel->p_log );
+ cl_list_item_t *p_list_item;
+ cl_map_item_t *p_map_item;
+ cl_event_wheel_reg_info_t *p_event;
+
+ OSM_LOG_ENTER(p_event_wheel->p_log, cl_event_wheel_destroy);
+
+ /* we need to get a lock */
+ CL_SPINLOCK_ACQUIRE(&p_event_wheel->lock);
+
+ cl_event_wheel_dump(p_event_wheel);
+
+ /* go over all the items in the list and remove them */
+ p_list_item = cl_qlist_remove_head(&p_event_wheel->events_wheel);
+ while (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel)) {
+ p_event =
+ PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t,
+ list_item);
+
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "cl_event_wheel_destroy: "
+ "Found outstanding event key:<0x%" PRIx64 ">\n",
+ p_event->key);
+
+ /* remove it from the map */
+ p_map_item = &(p_event->map_item);
+ cl_qmap_remove_item(&p_event_wheel->events_map, p_map_item);
+ free(p_event); /* allocated by cl_event_wheel_reg */
+ p_list_item =
+ cl_qlist_remove_head(&p_event_wheel->events_wheel);
+ }
+
+ /* destroy the timer */
+ cl_timer_destroy(&p_event_wheel->timer);
+
+ /* destroy the lock (this should be done without releasing - we don't want
+ any other run to grab the lock at this point. */
+ CL_SPINLOCK_RELEASE(&p_event_wheel->lock);
+ cl_spinlock_destroy(&(p_event_wheel->lock));
+
+ OSM_LOG_EXIT(p_event_wheel->p_log);
}
cl_status_t
-cl_event_wheel_reg(
- IN cl_event_wheel_t* const p_event_wheel,
- IN const uint64_t key,
- IN const uint64_t aging_time_usec,
- IN cl_pfn_event_aged_cb_t pfn_callback,
- IN void* const context )
+cl_event_wheel_reg(IN cl_event_wheel_t * const p_event_wheel,
+ IN const uint64_t key,
+ IN const uint64_t aging_time_usec,
+ IN cl_pfn_event_aged_cb_t pfn_callback,
+ IN void *const context)
{
- cl_event_wheel_reg_info_t *p_event;
- uint64_t timeout;
- uint32_t to;
- cl_status_t cl_status = CL_SUCCESS;
- cl_list_item_t *prev_event_list_item;
- cl_map_item_t *p_map_item;
-
- OSM_LOG_ENTER( p_event_wheel->p_log, cl_event_wheel_reg );
-
- /* Get the lock on the manager */
- CL_SPINLOCK_ACQUIRE( &(p_event_wheel->lock) );
-
- cl_event_wheel_dump( p_event_wheel);
-
- /* Make sure such a key does not exists */
- p_map_item = cl_qmap_get( &p_event_wheel->events_map, key );
- if (p_map_item != cl_qmap_end( &p_event_wheel->events_map ))
- {
- osm_log( p_event_wheel->p_log, OSM_LOG_DEBUG,
- "cl_event_wheel_reg: "
- "Already exists key:0x%"PRIx64"\n", key);
-
- /* already there - remove it from the list as it is getting a new time */
- p_event = PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t, map_item);
-
- /* remove the item from the qlist */
- cl_qlist_remove_item( &p_event_wheel->events_wheel, &p_event->list_item );
- /* and the qmap */
- cl_qmap_remove_item( &p_event_wheel->events_map, &p_event->map_item );
- }
- else
- {
- /* make a new one */
- p_event = (cl_event_wheel_reg_info_t *)
- malloc( sizeof (cl_event_wheel_reg_info_t) );
- p_event->num_regs = 0;
- }
-
- p_event->key = key;
- p_event->aging_time = aging_time_usec;
- p_event->pfn_aged_callback = pfn_callback;
- p_event->context = context;
- p_event->num_regs++;
-
- osm_log( p_event_wheel->p_log, OSM_LOG_DEBUG,
- "cl_event_wheel_reg: "
- "Registering event key:0x%"PRIx64" aging in %u [msec]\n",
- p_event->key,
- (uint32_t)((p_event->aging_time - cl_get_time_stamp()) / 1000 ));
-
- /* If the list is empty - need to start the timer */
- if (cl_is_qlist_empty(&p_event_wheel->events_wheel))
- {
- /* Edward Bortnikov 03/29/2003
- * ++TBD Consider moving the timer manipulation behind the list manipulation.
- */
-
- /* calculate the new timeout */
- timeout = (p_event->aging_time - cl_get_time_stamp() + 500) / 1000;
-
- /* stop the timer if it is running */
-
- /* Edward Bortnikov 03/29/2003
- * Don't call cl_timer_stop() because it spins forever.
- * cl_timer_start() will invoke cl_timer_stop() by itself.
- *
- * The problematic scenario is when __cl_event_wheel_callback()
- * is in race condition with this code. It sets timer.in_timer_cb
- * to TRUE and then blocks on p_event_wheel->lock. Following this,
- * the call to cl_timer_stop() hangs. Following this, the whole system
- * enters into a deadlock.
- *
- * cl_timer_stop(&p_event_wheel->timer);
- */
-
- /* The timeout for the cl_timer_start should be given as uint32_t.
- if there is an overflow - warn about it. */
- to = (uint32_t)timeout;
- if ( timeout > (uint32_t)timeout )
- {
- to = 0xffffffff; /* max 32 bit timer */
- osm_log (p_event_wheel->p_log, OSM_LOG_INFO,
- "cl_event_wheel_reg: "
- "timeout requested is too large. Using timeout: %u\n",
- to );
- }
-
- /* start the timer to the timeout [msec] */
- cl_status = cl_timer_start(&p_event_wheel->timer, to);
- if (cl_status != CL_SUCCESS)
- {
- osm_log (p_event_wheel->p_log, OSM_LOG_ERROR,
- "cl_event_wheel_reg : ERR 6103: "
- "Failed to start timer\n" );
- goto Exit;
- }
- }
-
- /* insert the object to the qlist and the qmap */
-
- /* BUT WE MUST INSERT IT IN A SORTED MANNER */
- prev_event_list_item = cl_qlist_find_from_tail(
- &p_event_wheel->events_wheel,
- __event_will_age_before,
- &p_event->aging_time);
-
- cl_qlist_insert_next(
- &p_event_wheel->events_wheel,
- prev_event_list_item ,
- &p_event->list_item);
-
- cl_qmap_insert( &p_event_wheel->events_map, key, &(p_event->map_item));
-
- Exit:
- CL_SPINLOCK_RELEASE( &p_event_wheel->lock );
- OSM_LOG_EXIT( p_event_wheel->p_log );
-
- return cl_status;
+ cl_event_wheel_reg_info_t *p_event;
+ uint64_t timeout;
+ uint32_t to;
+ cl_status_t cl_status = CL_SUCCESS;
+ cl_list_item_t *prev_event_list_item;
+ cl_map_item_t *p_map_item;
+
+ OSM_LOG_ENTER(p_event_wheel->p_log, cl_event_wheel_reg);
+
+ /* Get the lock on the manager */
+ CL_SPINLOCK_ACQUIRE(&(p_event_wheel->lock));
+
+ cl_event_wheel_dump(p_event_wheel);
+
+ /* Make sure such a key does not exists */
+ p_map_item = cl_qmap_get(&p_event_wheel->events_map, key);
+ if (p_map_item != cl_qmap_end(&p_event_wheel->events_map)) {
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "cl_event_wheel_reg: "
+ "Already exists key:0x%" PRIx64 "\n", key);
+
+ /* already there - remove it from the list as it is getting a new time */
+ p_event =
+ PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t,
+ map_item);
+
+ /* remove the item from the qlist */
+ cl_qlist_remove_item(&p_event_wheel->events_wheel,
+ &p_event->list_item);
+ /* and the qmap */
+ cl_qmap_remove_item(&p_event_wheel->events_map,
+ &p_event->map_item);
+ } else {
+ /* make a new one */
+ p_event = (cl_event_wheel_reg_info_t *)
+ malloc(sizeof(cl_event_wheel_reg_info_t));
+ p_event->num_regs = 0;
+ }
+
+ p_event->key = key;
+ p_event->aging_time = aging_time_usec;
+ p_event->pfn_aged_callback = pfn_callback;
+ p_event->context = context;
+ p_event->num_regs++;
+
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "cl_event_wheel_reg: "
+ "Registering event key:0x%" PRIx64 " aging in %u [msec]\n",
+ p_event->key,
+ (uint32_t) ((p_event->aging_time -
+ cl_get_time_stamp()) / 1000));
+
+ /* If the list is empty - need to start the timer */
+ if (cl_is_qlist_empty(&p_event_wheel->events_wheel)) {
+ /* Edward Bortnikov 03/29/2003
+ * ++TBD Consider moving the timer manipulation behind the list manipulation.
+ */
+
+ /* calculate the new timeout */
+ timeout =
+ (p_event->aging_time - cl_get_time_stamp() + 500) / 1000;
+
+ /* stop the timer if it is running */
+
+ /* Edward Bortnikov 03/29/2003
+ * Don't call cl_timer_stop() because it spins forever.
+ * cl_timer_start() will invoke cl_timer_stop() by itself.
+ *
+ * The problematic scenario is when __cl_event_wheel_callback()
+ * is in race condition with this code. It sets timer.in_timer_cb
+ * to TRUE and then blocks on p_event_wheel->lock. Following this,
+ * the call to cl_timer_stop() hangs. Following this, the whole system
+ * enters into a deadlock.
+ *
+ * cl_timer_stop(&p_event_wheel->timer);
+ */
+
+ /* The timeout for the cl_timer_start should be given as uint32_t.
+ if there is an overflow - warn about it. */
+ to = (uint32_t) timeout;
+ if (timeout > (uint32_t) timeout) {
+ to = 0xffffffff; /* max 32 bit timer */
+ osm_log(p_event_wheel->p_log, OSM_LOG_INFO,
+ "cl_event_wheel_reg: "
+ "timeout requested is too large. Using timeout: %u\n",
+ to);
+ }
+
+ /* start the timer to the timeout [msec] */
+ cl_status = cl_timer_start(&p_event_wheel->timer, to);
+ if (cl_status != CL_SUCCESS) {
+ osm_log(p_event_wheel->p_log, OSM_LOG_ERROR,
+ "cl_event_wheel_reg : ERR 6103: "
+ "Failed to start timer\n");
+ goto Exit;
+ }
+ }
+
+ /* insert the object to the qlist and the qmap */
+
+ /* BUT WE MUST INSERT IT IN A SORTED MANNER */
+ prev_event_list_item =
+ cl_qlist_find_from_tail(&p_event_wheel->events_wheel,
+ __event_will_age_before,
+ &p_event->aging_time);
+
+ cl_qlist_insert_next(&p_event_wheel->events_wheel,
+ prev_event_list_item, &p_event->list_item);
+
+ cl_qmap_insert(&p_event_wheel->events_map, key, &(p_event->map_item));
+
+ Exit:
+ CL_SPINLOCK_RELEASE(&p_event_wheel->lock);
+ OSM_LOG_EXIT(p_event_wheel->p_log);
+
+ return cl_status;
}
void
-cl_event_wheel_unreg(
- IN cl_event_wheel_t* const p_event_wheel,
- IN uint64_t key )
+cl_event_wheel_unreg(IN cl_event_wheel_t * const p_event_wheel, IN uint64_t key)
{
- cl_event_wheel_reg_info_t *p_event;
- cl_map_item_t* p_map_item;
-
- OSM_LOG_ENTER( p_event_wheel->p_log, cl_event_wheel_unreg );
-
- osm_log( p_event_wheel->p_log, OSM_LOG_DEBUG,
- "cl_event_wheel_unreg: "
- "Removing key:0x%"PRIx64"\n", key );
-
- CL_SPINLOCK_ACQUIRE( &p_event_wheel->lock );
- p_map_item = cl_qmap_get( &p_event_wheel->events_map, key );
- if (p_map_item != cl_qmap_end( &p_event_wheel->events_map ))
- {
- /* we found such an item. */
- p_event = PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t, map_item);
-
- /* remove the item from the qlist */
- cl_qlist_remove_item( &p_event_wheel->events_wheel, &(p_event->list_item));
- /* remove the item from the qmap */
- cl_qmap_remove_item( &p_event_wheel->events_map, &(p_event->map_item) );
-
- osm_log( p_event_wheel->p_log, OSM_LOG_DEBUG,
- "cl_event_wheel_unreg: "
- "Removed key:0x%"PRIx64"\n", key );
-
- /* free the item */
- free(p_event);
- }
- else
- {
- osm_log( p_event_wheel->p_log, OSM_LOG_DEBUG,
- "cl_event_wheel_unreg: "
- "Did not find key:0x%"PRIx64"\n", key );
- }
-
- CL_SPINLOCK_RELEASE( &p_event_wheel->lock );
- OSM_LOG_EXIT( p_event_wheel->p_log );
+ cl_event_wheel_reg_info_t *p_event;
+ cl_map_item_t *p_map_item;
+
+ OSM_LOG_ENTER(p_event_wheel->p_log, cl_event_wheel_unreg);
+
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "cl_event_wheel_unreg: " "Removing key:0x%" PRIx64 "\n", key);
+
+ CL_SPINLOCK_ACQUIRE(&p_event_wheel->lock);
+ p_map_item = cl_qmap_get(&p_event_wheel->events_map, key);
+ if (p_map_item != cl_qmap_end(&p_event_wheel->events_map)) {
+ /* we found such an item. */
+ p_event =
+ PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t,
+ map_item);
+
+ /* remove the item from the qlist */
+ cl_qlist_remove_item(&p_event_wheel->events_wheel,
+ &(p_event->list_item));
+ /* remove the item from the qmap */
+ cl_qmap_remove_item(&p_event_wheel->events_map,
+ &(p_event->map_item));
+
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "cl_event_wheel_unreg: "
+ "Removed key:0x%" PRIx64 "\n", key);
+
+ /* free the item */
+ free(p_event);
+ } else {
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "cl_event_wheel_unreg: "
+ "Did not find key:0x%" PRIx64 "\n", key);
+ }
+
+ CL_SPINLOCK_RELEASE(&p_event_wheel->lock);
+ OSM_LOG_EXIT(p_event_wheel->p_log);
}
uint32_t
-cl_event_wheel_num_regs(
- IN cl_event_wheel_t* const p_event_wheel,
- IN uint64_t key )
+cl_event_wheel_num_regs(IN cl_event_wheel_t * const p_event_wheel,
+ IN uint64_t key)
{
- cl_event_wheel_reg_info_t *p_event;
- cl_map_item_t* p_map_item;
- uint32_t num_regs = 0;
-
- OSM_LOG_ENTER( p_event_wheel->p_log, cl_event_wheel_num_regs );
-
- /* try to find the key in the map */
- osm_log( p_event_wheel->p_log, OSM_LOG_DEBUG,
- "cl_event_wheel_num_regs: "
- "Looking for key:0x%"PRIx64"\n", key );
-
- CL_SPINLOCK_ACQUIRE( &p_event_wheel->lock );
- p_map_item = cl_qmap_get( &p_event_wheel->events_map, key );
- if (p_map_item != cl_qmap_end( &p_event_wheel->events_map ))
- {
- /* ok so we can simply return it's num_regs */
- p_event = PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t, map_item);
- num_regs = p_event->num_regs;
- }
-
- CL_SPINLOCK_RELEASE( &p_event_wheel->lock );
- OSM_LOG_EXIT( p_event_wheel->p_log );
- return(num_regs);
+ cl_event_wheel_reg_info_t *p_event;
+ cl_map_item_t *p_map_item;
+ uint32_t num_regs = 0;
+
+ OSM_LOG_ENTER(p_event_wheel->p_log, cl_event_wheel_num_regs);
+
+ /* try to find the key in the map */
+ osm_log(p_event_wheel->p_log, OSM_LOG_DEBUG,
+ "cl_event_wheel_num_regs: "
+ "Looking for key:0x%" PRIx64 "\n", key);
+
+ CL_SPINLOCK_ACQUIRE(&p_event_wheel->lock);
+ p_map_item = cl_qmap_get(&p_event_wheel->events_map, key);
+ if (p_map_item != cl_qmap_end(&p_event_wheel->events_map)) {
+ /* ok so we can simply return it's num_regs */
+ p_event =
+ PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t,
+ map_item);
+ num_regs = p_event->num_regs;
+ }
+
+ CL_SPINLOCK_RELEASE(&p_event_wheel->lock);
+ OSM_LOG_EXIT(p_event_wheel->p_log);
+ return (num_regs);
}
#ifdef __CL_EVENT_WHEEL_TEST__
/* Dump out the complete state of the event wheel */
-void __cl_event_wheel_dump(
- IN cl_event_wheel_t* const p_event_wheel)
+void __cl_event_wheel_dump(IN cl_event_wheel_t * const p_event_wheel)
{
- cl_list_item_t *p_list_item;
- cl_map_item_t *p_map_item;
- cl_event_wheel_reg_info_t *p_event;
-
- printf("************** Event Wheel Dump ***********************\n");
- printf("Event Wheel List has %u items:\n",
- cl_qlist_count( &p_event_wheel->events_wheel ));
-
- p_list_item = cl_qlist_head(&p_event_wheel->events_wheel);
- while (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel))
- {
- p_event = PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t, list_item);
- printf("Event key:0x%"PRIx64" Conetxt:%s NumRegs:%u\n",
- p_event->key, (char *)p_event->context, p_event->num_regs);
-
- /* next */
- p_list_item = cl_qlist_next(p_list_item);
- }
-
- printf("Event Map has %u items:\n",
- cl_qmap_count( &p_event_wheel->events_map ));
-
- p_map_item = cl_qmap_head(&p_event_wheel->events_map);
- while (p_map_item != cl_qmap_end(&p_event_wheel->events_map))
- {
- p_event = PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t, map_item);
- printf("Event key:0x%"PRIx64" Conetxt:%s NumRegs:%u\n",
- p_event->key, (char *)p_event->context, p_event->num_regs);
-
- /* next */
- p_map_item = cl_qmap_next(p_map_item);
- }
+ cl_list_item_t *p_list_item;
+ cl_map_item_t *p_map_item;
+ cl_event_wheel_reg_info_t *p_event;
+
+ printf("************** Event Wheel Dump ***********************\n");
+ printf("Event Wheel List has %u items:\n",
+ cl_qlist_count(&p_event_wheel->events_wheel));
+
+ p_list_item = cl_qlist_head(&p_event_wheel->events_wheel);
+ while (p_list_item != cl_qlist_end(&p_event_wheel->events_wheel)) {
+ p_event =
+ PARENT_STRUCT(p_list_item, cl_event_wheel_reg_info_t,
+ list_item);
+ printf("Event key:0x%" PRIx64 " Conetxt:%s NumRegs:%u\n",
+ p_event->key, (char *)p_event->context,
+ p_event->num_regs);
+
+ /* next */
+ p_list_item = cl_qlist_next(p_list_item);
+ }
+
+ printf("Event Map has %u items:\n",
+ cl_qmap_count(&p_event_wheel->events_map));
+
+ p_map_item = cl_qmap_head(&p_event_wheel->events_map);
+ while (p_map_item != cl_qmap_end(&p_event_wheel->events_map)) {
+ p_event =
+ PARENT_STRUCT(p_map_item, cl_event_wheel_reg_info_t,
+ map_item);
+ printf("Event key:0x%" PRIx64 " Conetxt:%s NumRegs:%u\n",
+ p_event->key, (char *)p_event->context,
+ p_event->num_regs);
+
+ /* next */
+ p_map_item = cl_qmap_next(p_map_item);
+ }
}
@@ -591,73 +571,65 @@ void __cl_event_wheel_dump(
/* We assume we pass a text context */
void __test_event_aging(uint64_t key, void *context)
{
- printf("*****************************************************\n");
- printf("Aged key: 0x%"PRIx64" Conetxt:%s\n", key, (char *)context);
+ printf("*****************************************************\n");
+ printf("Aged key: 0x%" PRIx64 " Conetxt:%s\n", key, (char *)context);
}
-int
-main ()
+int main()
{
- osm_log_t log;
- cl_event_wheel_t event_wheel;
- /* uint64_t key; */
-
- /* construct */
- osm_log_construct( &log );
- cl_event_wheel_construct( &event_wheel );
-
- /* init */
- osm_log_init_v2( &log, TRUE, 0xff, NULL, 0, FALSE);
- cl_event_wheel_init( &event_wheel, &log );
-
- /* Start Playing */
- cl_event_wheel_reg( &event_wheel,
- 1, /* key */
- cl_get_time_stamp() + 3000000, /* 3 sec lifetime */
- __test_event_aging, /* cb */
- "The first Aging Event"
- );
-
- cl_event_wheel_reg( &event_wheel,
- 2, /* key */
- cl_get_time_stamp() + 3000000, /* 3 sec lifetime */
- __test_event_aging, /* cb */
- "The Second Aging Event"
- );
-
- cl_event_wheel_reg( &event_wheel,
- 3, /* key */
- cl_get_time_stamp() + 3500000, /* 3 sec lifetime */
- __test_event_aging, /* cb */
- "The Third Aging Event"
- );
-
- __cl_event_wheel_dump(&event_wheel);
-
- sleep(2);
- cl_event_wheel_reg( &event_wheel,
- 2, /* key */
- cl_get_time_stamp() + 8000000, /* 3 sec lifetime */
- __test_event_aging, /* cb */
- "The Second Aging Event Moved"
- );
-
- __cl_event_wheel_dump(&event_wheel);
-
- sleep(1);
- /* remove the third event */
- cl_event_wheel_unreg( &event_wheel,
- 3); /* key */
-
- /* get the number of registrations for the keys */
- printf("Event 1 Registered: %u\n", cl_event_wheel_num_regs(&event_wheel, 1));
- printf("Event 2 Registered: %u\n", cl_event_wheel_num_regs(&event_wheel, 2));
-
- sleep(5);
- /* destroy */
- cl_event_wheel_destroy( &event_wheel );
-
- return(0);
+ osm_log_t log;
+ cl_event_wheel_t event_wheel;
+ /* uint64_t key; */
+
+ /* construct */
+ osm_log_construct(&log);
+ cl_event_wheel_construct(&event_wheel);
+
+ /* init */
+ osm_log_init_v2(&log, TRUE, 0xff, NULL, 0, FALSE);
+ cl_event_wheel_init(&event_wheel, &log);
+
+ /* Start Playing */
+ cl_event_wheel_reg(&event_wheel, 1, /* key */
+ cl_get_time_stamp() + 3000000, /* 3 sec lifetime */
+ __test_event_aging, /* cb */
+ "The first Aging Event");
+
+ cl_event_wheel_reg(&event_wheel, 2, /* key */
+ cl_get_time_stamp() + 3000000, /* 3 sec lifetime */
+ __test_event_aging, /* cb */
+ "The Second Aging Event");
+
+ cl_event_wheel_reg(&event_wheel, 3, /* key */
+ cl_get_time_stamp() + 3500000, /* 3 sec lifetime */
+ __test_event_aging, /* cb */
+ "The Third Aging Event");
+
+ __cl_event_wheel_dump(&event_wheel);
+
+ sleep(2);
+ cl_event_wheel_reg(&event_wheel, 2, /* key */
+ cl_get_time_stamp() + 8000000, /* 3 sec lifetime */
+ __test_event_aging, /* cb */
+ "The Second Aging Event Moved");
+
+ __cl_event_wheel_dump(&event_wheel);
+
+ sleep(1);
+ /* remove the third event */
+ cl_event_wheel_unreg(&event_wheel, 3); /* key */
+
+ /* get the number of registrations for the keys */
+ printf("Event 1 Registered: %u\n",
+ cl_event_wheel_num_regs(&event_wheel, 1));
+ printf("Event 2 Registered: %u\n",
+ cl_event_wheel_num_regs(&event_wheel, 2));
+
+ sleep(5);
+ /* destroy */
+ cl_event_wheel_destroy(&event_wheel);
+
+ return (0);
}
-#endif /* __CL_EVENT_WHEEL_TEST__ */
+#endif /* __CL_EVENT_WHEEL_TEST__ */
diff --git a/opensm/complib/cl_list.c b/opensm/complib/cl_list.c
index d0cef8a..7a25e4b 100644
--- a/opensm/complib/cl_list.c
+++ b/opensm/complib/cl_list.c
@@ -45,7 +45,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <complib/cl_qlist.h>
#include <complib/cl_list.h>
@@ -60,110 +60,102 @@
*******************************************************************************
******************************************************************************/
void
-cl_qlist_insert_array_head(
- IN cl_qlist_t* const p_list,
- IN cl_list_item_t* const p_array,
- IN uint32_t item_count,
- IN const uint32_t item_size )
+cl_qlist_insert_array_head(IN cl_qlist_t * const p_list,
+ IN cl_list_item_t * const p_array,
+ IN uint32_t item_count, IN const uint32_t item_size)
{
- cl_list_item_t *p_item;
+ cl_list_item_t *p_item;
- CL_ASSERT( p_list );
- CL_ASSERT( p_list->state == CL_INITIALIZED );
- CL_ASSERT( p_array );
- CL_ASSERT( item_size >= sizeof(cl_list_item_t) );
- CL_ASSERT( item_count );
+ CL_ASSERT(p_list);
+ CL_ASSERT(p_list->state == CL_INITIALIZED);
+ CL_ASSERT(p_array);
+ CL_ASSERT(item_size >= sizeof(cl_list_item_t));
+ CL_ASSERT(item_count);
/*
* To add items from the array to the list in the same order as
* the elements appear in the array, we add them starting with
* the last one first. Locate the last item.
*/
- p_item = (cl_list_item_t*)(
- (uint8_t*)p_array + (item_size * (item_count - 1)));
+ p_item = (cl_list_item_t *) ((uint8_t *) p_array +
+ (item_size * (item_count - 1)));
/* Continue to add all items to the list. */
- while( item_count-- )
- {
- cl_qlist_insert_head( p_list, p_item );
+ while (item_count--) {
+ cl_qlist_insert_head(p_list, p_item);
/* Get the next object to add to the list. */
- p_item = (cl_list_item_t*)((uint8_t*)p_item - item_size);
+ p_item = (cl_list_item_t *) ((uint8_t *) p_item - item_size);
}
}
void
-cl_qlist_insert_array_tail(
- IN cl_qlist_t* const p_list,
- IN cl_list_item_t* const p_array,
- IN uint32_t item_count,
- IN const uint32_t item_size )
+cl_qlist_insert_array_tail(IN cl_qlist_t * const p_list,
+ IN cl_list_item_t * const p_array,
+ IN uint32_t item_count, IN const uint32_t item_size)
{
- cl_list_item_t *p_item;
+ cl_list_item_t *p_item;
- CL_ASSERT( p_list );
- CL_ASSERT( p_list->state == CL_INITIALIZED );
- CL_ASSERT( p_array );
- CL_ASSERT( item_size >= sizeof(cl_list_item_t) );
- CL_ASSERT( item_count );
+ CL_ASSERT(p_list);
+ CL_ASSERT(p_list->state == CL_INITIALIZED);
+ CL_ASSERT(p_array);
+ CL_ASSERT(item_size >= sizeof(cl_list_item_t));
+ CL_ASSERT(item_count);
/* Set the first item to add to the list. */
p_item = p_array;
/* Continue to add all items to the list. */
- while( item_count-- )
- {
- cl_qlist_insert_tail( p_list, p_item );
+ while (item_count--) {
+ cl_qlist_insert_tail(p_list, p_item);
/* Get the next object to add to the list. */
- p_item = (cl_list_item_t*)((uint8_t*)p_item + item_size);
+ p_item = (cl_list_item_t *) ((uint8_t *) p_item + item_size);
}
}
void
-cl_qlist_insert_list_head(
- IN cl_qlist_t* const p_dest_list,
- IN cl_qlist_t* const p_src_list )
+cl_qlist_insert_list_head(IN cl_qlist_t * const p_dest_list,
+ IN cl_qlist_t * const p_src_list)
{
#if defined( _DEBUG_ )
- cl_list_item_t *p_item;
+ cl_list_item_t *p_item;
#endif
- CL_ASSERT( p_dest_list );
- CL_ASSERT( p_src_list );
- CL_ASSERT( p_dest_list->state == CL_INITIALIZED );
- CL_ASSERT( p_src_list->state == CL_INITIALIZED );
+ CL_ASSERT(p_dest_list);
+ CL_ASSERT(p_src_list);
+ CL_ASSERT(p_dest_list->state == CL_INITIALIZED);
+ CL_ASSERT(p_src_list->state == CL_INITIALIZED);
/*
* Is the src list empty?
* We must have this check here for code below to work.
*/
- if( cl_is_qlist_empty( p_src_list ) )
+ if (cl_is_qlist_empty(p_src_list))
return;
#if defined( _DEBUG_ )
/* Check that all items in the source list belong there. */
- p_item = cl_qlist_head( p_src_list );
- while( p_item != cl_qlist_end( p_src_list ) )
- {
+ p_item = cl_qlist_head(p_src_list);
+ while (p_item != cl_qlist_end(p_src_list)) {
/* All list items in the source list must point to it. */
- CL_ASSERT( p_item->p_list == p_src_list );
+ CL_ASSERT(p_item->p_list == p_src_list);
/* Point them all to the destination list. */
p_item->p_list = p_dest_list;
- p_item = cl_qlist_next( p_item );
+ p_item = cl_qlist_next(p_item);
}
#endif
/* Chain the destination list to the tail of the source list. */
- cl_qlist_tail( p_src_list )->p_next = cl_qlist_head( p_dest_list );
- cl_qlist_head( p_dest_list )->p_prev = cl_qlist_tail( p_src_list );
+ cl_qlist_tail(p_src_list)->p_next = cl_qlist_head(p_dest_list);
+ cl_qlist_head(p_dest_list)->p_prev = cl_qlist_tail(p_src_list);
/*
* Update the head of the destination list to the head of
* the source list.
*/
- p_dest_list->end.p_next = cl_qlist_head( p_src_list );
- cl_qlist_head( p_src_list )->p_prev = &p_dest_list->end;
+ p_dest_list->end.p_next = cl_qlist_head(p_src_list);
+ cl_qlist_head(p_src_list)->p_prev = &p_dest_list->end;
/*
* Update the count of the destination to reflect the source items having
@@ -172,53 +164,51 @@ cl_qlist_insert_list_head(
p_dest_list->count += p_src_list->count;
/* Update source list to reflect being empty. */
- __cl_qlist_reset( p_src_list );
+ __cl_qlist_reset(p_src_list);
}
void
-cl_qlist_insert_list_tail(
- IN cl_qlist_t* const p_dest_list,
- IN cl_qlist_t* const p_src_list )
+cl_qlist_insert_list_tail(IN cl_qlist_t * const p_dest_list,
+ IN cl_qlist_t * const p_src_list)
{
#if defined( _DEBUG_ )
- cl_list_item_t *p_item;
+ cl_list_item_t *p_item;
#endif
- CL_ASSERT( p_dest_list );
- CL_ASSERT( p_src_list );
- CL_ASSERT( p_dest_list->state == CL_INITIALIZED );
- CL_ASSERT( p_src_list->state == CL_INITIALIZED );
+ CL_ASSERT(p_dest_list);
+ CL_ASSERT(p_src_list);
+ CL_ASSERT(p_dest_list->state == CL_INITIALIZED);
+ CL_ASSERT(p_src_list->state == CL_INITIALIZED);
/*
* Is the src list empty?
* We must have this check here for code below to work.
*/
- if( cl_is_qlist_empty( p_src_list ) )
+ if (cl_is_qlist_empty(p_src_list))
return;
#if defined( _DEBUG_ )
/* Check that all items in the source list belong there. */
- p_item = cl_qlist_head( p_src_list );
- while( p_item != cl_qlist_end( p_src_list ) )
- {
+ p_item = cl_qlist_head(p_src_list);
+ while (p_item != cl_qlist_end(p_src_list)) {
/* All list items in the source list must point to it. */
- CL_ASSERT( p_item->p_list == p_src_list );
+ CL_ASSERT(p_item->p_list == p_src_list);
/* Point them all to the destination list. */
p_item->p_list = p_dest_list;
- p_item = cl_qlist_next( p_item );
+ p_item = cl_qlist_next(p_item);
}
#endif
/* Chain the source list to the tail of the destination list. */
- cl_qlist_tail( p_dest_list )->p_next = cl_qlist_head( p_src_list );
- cl_qlist_head( p_src_list )->p_prev = cl_qlist_tail( p_dest_list );
+ cl_qlist_tail(p_dest_list)->p_next = cl_qlist_head(p_src_list);
+ cl_qlist_head(p_src_list)->p_prev = cl_qlist_tail(p_dest_list);
/*
* Update the tail of the destination list to the tail of
* the source list.
*/
- p_dest_list->end.p_prev = cl_qlist_tail( p_src_list );
- cl_qlist_tail( p_src_list )->p_next = &p_dest_list->end;
+ p_dest_list->end.p_prev = cl_qlist_tail(p_src_list);
+ cl_qlist_tail(p_src_list)->p_next = &p_dest_list->end;
/*
* Update the count of the destination to reflect the source items having
@@ -227,148 +217,134 @@ cl_qlist_insert_list_tail(
p_dest_list->count += p_src_list->count;
/* Update source list to reflect being empty. */
- __cl_qlist_reset( p_src_list );
+ __cl_qlist_reset(p_src_list);
}
boolean_t
-cl_is_item_in_qlist(
- IN const cl_qlist_t* const p_list,
- IN const cl_list_item_t* const p_list_item )
+cl_is_item_in_qlist(IN const cl_qlist_t * const p_list,
+ IN const cl_list_item_t * const p_list_item)
{
- const cl_list_item_t* p_temp;
+ const cl_list_item_t *p_temp;
- CL_ASSERT( p_list );
- CL_ASSERT( p_list_item );
- CL_ASSERT( p_list->state == CL_INITIALIZED );
+ CL_ASSERT(p_list);
+ CL_ASSERT(p_list_item);
+ CL_ASSERT(p_list->state == CL_INITIALIZED);
/* Traverse looking for a match */
- p_temp = cl_qlist_head( p_list );
- while( p_temp != cl_qlist_end( p_list ) )
- {
- if( p_temp == p_list_item )
- {
- CL_ASSERT( p_list_item->p_list == p_list );
- return( TRUE );
+ p_temp = cl_qlist_head(p_list);
+ while (p_temp != cl_qlist_end(p_list)) {
+ if (p_temp == p_list_item) {
+ CL_ASSERT(p_list_item->p_list == p_list);
+ return (TRUE);
}
- p_temp = cl_qlist_next( p_temp );
+ p_temp = cl_qlist_next(p_temp);
}
- return( FALSE );
+ return (FALSE);
}
-cl_list_item_t*
-cl_qlist_find_next(
- IN const cl_qlist_t* const p_list,
- IN const cl_list_item_t* const p_list_item,
- IN cl_pfn_qlist_find_t pfn_func,
- IN const void* const context )
+cl_list_item_t *cl_qlist_find_next(IN const cl_qlist_t * const p_list,
+ IN const cl_list_item_t * const p_list_item,
+ IN cl_pfn_qlist_find_t pfn_func,
+ IN const void *const context)
{
- cl_list_item_t *p_found_item;
+ cl_list_item_t *p_found_item;
- CL_ASSERT( p_list );
- CL_ASSERT( p_list->state == CL_INITIALIZED );
- CL_ASSERT( p_list_item );
- CL_ASSERT( p_list_item->p_list == p_list );
- CL_ASSERT( pfn_func );
+ CL_ASSERT(p_list);
+ CL_ASSERT(p_list->state == CL_INITIALIZED);
+ CL_ASSERT(p_list_item);
+ CL_ASSERT(p_list_item->p_list == p_list);
+ CL_ASSERT(pfn_func);
- p_found_item = cl_qlist_next( p_list_item );
+ p_found_item = cl_qlist_next(p_list_item);
/* The user provided a compare function */
- while( p_found_item != cl_qlist_end( p_list ) )
- {
- CL_ASSERT( p_found_item->p_list == p_list );
+ while (p_found_item != cl_qlist_end(p_list)) {
+ CL_ASSERT(p_found_item->p_list == p_list);
- if( pfn_func( p_found_item, (void*)context ) == CL_SUCCESS )
+ if (pfn_func(p_found_item, (void *)context) == CL_SUCCESS)
break;
- p_found_item = cl_qlist_next( p_found_item );
+ p_found_item = cl_qlist_next(p_found_item);
}
/* No match */
- return( p_found_item );
+ return (p_found_item);
}
-cl_list_item_t*
-cl_qlist_find_prev(
- IN const cl_qlist_t* const p_list,
- IN const cl_list_item_t* const p_list_item,
- IN cl_pfn_qlist_find_t pfn_func,
- IN const void* const context )
+cl_list_item_t *cl_qlist_find_prev(IN const cl_qlist_t * const p_list,
+ IN const cl_list_item_t * const p_list_item,
+ IN cl_pfn_qlist_find_t pfn_func,
+ IN const void *const context)
{
- cl_list_item_t *p_found_item;
+ cl_list_item_t *p_found_item;
- CL_ASSERT( p_list );
- CL_ASSERT( p_list->state == CL_INITIALIZED );
- CL_ASSERT( p_list_item );
- CL_ASSERT( p_list_item->p_list == p_list );
- CL_ASSERT( pfn_func );
+ CL_ASSERT(p_list);
+ CL_ASSERT(p_list->state == CL_INITIALIZED);
+ CL_ASSERT(p_list_item);
+ CL_ASSERT(p_list_item->p_list == p_list);
+ CL_ASSERT(pfn_func);
- p_found_item = cl_qlist_prev( p_list_item );
+ p_found_item = cl_qlist_prev(p_list_item);
/* The user provided a compare function */
- while( p_found_item != cl_qlist_end( p_list ) )
- {
- CL_ASSERT( p_found_item->p_list == p_list );
+ while (p_found_item != cl_qlist_end(p_list)) {
+ CL_ASSERT(p_found_item->p_list == p_list);
- if( pfn_func( p_found_item, (void*)context ) == CL_SUCCESS )
+ if (pfn_func(p_found_item, (void *)context) == CL_SUCCESS)
break;
- p_found_item = cl_qlist_prev( p_found_item );
+ p_found_item = cl_qlist_prev(p_found_item);
}
/* No match */
- return( p_found_item );
+ return (p_found_item);
}
void
-cl_qlist_apply_func(
- IN const cl_qlist_t* const p_list,
- IN cl_pfn_qlist_apply_t pfn_func,
- IN const void* const context )
+cl_qlist_apply_func(IN const cl_qlist_t * const p_list,
+ IN cl_pfn_qlist_apply_t pfn_func,
+ IN const void *const context)
{
- cl_list_item_t* p_list_item;
+ cl_list_item_t *p_list_item;
/* Note that context can have any arbitrary value. */
- CL_ASSERT( p_list );
- CL_ASSERT( p_list->state == CL_INITIALIZED );
- CL_ASSERT( pfn_func );
-
- p_list_item = cl_qlist_head( p_list );
- while( p_list_item != cl_qlist_end( p_list ) )
- {
- pfn_func( p_list_item, (void*)context );
- p_list_item = cl_qlist_next( p_list_item );
+ CL_ASSERT(p_list);
+ CL_ASSERT(p_list->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_func);
+
+ p_list_item = cl_qlist_head(p_list);
+ while (p_list_item != cl_qlist_end(p_list)) {
+ pfn_func(p_list_item, (void *)context);
+ p_list_item = cl_qlist_next(p_list_item);
}
}
void
-cl_qlist_move_items(
- IN cl_qlist_t* const p_src_list,
- IN cl_qlist_t* const p_dest_list,
- IN cl_pfn_qlist_find_t pfn_func,
- IN const void* const context )
+cl_qlist_move_items(IN cl_qlist_t * const p_src_list,
+ IN cl_qlist_t * const p_dest_list,
+ IN cl_pfn_qlist_find_t pfn_func,
+ IN const void *const context)
{
- cl_list_item_t *p_current_item, *p_next;
+ cl_list_item_t *p_current_item, *p_next;
- CL_ASSERT( p_src_list );
- CL_ASSERT( p_dest_list );
- CL_ASSERT( p_src_list->state == CL_INITIALIZED );
- CL_ASSERT( p_dest_list->state == CL_INITIALIZED );
- CL_ASSERT( pfn_func );
+ CL_ASSERT(p_src_list);
+ CL_ASSERT(p_dest_list);
+ CL_ASSERT(p_src_list->state == CL_INITIALIZED);
+ CL_ASSERT(p_dest_list->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_func);
- p_current_item = cl_qlist_head( p_src_list );
+ p_current_item = cl_qlist_head(p_src_list);
- while( p_current_item != cl_qlist_end( p_src_list ) )
- {
+ while (p_current_item != cl_qlist_end(p_src_list)) {
/* Before we do anything, get a pointer to the next item. */
- p_next = cl_qlist_next( p_current_item );
+ p_next = cl_qlist_next(p_current_item);
- if( pfn_func( p_current_item, (void*)context ) == CL_SUCCESS )
- {
+ if (pfn_func(p_current_item, (void *)context) == CL_SUCCESS) {
/* Move the item from one list to the other. */
- cl_qlist_remove_item( p_src_list, p_current_item );
- cl_qlist_insert_tail( p_dest_list, p_current_item );
+ cl_qlist_remove_item(p_src_list, p_current_item);
+ cl_qlist_insert_tail(p_dest_list, p_current_item);
}
p_current_item = p_next;
}
@@ -381,252 +357,229 @@ cl_qlist_move_items(
************** ************
*******************************************************************************
******************************************************************************/
-void
-cl_list_construct(
- IN cl_list_t* const p_list )
+void cl_list_construct(IN cl_list_t * const p_list)
{
- CL_ASSERT( p_list );
+ CL_ASSERT(p_list);
- cl_qpool_construct( &p_list->list_item_pool );
+ cl_qpool_construct(&p_list->list_item_pool);
}
-cl_status_t
-cl_list_init(
- IN cl_list_t* const p_list,
- IN const size_t min_items )
+cl_status_t cl_list_init(IN cl_list_t * const p_list, IN const size_t min_items)
{
- uint32_t grow_size;
+ uint32_t grow_size;
- CL_ASSERT( p_list );
- cl_qlist_init( &p_list->list );
+ CL_ASSERT(p_list);
+ cl_qlist_init(&p_list->list);
/*
* We will grow by min_items/8 items at a time, with a minimum of
* FREE_ITEM_GROW_SIZE.
*/
grow_size = (uint32_t) min_items >> 3;
- if( grow_size < FREE_ITEM_GROW_SIZE )
+ if (grow_size < FREE_ITEM_GROW_SIZE)
grow_size = FREE_ITEM_GROW_SIZE;
/* Initialize the pool of list items. */
- return( cl_qpool_init( &p_list->list_item_pool, min_items, 0, grow_size,
- sizeof(cl_pool_obj_t), NULL, NULL, NULL ) );
+ return (cl_qpool_init(&p_list->list_item_pool, min_items, 0, grow_size,
+ sizeof(cl_pool_obj_t), NULL, NULL, NULL));
}
-void
-cl_list_destroy(
- IN cl_list_t* const p_list )
+void cl_list_destroy(IN cl_list_t * const p_list)
{
- CL_ASSERT( p_list );
+ CL_ASSERT(p_list);
- cl_qpool_destroy( &p_list->list_item_pool );
+ cl_qpool_destroy(&p_list->list_item_pool);
}
static cl_status_t
-cl_list_find_cb(
- IN const cl_list_item_t* const p_list_item,
- IN void* const context )
+cl_list_find_cb(IN const cl_list_item_t * const p_list_item,
+ IN void *const context)
{
- CL_ASSERT( p_list_item );
+ CL_ASSERT(p_list_item);
- if( cl_list_obj( p_list_item ) == context )
- return( CL_SUCCESS );
+ if (cl_list_obj(p_list_item) == context)
+ return (CL_SUCCESS);
- return( CL_NOT_FOUND );
+ return (CL_NOT_FOUND);
}
cl_status_t
-cl_list_remove_object(
- IN cl_list_t* const p_list,
- IN const void* const p_object )
+cl_list_remove_object(IN cl_list_t * const p_list,
+ IN const void *const p_object)
{
- cl_list_item_t *p_list_item;
+ cl_list_item_t *p_list_item;
- CL_ASSERT( p_list );
- CL_ASSERT( cl_is_qpool_inited( &p_list->list_item_pool ) );
+ CL_ASSERT(p_list);
+ CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
/* find the item in question */
p_list_item =
- cl_qlist_find_from_head( &p_list->list, cl_list_find_cb, p_object );
- if( p_list_item != cl_qlist_end( &p_list->list ) )
- {
+ cl_qlist_find_from_head(&p_list->list, cl_list_find_cb, p_object);
+ if (p_list_item != cl_qlist_end(&p_list->list)) {
/* remove this item */
- cl_qlist_remove_item( &p_list->list, p_list_item );
- cl_qpool_put( &p_list->list_item_pool, (cl_pool_item_t*)p_list_item );
- return( CL_SUCCESS );
+ cl_qlist_remove_item(&p_list->list, p_list_item);
+ cl_qpool_put(&p_list->list_item_pool,
+ (cl_pool_item_t *) p_list_item);
+ return (CL_SUCCESS);
}
- return( CL_NOT_FOUND );
+ return (CL_NOT_FOUND);
}
boolean_t
-cl_is_object_in_list(
- IN const cl_list_t* const p_list,
- IN const void* const p_object )
+cl_is_object_in_list(IN const cl_list_t * const p_list,
+ IN const void *const p_object)
{
- CL_ASSERT( p_list );
- CL_ASSERT( cl_is_qpool_inited( &p_list->list_item_pool ) );
+ CL_ASSERT(p_list);
+ CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
- return( cl_qlist_find_from_head( &p_list->list, cl_list_find_cb, p_object )
- != cl_qlist_end( &p_list->list ) );
+ return (cl_qlist_find_from_head
+ (&p_list->list, cl_list_find_cb, p_object)
+ != cl_qlist_end(&p_list->list));
}
cl_status_t
-cl_list_insert_array_head(
- IN cl_list_t* const p_list,
- IN const void* const p_array,
- IN uint32_t item_count,
- IN const uint32_t item_size )
+cl_list_insert_array_head(IN cl_list_t * const p_list,
+ IN const void *const p_array,
+ IN uint32_t item_count, IN const uint32_t item_size)
{
- cl_status_t status;
- void *p_object;
+ cl_status_t status;
+ void *p_object;
- CL_ASSERT( p_list );
- CL_ASSERT( cl_is_qpool_inited( &p_list->list_item_pool ) );
- CL_ASSERT( p_array );
- CL_ASSERT( item_size );
- CL_ASSERT( item_count );
+ CL_ASSERT(p_list);
+ CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
+ CL_ASSERT(p_array);
+ CL_ASSERT(item_size);
+ CL_ASSERT(item_count);
/*
* To add items from the array to the list in the same order as
* the elements appear in the array, we add them starting with
* the last one first. Locate the last item.
*/
- p_object = ((uint8_t*)p_array + (item_size * (item_count - 1)));
+ p_object = ((uint8_t *) p_array + (item_size * (item_count - 1)));
/* Continue to add all items to the list. */
- while( item_count-- )
- {
- status = cl_list_insert_head( p_list, p_object );
- if( status != CL_SUCCESS )
- {
+ while (item_count--) {
+ status = cl_list_insert_head(p_list, p_object);
+ if (status != CL_SUCCESS) {
/* Remove all items that have been inserted. */
- while( item_count++ < item_count )
- cl_list_remove_head( p_list );
- return( status );
+ while (item_count++ < item_count)
+ cl_list_remove_head(p_list);
+ return (status);
}
/* Get the next object to add to the list. */
- p_object = ((uint8_t*)p_object - item_size);
+ p_object = ((uint8_t *) p_object - item_size);
}
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
cl_status_t
-cl_list_insert_array_tail(
- IN cl_list_t* const p_list,
- IN const void* const p_array,
- IN uint32_t item_count,
- IN const uint32_t item_size )
+cl_list_insert_array_tail(IN cl_list_t * const p_list,
+ IN const void *const p_array,
+ IN uint32_t item_count, IN const uint32_t item_size)
{
- cl_status_t status;
- void *p_object;
+ cl_status_t status;
+ void *p_object;
- CL_ASSERT( p_list );
- CL_ASSERT( cl_is_qpool_inited( &p_list->list_item_pool ) );
- CL_ASSERT( p_array );
- CL_ASSERT( item_size );
- CL_ASSERT( item_count );
+ CL_ASSERT(p_list);
+ CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
+ CL_ASSERT(p_array);
+ CL_ASSERT(item_size);
+ CL_ASSERT(item_count);
/* Set the first item to add to the list. */
- p_object = (void*)p_array;
+ p_object = (void *)p_array;
/* Continue to add all items to the list. */
- while( item_count-- )
- {
- status = cl_list_insert_tail( p_list, p_object );
- if( status != CL_SUCCESS )
- {
+ while (item_count--) {
+ status = cl_list_insert_tail(p_list, p_object);
+ if (status != CL_SUCCESS) {
/* Remove all items that have been inserted. */
- while( item_count++ < item_count )
- cl_list_remove_tail( p_list );
- return( status );
+ while (item_count++ < item_count)
+ cl_list_remove_tail(p_list);
+ return (status);
}
/* Get the next object to add to the list. */
- p_object = ((uint8_t*)p_object + item_size);
+ p_object = ((uint8_t *) p_object + item_size);
}
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
cl_list_iterator_t
-cl_list_find_from_head(
- IN const cl_list_t* const p_list,
- IN cl_pfn_list_find_t pfn_func,
- IN const void* const context )
+cl_list_find_from_head(IN const cl_list_t * const p_list,
+ IN cl_pfn_list_find_t pfn_func,
+ IN const void *const context)
{
- cl_status_t status;
- cl_list_iterator_t itor;
+ cl_status_t status;
+ cl_list_iterator_t itor;
/* Note that context can have any arbitrary value. */
- CL_ASSERT( p_list );
- CL_ASSERT( cl_is_qpool_inited( &p_list->list_item_pool ) );
- CL_ASSERT( pfn_func );
+ CL_ASSERT(p_list);
+ CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
+ CL_ASSERT(pfn_func);
- itor = cl_list_head( p_list );
+ itor = cl_list_head(p_list);
- while( itor != cl_list_end( p_list ) )
- {
- status = pfn_func( cl_list_obj( itor ), (void*)context );
- if( status == CL_SUCCESS )
+ while (itor != cl_list_end(p_list)) {
+ status = pfn_func(cl_list_obj(itor), (void *)context);
+ if (status == CL_SUCCESS)
break;
- itor = cl_list_next( itor );
+ itor = cl_list_next(itor);
}
/* no match */
- return( itor );
+ return (itor);
}
cl_list_iterator_t
-cl_list_find_from_tail(
- IN const cl_list_t* const p_list,
- IN cl_pfn_list_find_t pfn_func,
- IN const void* const context )
+cl_list_find_from_tail(IN const cl_list_t * const p_list,
+ IN cl_pfn_list_find_t pfn_func,
+ IN const void *const context)
{
- cl_status_t status;
- cl_list_iterator_t itor;
+ cl_status_t status;
+ cl_list_iterator_t itor;
/* Note that context can have any arbitrary value. */
- CL_ASSERT( p_list );
- CL_ASSERT( cl_is_qpool_inited( &p_list->list_item_pool ) );
- CL_ASSERT( pfn_func );
+ CL_ASSERT(p_list);
+ CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
+ CL_ASSERT(pfn_func);
- itor = cl_list_tail( p_list );
+ itor = cl_list_tail(p_list);
- while( itor != cl_list_end( p_list ) )
- {
- status = pfn_func( cl_list_obj( itor ), (void*)context );
- if( status == CL_SUCCESS )
+ while (itor != cl_list_end(p_list)) {
+ status = pfn_func(cl_list_obj(itor), (void *)context);
+ if (status == CL_SUCCESS)
break;
- itor = cl_list_prev( itor );
+ itor = cl_list_prev(itor);
}
/* no match */
- return( itor );
+ return (itor);
}
void
-cl_list_apply_func(
- IN const cl_list_t* const p_list,
- IN cl_pfn_list_apply_t pfn_func,
- IN const void* const context )
+cl_list_apply_func(IN const cl_list_t * const p_list,
+ IN cl_pfn_list_apply_t pfn_func,
+ IN const void *const context)
{
- cl_list_iterator_t itor;
+ cl_list_iterator_t itor;
/* Note that context can have any arbitrary value. */
- CL_ASSERT( p_list );
- CL_ASSERT( cl_is_qpool_inited( &p_list->list_item_pool ) );
- CL_ASSERT( pfn_func );
+ CL_ASSERT(p_list);
+ CL_ASSERT(cl_is_qpool_inited(&p_list->list_item_pool));
+ CL_ASSERT(pfn_func);
- itor = cl_list_head( p_list );
+ itor = cl_list_head(p_list);
- while( itor != cl_list_end( p_list ) )
- {
- pfn_func( cl_list_obj( itor ), (void*)context );
+ while (itor != cl_list_end(p_list)) {
+ pfn_func(cl_list_obj(itor), (void *)context);
- itor = cl_list_next( itor );
+ itor = cl_list_next(itor);
}
}
diff --git a/opensm/complib/cl_log.c b/opensm/complib/cl_log.c
index dd3a4c6..a2a1372 100644
--- a/opensm/complib/cl_log.c
+++ b/opensm/complib/cl_log.c
@@ -39,7 +39,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <complib/cl_log.h>
#include <complib/cl_debug.h>
@@ -56,24 +56,21 @@
#define CL_LOG_DATA_SIZE (CL_MAX_LOG_DATA + (CL_MAX_LOG_DATA/4))
void
-cl_log_event(
- IN const char* const name,
- IN const cl_log_type_t type,
- IN const char* const message,
- IN const void* const p_data OPTIONAL,
- IN const uint32_t data_len )
+cl_log_event(IN const char *const name,
+ IN const cl_log_type_t type,
+ IN const char *const message,
+ IN const void *const p_data OPTIONAL, IN const uint32_t data_len)
{
- int priority, i;
- char data[CL_LOG_DATA_SIZE];
- char *p_buf;
- uint8_t *p_int_data = (uint8_t*)p_data;
+ int priority, i;
+ char data[CL_LOG_DATA_SIZE];
+ char *p_buf;
+ uint8_t *p_int_data = (uint8_t *) p_data;
- CL_ASSERT( name );
- CL_ASSERT( message );
+ CL_ASSERT(name);
+ CL_ASSERT(message);
- openlog( name, LOG_NDELAY | LOG_PID, LOG_USER );
- switch( type )
- {
+ openlog(name, LOG_NDELAY | LOG_PID, LOG_USER);
+ switch (type) {
case CL_LOG_ERROR:
priority = LOG_ERR;
break;
@@ -88,41 +85,34 @@ cl_log_event(
break;
}
- if( p_data )
- {
- CL_ASSERT( data_len );
- if( data_len < CL_MAX_LOG_DATA )
- {
+ if (p_data) {
+ CL_ASSERT(data_len);
+ if (data_len < CL_MAX_LOG_DATA) {
p_buf = data;
/* Format the data into ASCII. */
- for( i = 0; i < data_len; i++ )
- {
- sprintf( p_buf, "%02x", *p_int_data++ );
+ for (i = 0; i < data_len; i++) {
+ sprintf(p_buf, "%02x", *p_int_data++);
p_buf += 2;
/* Add line break after 8 DWORDS. */
- if( i % 32 )
- {
- sprintf( p_buf++, "\n" );
+ if (i % 32) {
+ sprintf(p_buf++, "\n");
continue;
}
/* Add a space between DWORDS. */
- if( i % 4 )
- sprintf( p_buf++, " " );
+ if (i % 4)
+ sprintf(p_buf++, " ");
}
- syslog( priority, "%s data:\n%s\n", message, p_buf );
- }
- else
- {
+ syslog(priority, "%s data:\n%s\n", message, p_buf);
+ } else {
/* The data portion is too large to log. */
- cl_msg_out( "cl_log() - WARNING: data too large to log.\n" );
- syslog( priority, "%s\n", message );
+ cl_msg_out
+ ("cl_log() - WARNING: data too large to log.\n");
+ syslog(priority, "%s\n", message);
}
- }
- else
- {
- syslog( priority, "%s\n", message );
+ } else {
+ syslog(priority, "%s\n", message);
}
closelog();
}
diff --git a/opensm/complib/cl_map.c b/opensm/complib/cl_map.c
index 7138a43..d8b7254 100644
--- a/opensm/complib/cl_map.c
+++ b/opensm/complib/cl_map.c
@@ -64,7 +64,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <string.h>
#include <complib/cl_qmap.h>
@@ -82,44 +82,39 @@
/*
* Get the root.
*/
-static inline cl_map_item_t*
-__cl_map_root(
- IN const cl_qmap_t* const p_map )
+static inline cl_map_item_t *__cl_map_root(IN const cl_qmap_t * const p_map)
{
- CL_ASSERT( p_map );
- return( p_map->root.p_left );
+ CL_ASSERT(p_map);
+ return (p_map->root.p_left);
}
/*
* Returns whether a given item is on the left of its parent.
*/
-static boolean_t
-__cl_map_is_left_child(
- IN const cl_map_item_t* const p_item )
+static boolean_t __cl_map_is_left_child(IN const cl_map_item_t * const p_item)
{
- CL_ASSERT( p_item );
- CL_ASSERT( p_item->p_up );
- CL_ASSERT( p_item->p_up != p_item );
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item->p_up);
+ CL_ASSERT(p_item->p_up != p_item);
- return( p_item->p_up->p_left == p_item );
+ return (p_item->p_up->p_left == p_item);
}
/*
* Retrieve the pointer to the parent's pointer to an item.
*/
-static cl_map_item_t**
-__cl_map_get_parent_ptr_to_item(
- IN cl_map_item_t* const p_item )
+static cl_map_item_t **__cl_map_get_parent_ptr_to_item(IN cl_map_item_t *
+ const p_item)
{
- CL_ASSERT( p_item );
- CL_ASSERT( p_item->p_up );
- CL_ASSERT( p_item->p_up != p_item );
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item->p_up);
+ CL_ASSERT(p_item->p_up != p_item);
- if( __cl_map_is_left_child( p_item ) )
- return( &p_item->p_up->p_left );
+ if (__cl_map_is_left_child(p_item))
+ return (&p_item->p_up->p_left);
- CL_ASSERT( p_item->p_up->p_right == p_item );
- return( &p_item->p_up->p_right );
+ CL_ASSERT(p_item->p_up->p_right == p_item);
+ return (&p_item->p_up->p_right);
}
/*
@@ -138,17 +133,15 @@ __cl_map_get_parent_ptr_to_item(
* X Y X Y
*/
static void
-__cl_map_rot_left(
- IN cl_qmap_t* const p_map,
- IN cl_map_item_t* const p_item )
+__cl_map_rot_left(IN cl_qmap_t * const p_map, IN cl_map_item_t * const p_item)
{
- cl_map_item_t **pp_root;
+ cl_map_item_t **pp_root;
- CL_ASSERT( p_map );
- CL_ASSERT( p_item );
- CL_ASSERT( p_item->p_right != &p_map->nil );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item->p_right != &p_map->nil);
- pp_root = __cl_map_get_parent_ptr_to_item( p_item );
+ pp_root = __cl_map_get_parent_ptr_to_item(p_item);
/* Point R to C instead of A. */
*pp_root = p_item->p_right;
@@ -161,7 +154,7 @@ __cl_map_rot_left(
* Set B's parent to A. We trap for B being NIL since the
* caller may depend on NIL not changing.
*/
- if( (*pp_root)->p_left != &p_map->nil )
+ if ((*pp_root)->p_left != &p_map->nil)
(*pp_root)->p_left->p_up = p_item;
/* Set C's left to A. */
@@ -186,18 +179,16 @@ __cl_map_rot_left(
* X Y X Y
*/
static void
-__cl_map_rot_right(
- IN cl_qmap_t* const p_map,
- IN cl_map_item_t* const p_item )
+__cl_map_rot_right(IN cl_qmap_t * const p_map, IN cl_map_item_t * const p_item)
{
- cl_map_item_t **pp_root;
+ cl_map_item_t **pp_root;
- CL_ASSERT( p_map );
- CL_ASSERT( p_item );
- CL_ASSERT( p_item->p_left != &p_map->nil );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item->p_left != &p_map->nil);
/* Point R to A instead of C. */
- pp_root = __cl_map_get_parent_ptr_to_item( p_item );
+ pp_root = __cl_map_get_parent_ptr_to_item(p_item);
(*pp_root) = p_item->p_left;
/* Set A's parent to R. */
(*pp_root)->p_up = p_item->p_up;
@@ -208,7 +199,7 @@ __cl_map_rot_right(
* Set B's parent to C. We trap for B being NIL since the
* caller may depend on NIL not changing.
*/
- if( (*pp_root)->p_right != &p_map->nil )
+ if ((*pp_root)->p_right != &p_map->nil)
(*pp_root)->p_right->p_up = p_item;
/* Set A's right to C. */
@@ -217,13 +208,11 @@ __cl_map_rot_right(
p_item->p_up = *pp_root;
}
-void
-cl_qmap_init(
- IN cl_qmap_t* const p_map )
+void cl_qmap_init(IN cl_qmap_t * const p_map)
{
- CL_ASSERT( p_map );
+ CL_ASSERT(p_map);
- memset( p_map, 0, sizeof(cl_qmap_t) );
+ memset(p_map, 0, sizeof(cl_qmap_t));
/* special setup for the root node */
p_map->root.p_up = &p_map->root;
@@ -239,80 +228,72 @@ cl_qmap_init(
p_map->state = CL_INITIALIZED;
- cl_qmap_remove_all( p_map );
+ cl_qmap_remove_all(p_map);
}
-cl_map_item_t*
-cl_qmap_get(
- IN const cl_qmap_t* const p_map,
- IN const uint64_t key )
+cl_map_item_t *cl_qmap_get(IN const cl_qmap_t * const p_map,
+ IN const uint64_t key)
{
- cl_map_item_t *p_item;
+ cl_map_item_t *p_item;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
- p_item = __cl_map_root( p_map );
+ p_item = __cl_map_root(p_map);
- while( p_item != &p_map->nil )
- {
- if( key == p_item->key )
- break; /* just right */
+ while (p_item != &p_map->nil) {
+ if (key == p_item->key)
+ break; /* just right */
- if( key < p_item->key )
+ if (key < p_item->key)
p_item = p_item->p_left; /* too small */
else
p_item = p_item->p_right; /* too big */
}
- return( p_item );
+ return (p_item);
}
-cl_map_item_t*
-cl_qmap_get_next(
- IN const cl_qmap_t* const p_map,
- IN const uint64_t key )
+cl_map_item_t *cl_qmap_get_next(IN const cl_qmap_t * const p_map,
+ IN const uint64_t key)
{
- cl_map_item_t *p_item;
- cl_map_item_t *p_item_found;
+ cl_map_item_t *p_item;
+ cl_map_item_t *p_item_found;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
- p_item = __cl_map_root( p_map );
- p_item_found = (cl_map_item_t*)&p_map->nil;
+ p_item = __cl_map_root(p_map);
+ p_item_found = (cl_map_item_t *) & p_map->nil;
- while( p_item != &p_map->nil )
- {
- if( key < p_item->key ){
+ while (p_item != &p_map->nil) {
+ if (key < p_item->key) {
p_item_found = p_item;
p_item = p_item->p_left;
- }else{
+ } else {
p_item = p_item->p_right;
}
}
- return( p_item_found );
+ return (p_item_found);
}
void
-cl_qmap_apply_func(
- IN const cl_qmap_t* const p_map,
- IN cl_pfn_qmap_apply_t pfn_func,
- IN const void* const context )
+cl_qmap_apply_func(IN const cl_qmap_t * const p_map,
+ IN cl_pfn_qmap_apply_t pfn_func,
+ IN const void *const context)
{
- cl_map_item_t* p_map_item;
+ cl_map_item_t *p_map_item;
/* Note that context can have any arbitrary value. */
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
- CL_ASSERT( pfn_func );
-
- p_map_item = cl_qmap_head( p_map );
- while( p_map_item != cl_qmap_end( p_map ) )
- {
- pfn_func( p_map_item, (void*)context );
- p_map_item = cl_qmap_next( p_map_item );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_func);
+
+ p_map_item = cl_qmap_head(p_map);
+ while (p_map_item != cl_qmap_end(p_map)) {
+ pfn_func(p_map_item, (void *)context);
+ p_map_item = cl_qmap_next(p_map_item);
}
}
@@ -320,24 +301,19 @@ cl_qmap_apply_func(
* Balance a tree starting at a given item back to the root.
*/
static void
-__cl_map_ins_bal(
- IN cl_qmap_t* const p_map,
- IN cl_map_item_t* p_item )
+__cl_map_ins_bal(IN cl_qmap_t * const p_map, IN cl_map_item_t * p_item)
{
- cl_map_item_t* p_grand_uncle;
+ cl_map_item_t *p_grand_uncle;
- CL_ASSERT( p_map );
- CL_ASSERT( p_item );
- CL_ASSERT( p_item != &p_map->root );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item != &p_map->root);
- while( p_item->p_up->color == CL_MAP_RED )
- {
- if( __cl_map_is_left_child( p_item->p_up ) )
- {
+ while (p_item->p_up->color == CL_MAP_RED) {
+ if (__cl_map_is_left_child(p_item->p_up)) {
p_grand_uncle = p_item->p_up->p_up->p_right;
- CL_ASSERT( p_grand_uncle );
- if( p_grand_uncle->color == CL_MAP_RED )
- {
+ CL_ASSERT(p_grand_uncle);
+ if (p_grand_uncle->color == CL_MAP_RED) {
p_grand_uncle->color = CL_MAP_BLACK;
p_item->p_up->color = CL_MAP_BLACK;
p_item->p_up->p_up->color = CL_MAP_RED;
@@ -345,21 +321,17 @@ __cl_map_ins_bal(
continue;
}
- if( !__cl_map_is_left_child( p_item ) )
- {
+ if (!__cl_map_is_left_child(p_item)) {
p_item = p_item->p_up;
- __cl_map_rot_left( p_map, p_item );
+ __cl_map_rot_left(p_map, p_item);
}
p_item->p_up->color = CL_MAP_BLACK;
p_item->p_up->p_up->color = CL_MAP_RED;
- __cl_map_rot_right( p_map, p_item->p_up->p_up );
- }
- else
- {
+ __cl_map_rot_right(p_map, p_item->p_up->p_up);
+ } else {
p_grand_uncle = p_item->p_up->p_up->p_left;
- CL_ASSERT( p_grand_uncle );
- if( p_grand_uncle->color == CL_MAP_RED )
- {
+ CL_ASSERT(p_grand_uncle);
+ if (p_grand_uncle->color == CL_MAP_RED) {
p_grand_uncle->color = CL_MAP_BLACK;
p_item->p_up->color = CL_MAP_BLACK;
p_item->p_up->p_up->color = CL_MAP_RED;
@@ -367,32 +339,29 @@ __cl_map_ins_bal(
continue;
}
- if( __cl_map_is_left_child( p_item ) )
- {
+ if (__cl_map_is_left_child(p_item)) {
p_item = p_item->p_up;
- __cl_map_rot_right( p_map, p_item );
+ __cl_map_rot_right(p_map, p_item);
}
p_item->p_up->color = CL_MAP_BLACK;
p_item->p_up->p_up->color = CL_MAP_RED;
- __cl_map_rot_left( p_map, p_item->p_up->p_up );
+ __cl_map_rot_left(p_map, p_item->p_up->p_up);
}
}
}
-cl_map_item_t*
-cl_qmap_insert(
- IN cl_qmap_t* const p_map,
- IN const uint64_t key,
- IN cl_map_item_t* const p_item )
+cl_map_item_t *cl_qmap_insert(IN cl_qmap_t * const p_map,
+ IN const uint64_t key,
+ IN cl_map_item_t * const p_item)
{
- cl_map_item_t *p_insert_at, *p_comp_item;
+ cl_map_item_t *p_insert_at, *p_comp_item;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
- CL_ASSERT( p_item );
- CL_ASSERT( p_map->root.p_up == &p_map->root );
- CL_ASSERT( p_map->root.color != CL_MAP_RED );
- CL_ASSERT( p_map->nil.color != CL_MAP_RED );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_map->root.p_up == &p_map->root);
+ CL_ASSERT(p_map->root.color != CL_MAP_RED);
+ CL_ASSERT(p_map->nil.color != CL_MAP_RED);
p_item->p_left = &p_map->nil;
p_item->p_right = &p_map->nil;
@@ -401,54 +370,48 @@ cl_qmap_insert(
/* Find the insertion location. */
p_insert_at = &p_map->root;
- p_comp_item = __cl_map_root( p_map );
+ p_comp_item = __cl_map_root(p_map);
- while( p_comp_item != &p_map->nil )
- {
+ while (p_comp_item != &p_map->nil) {
p_insert_at = p_comp_item;
- if( key == p_insert_at->key )
- return( p_insert_at );
+ if (key == p_insert_at->key)
+ return (p_insert_at);
/* Traverse the tree until the correct insertion point is found. */
- if( key < p_insert_at->key )
+ if (key < p_insert_at->key)
p_comp_item = p_insert_at->p_left;
else
p_comp_item = p_insert_at->p_right;
}
- CL_ASSERT( p_insert_at != &p_map->nil );
- CL_ASSERT( p_comp_item == &p_map->nil );
+ CL_ASSERT(p_insert_at != &p_map->nil);
+ CL_ASSERT(p_comp_item == &p_map->nil);
/* Insert the item. */
- if( p_insert_at == &p_map->root )
- {
+ if (p_insert_at == &p_map->root) {
p_insert_at->p_left = p_item;
/*
* Primitive insert places the new item in front of
* the existing item.
*/
- __cl_primitive_insert( &p_map->nil.pool_item.list_item,
- &p_item->pool_item.list_item );
- }
- else if( key < p_insert_at->key )
- {
+ __cl_primitive_insert(&p_map->nil.pool_item.list_item,
+ &p_item->pool_item.list_item);
+ } else if (key < p_insert_at->key) {
p_insert_at->p_left = p_item;
/*
* Primitive insert places the new item in front of
* the existing item.
*/
- __cl_primitive_insert( &p_insert_at->pool_item.list_item,
- &p_item->pool_item.list_item );
- }
- else
- {
+ __cl_primitive_insert(&p_insert_at->pool_item.list_item,
+ &p_item->pool_item.list_item);
+ } else {
p_insert_at->p_right = p_item;
/*
* Primitive insert places the new item in front of
* the existing item.
*/
- __cl_primitive_insert( p_insert_at->pool_item.list_item.p_next,
- &p_item->pool_item.list_item );
+ __cl_primitive_insert(p_insert_at->pool_item.list_item.p_next,
+ &p_item->pool_item.list_item);
}
/* Increase the count. */
p_map->count++;
@@ -460,9 +423,9 @@ cl_qmap_insert(
* Rebalance as necessary as we retrace our path through the tree
* and update colors.
*/
- __cl_map_ins_bal( p_map, p_item );
+ __cl_map_ins_bal(p_map, p_item);
- __cl_map_root( p_map )->color = CL_MAP_BLACK;
+ __cl_map_root(p_map)->color = CL_MAP_BLACK;
/*
* Note that it is not necessary to re-color the nil node black because all
@@ -475,34 +438,27 @@ cl_qmap_insert(
p_item->p_map = p_map;
#endif
- return( p_item );
+ return (p_item);
}
static void
-__cl_map_del_bal(
- IN cl_qmap_t* const p_map,
- IN cl_map_item_t* p_item )
+__cl_map_del_bal(IN cl_qmap_t * const p_map, IN cl_map_item_t * p_item)
{
- cl_map_item_t *p_uncle;
+ cl_map_item_t *p_uncle;
- while( (p_item->color != CL_MAP_RED) && (p_item->p_up != &p_map->root) )
- {
- if( __cl_map_is_left_child( p_item ) )
- {
+ while ((p_item->color != CL_MAP_RED) && (p_item->p_up != &p_map->root)) {
+ if (__cl_map_is_left_child(p_item)) {
p_uncle = p_item->p_up->p_right;
- if( p_uncle->color == CL_MAP_RED )
- {
+ if (p_uncle->color == CL_MAP_RED) {
p_uncle->color = CL_MAP_BLACK;
p_item->p_up->color = CL_MAP_RED;
- __cl_map_rot_left( p_map, p_item->p_up );
+ __cl_map_rot_left(p_map, p_item->p_up);
p_uncle = p_item->p_up->p_right;
}
- if( p_uncle->p_right->color != CL_MAP_RED )
- {
- if( p_uncle->p_left->color != CL_MAP_RED )
- {
+ if (p_uncle->p_right->color != CL_MAP_RED) {
+ if (p_uncle->p_left->color != CL_MAP_RED) {
p_uncle->color = CL_MAP_RED;
p_item = p_item->p_up;
continue;
@@ -510,31 +466,26 @@ __cl_map_del_bal(
p_uncle->p_left->color = CL_MAP_BLACK;
p_uncle->color = CL_MAP_RED;
- __cl_map_rot_right( p_map, p_uncle );
+ __cl_map_rot_right(p_map, p_uncle);
p_uncle = p_item->p_up->p_right;
}
p_uncle->color = p_item->p_up->color;
p_item->p_up->color = CL_MAP_BLACK;
p_uncle->p_right->color = CL_MAP_BLACK;
- __cl_map_rot_left( p_map, p_item->p_up );
+ __cl_map_rot_left(p_map, p_item->p_up);
break;
- }
- else
- {
+ } else {
p_uncle = p_item->p_up->p_left;
- if( p_uncle->color == CL_MAP_RED )
- {
+ if (p_uncle->color == CL_MAP_RED) {
p_uncle->color = CL_MAP_BLACK;
p_item->p_up->color = CL_MAP_RED;
- __cl_map_rot_right( p_map, p_item->p_up );
+ __cl_map_rot_right(p_map, p_item->p_up);
p_uncle = p_item->p_up->p_left;
}
- if( p_uncle->p_left->color != CL_MAP_RED )
- {
- if( p_uncle->p_right->color != CL_MAP_RED )
- {
+ if (p_uncle->p_left->color != CL_MAP_RED) {
+ if (p_uncle->p_right->color != CL_MAP_RED) {
p_uncle->color = CL_MAP_RED;
p_item = p_item->p_up;
continue;
@@ -542,13 +493,13 @@ __cl_map_del_bal(
p_uncle->p_right->color = CL_MAP_BLACK;
p_uncle->color = CL_MAP_RED;
- __cl_map_rot_left( p_map, p_uncle );
+ __cl_map_rot_left(p_map, p_uncle);
p_uncle = p_item->p_up->p_left;
}
p_uncle->color = p_item->p_up->color;
p_item->p_up->color = CL_MAP_BLACK;
p_uncle->p_left->color = CL_MAP_BLACK;
- __cl_map_rot_right( p_map, p_item->p_up );
+ __cl_map_rot_right(p_map, p_item->p_up);
break;
}
}
@@ -556,30 +507,25 @@ __cl_map_del_bal(
}
void
-cl_qmap_remove_item(
- IN cl_qmap_t* const p_map,
- IN cl_map_item_t* const p_item )
+cl_qmap_remove_item(IN cl_qmap_t * const p_map, IN cl_map_item_t * const p_item)
{
- cl_map_item_t *p_child, *p_del_item;
+ cl_map_item_t *p_child, *p_del_item;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
- CL_ASSERT( p_item );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
+ CL_ASSERT(p_item);
- if( p_item == cl_qmap_end( p_map ) )
+ if (p_item == cl_qmap_end(p_map))
return;
- /* must be checked after comparing to cl_qmap_end, since
- the end is not a valid item. */
- CL_ASSERT( p_item->p_map == p_map );
+ /* must be checked after comparing to cl_qmap_end, since
+ the end is not a valid item. */
+ CL_ASSERT(p_item->p_map == p_map);
- if( (p_item->p_right == &p_map->nil) || (p_item->p_left == &p_map->nil ) )
- {
+ if ((p_item->p_right == &p_map->nil) || (p_item->p_left == &p_map->nil)) {
/* The item being removed has children on at most on side. */
p_del_item = p_item;
- }
- else
- {
+ } else {
/*
* The item being removed has children on both side.
* We select the item that will replace it. After removing
@@ -587,17 +533,17 @@ cl_qmap_remove_item(
* correct topology. Exchanging the substitute for the item
* will finalize the removal.
*/
- p_del_item = cl_qmap_next( p_item );
- CL_ASSERT( p_del_item != &p_map->nil );
+ p_del_item = cl_qmap_next(p_item);
+ CL_ASSERT(p_del_item != &p_map->nil);
}
/* Remove the item from the list. */
- __cl_primitive_remove( &p_item->pool_item.list_item );
+ __cl_primitive_remove(&p_item->pool_item.list_item);
/* Decrement the item count. */
p_map->count--;
/* Get the pointer to the new root's child, if any. */
- if( p_del_item->p_left != &p_map->nil )
+ if (p_del_item->p_left != &p_map->nil)
p_child = p_del_item->p_left;
else
p_child = p_del_item->p_right;
@@ -607,10 +553,10 @@ cl_qmap_remove_item(
* This is inconsequential.
*/
p_child->p_up = p_del_item->p_up;
- (*__cl_map_get_parent_ptr_to_item( p_del_item )) = p_child;
+ (*__cl_map_get_parent_ptr_to_item(p_del_item)) = p_child;
- if( p_del_item->color != CL_MAP_RED )
- __cl_map_del_bal( p_map, p_child );
+ if (p_del_item->color != CL_MAP_RED)
+ __cl_map_del_bal(p_map, p_child);
/*
* Note that the splicing done below does not need to occur before
@@ -618,8 +564,7 @@ cl_qmap_remove_item(
* preceding code. The topology is preserved by the color assignment made
* below (reader should be reminded that p_del_item == p_item in some cases).
*/
- if( p_del_item != p_item )
- {
+ if (p_del_item != p_item) {
/*
* Finalize the removal of the specified item by exchanging it with
* the substitute which we removed above.
@@ -627,13 +572,13 @@ cl_qmap_remove_item(
p_del_item->p_up = p_item->p_up;
p_del_item->p_left = p_item->p_left;
p_del_item->p_right = p_item->p_right;
- (*__cl_map_get_parent_ptr_to_item( p_item )) = p_del_item;
+ (*__cl_map_get_parent_ptr_to_item(p_item)) = p_del_item;
p_item->p_right->p_up = p_del_item;
p_item->p_left->p_up = p_del_item;
p_del_item->color = p_item->color;
}
- CL_ASSERT( p_map->nil.color != CL_MAP_RED );
+ CL_ASSERT(p_map->nil.color != CL_MAP_RED);
#ifdef _DEBUG_
/* Clear the pointer to the map since the item has been removed. */
@@ -641,127 +586,113 @@ cl_qmap_remove_item(
#endif
}
-cl_map_item_t*
-cl_qmap_remove(
- IN cl_qmap_t* const p_map,
- IN const uint64_t key )
+cl_map_item_t *cl_qmap_remove(IN cl_qmap_t * const p_map, IN const uint64_t key)
{
- cl_map_item_t *p_item;
+ cl_map_item_t *p_item;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
/* Seek the node with the specified key */
- p_item = cl_qmap_get( p_map, key );
+ p_item = cl_qmap_get(p_map, key);
- cl_qmap_remove_item( p_map, p_item );
+ cl_qmap_remove_item(p_map, p_item);
- return( p_item );
+ return (p_item);
}
void
-cl_qmap_merge(
- OUT cl_qmap_t* const p_dest_map,
- IN OUT cl_qmap_t* const p_src_map )
+cl_qmap_merge(OUT cl_qmap_t * const p_dest_map,
+ IN OUT cl_qmap_t * const p_src_map)
{
- cl_map_item_t *p_item, *p_item2, *p_next;
+ cl_map_item_t *p_item, *p_item2, *p_next;
- CL_ASSERT( p_dest_map );
- CL_ASSERT( p_src_map );
+ CL_ASSERT(p_dest_map);
+ CL_ASSERT(p_src_map);
- p_item = cl_qmap_head( p_src_map );
+ p_item = cl_qmap_head(p_src_map);
- while( p_item != cl_qmap_end( p_src_map ) )
- {
- p_next = cl_qmap_next( p_item );
+ while (p_item != cl_qmap_end(p_src_map)) {
+ p_next = cl_qmap_next(p_item);
/* Remove the item from its current map. */
- cl_qmap_remove_item( p_src_map, p_item );
+ cl_qmap_remove_item(p_src_map, p_item);
/* Insert the item into the destination map. */
- p_item2 = cl_qmap_insert( p_dest_map, cl_qmap_key( p_item ), p_item );
+ p_item2 =
+ cl_qmap_insert(p_dest_map, cl_qmap_key(p_item), p_item);
/* Check that the item was successfully inserted. */
- if( p_item2 != p_item )
- {
+ if (p_item2 != p_item) {
/* Put the item in back in the source map. */
p_item2 =
- cl_qmap_insert( p_src_map, cl_qmap_key( p_item ), p_item );
- CL_ASSERT( p_item2 == p_item );
+ cl_qmap_insert(p_src_map, cl_qmap_key(p_item),
+ p_item);
+ CL_ASSERT(p_item2 == p_item);
}
p_item = p_next;
}
}
static void
-__cl_qmap_delta_move(
- IN OUT cl_qmap_t* const p_dest,
- IN OUT cl_qmap_t* const p_src,
- IN OUT cl_map_item_t** const pp_item )
+__cl_qmap_delta_move(IN OUT cl_qmap_t * const p_dest,
+ IN OUT cl_qmap_t * const p_src,
+ IN OUT cl_map_item_t ** const pp_item)
{
- cl_map_item_t *p_temp, *p_next;
+ cl_map_item_t *p_temp, *p_next;
/*
* Get the next item so that we can ensure that pp_item points to
* a valid item upon return from the function.
*/
- p_next = cl_qmap_next( *pp_item );
+ p_next = cl_qmap_next(*pp_item);
/* Move the old item from its current map the the old map. */
- cl_qmap_remove_item( p_src, *pp_item );
- p_temp = cl_qmap_insert( p_dest, cl_qmap_key( *pp_item ), *pp_item );
+ cl_qmap_remove_item(p_src, *pp_item);
+ p_temp = cl_qmap_insert(p_dest, cl_qmap_key(*pp_item), *pp_item);
/* We should never have duplicates. */
- CL_ASSERT( p_temp == *pp_item );
+ CL_ASSERT(p_temp == *pp_item);
/* Point pp_item to a valid item in the source map. */
(*pp_item) = p_next;
}
void
-cl_qmap_delta(
- IN OUT cl_qmap_t* const p_map1,
- IN OUT cl_qmap_t* const p_map2,
- OUT cl_qmap_t* const p_new,
- OUT cl_qmap_t* const p_old )
+cl_qmap_delta(IN OUT cl_qmap_t * const p_map1,
+ IN OUT cl_qmap_t * const p_map2,
+ OUT cl_qmap_t * const p_new, OUT cl_qmap_t * const p_old)
{
- cl_map_item_t *p_item1, *p_item2;
- uint64_t key1, key2;
-
- CL_ASSERT( p_map1 );
- CL_ASSERT( p_map2 );
- CL_ASSERT( p_new );
- CL_ASSERT( p_old );
- CL_ASSERT( cl_is_qmap_empty( p_new ) );
- CL_ASSERT( cl_is_qmap_empty( p_old ) );
-
- p_item1 = cl_qmap_head( p_map1 );
- p_item2 = cl_qmap_head( p_map2 );
-
- while( p_item1 != cl_qmap_end( p_map1 ) &&
- p_item2 != cl_qmap_end( p_map2 ) )
- {
- key1 = cl_qmap_key( p_item1 );
- key2 = cl_qmap_key( p_item2 );
- if( key1 < key2 )
- {
+ cl_map_item_t *p_item1, *p_item2;
+ uint64_t key1, key2;
+
+ CL_ASSERT(p_map1);
+ CL_ASSERT(p_map2);
+ CL_ASSERT(p_new);
+ CL_ASSERT(p_old);
+ CL_ASSERT(cl_is_qmap_empty(p_new));
+ CL_ASSERT(cl_is_qmap_empty(p_old));
+
+ p_item1 = cl_qmap_head(p_map1);
+ p_item2 = cl_qmap_head(p_map2);
+
+ while (p_item1 != cl_qmap_end(p_map1) && p_item2 != cl_qmap_end(p_map2)) {
+ key1 = cl_qmap_key(p_item1);
+ key2 = cl_qmap_key(p_item2);
+ if (key1 < key2) {
/* We found an old item. */
- __cl_qmap_delta_move( p_old, p_map1, &p_item1 );
- }
- else if( key1 > key2 )
- {
+ __cl_qmap_delta_move(p_old, p_map1, &p_item1);
+ } else if (key1 > key2) {
/* We found a new item. */
- __cl_qmap_delta_move( p_new, p_map2, &p_item2 );
- }
- else
- {
+ __cl_qmap_delta_move(p_new, p_map2, &p_item2);
+ } else {
/* Move both forward since they have the same key. */
- p_item1 = cl_qmap_next( p_item1 );
- p_item2 = cl_qmap_next( p_item2 );
+ p_item1 = cl_qmap_next(p_item1);
+ p_item2 = cl_qmap_next(p_item2);
}
}
/* Process the remainder if the end of either source map was reached. */
- while( p_item2 != cl_qmap_end( p_map2 ) )
- __cl_qmap_delta_move( p_new, p_map2, &p_item2 );
+ while (p_item2 != cl_qmap_end(p_map2))
+ __cl_qmap_delta_move(p_new, p_map2, &p_item2);
- while( p_item1 != cl_qmap_end( p_map1 ) )
- __cl_qmap_delta_move( p_old, p_map1, &p_item1 );
+ while (p_item1 != cl_qmap_end(p_map1))
+ __cl_qmap_delta_move(p_old, p_map1, &p_item1);
}
/******************************************************************************
@@ -774,348 +705,301 @@ cl_qmap_delta(
#define MAP_GROW_SIZE 32
-void
-cl_map_construct(
- IN cl_map_t* const p_map )
+void cl_map_construct(IN cl_map_t * const p_map)
{
- CL_ASSERT( p_map );
+ CL_ASSERT(p_map);
- cl_qpool_construct( &p_map->pool );
+ cl_qpool_construct(&p_map->pool);
}
-cl_status_t
-cl_map_init(
- IN cl_map_t* const p_map,
- IN const uint32_t min_items )
+cl_status_t cl_map_init(IN cl_map_t * const p_map, IN const uint32_t min_items)
{
- uint32_t grow_size;
+ uint32_t grow_size;
- CL_ASSERT( p_map );
+ CL_ASSERT(p_map);
- cl_qmap_init( &p_map->qmap );
+ cl_qmap_init(&p_map->qmap);
/*
* We will grow by min_items/8 items at a time, with a minimum of
* MAP_GROW_SIZE.
*/
grow_size = min_items >> 3;
- if( grow_size < MAP_GROW_SIZE )
+ if (grow_size < MAP_GROW_SIZE)
grow_size = MAP_GROW_SIZE;
- return( cl_qpool_init( &p_map->pool, min_items, 0, grow_size,
- sizeof(cl_map_obj_t), NULL, NULL, NULL ) );
+ return (cl_qpool_init(&p_map->pool, min_items, 0, grow_size,
+ sizeof(cl_map_obj_t), NULL, NULL, NULL));
}
-void
-cl_map_destroy(
- IN cl_map_t* const p_map )
+void cl_map_destroy(IN cl_map_t * const p_map)
{
- CL_ASSERT( p_map );
+ CL_ASSERT(p_map);
- cl_qpool_destroy( &p_map->pool );
+ cl_qpool_destroy(&p_map->pool);
}
-void*
-cl_map_insert(
- IN cl_map_t* const p_map,
- IN const uint64_t key,
- IN const void* const p_object )
+void *cl_map_insert(IN cl_map_t * const p_map,
+ IN const uint64_t key, IN const void *const p_object)
{
- cl_map_obj_t *p_map_obj, *p_obj_at_key;
+ cl_map_obj_t *p_map_obj, *p_obj_at_key;
- CL_ASSERT( p_map );
+ CL_ASSERT(p_map);
- p_map_obj = (cl_map_obj_t*)cl_qpool_get( &p_map->pool );
+ p_map_obj = (cl_map_obj_t *) cl_qpool_get(&p_map->pool);
- if( !p_map_obj )
- return( NULL );
+ if (!p_map_obj)
+ return (NULL);
- cl_qmap_set_obj( p_map_obj, p_object );
+ cl_qmap_set_obj(p_map_obj, p_object);
p_obj_at_key =
- (cl_map_obj_t*)cl_qmap_insert( &p_map->qmap, key, &p_map_obj->item );
+ (cl_map_obj_t *) cl_qmap_insert(&p_map->qmap, key,
+ &p_map_obj->item);
/* Return the item to the pool if insertion failed. */
- if( p_obj_at_key != p_map_obj )
- cl_qpool_put( &p_map->pool, &p_map_obj->item.pool_item );
+ if (p_obj_at_key != p_map_obj)
+ cl_qpool_put(&p_map->pool, &p_map_obj->item.pool_item);
- return( cl_qmap_obj( p_obj_at_key ) );
+ return (cl_qmap_obj(p_obj_at_key));
}
-void*
-cl_map_get(
- IN const cl_map_t* const p_map,
- IN const uint64_t key )
+void *cl_map_get(IN const cl_map_t * const p_map, IN const uint64_t key)
{
- cl_map_item_t *p_item;
+ cl_map_item_t *p_item;
- CL_ASSERT( p_map );
+ CL_ASSERT(p_map);
- p_item = cl_qmap_get( &p_map->qmap, key );
+ p_item = cl_qmap_get(&p_map->qmap, key);
- if( p_item == cl_qmap_end( &p_map->qmap ) )
- return( NULL );
+ if (p_item == cl_qmap_end(&p_map->qmap))
+ return (NULL);
- return( cl_qmap_obj( PARENT_STRUCT( p_item, cl_map_obj_t, item ) ) );
+ return (cl_qmap_obj(PARENT_STRUCT(p_item, cl_map_obj_t, item)));
}
-void*
-cl_map_get_next(
- IN const cl_map_t* const p_map,
- IN const uint64_t key )
+void *cl_map_get_next(IN const cl_map_t * const p_map, IN const uint64_t key)
{
- cl_map_item_t *p_item;
+ cl_map_item_t *p_item;
- CL_ASSERT( p_map );
+ CL_ASSERT(p_map);
- p_item = cl_qmap_get_next( &p_map->qmap, key );
+ p_item = cl_qmap_get_next(&p_map->qmap, key);
- if( p_item == cl_qmap_end( &p_map->qmap ) )
- return( NULL );
+ if (p_item == cl_qmap_end(&p_map->qmap))
+ return (NULL);
- return( cl_qmap_obj( PARENT_STRUCT( p_item, cl_map_obj_t, item ) ) );
+ return (cl_qmap_obj(PARENT_STRUCT(p_item, cl_map_obj_t, item)));
}
void
-cl_map_remove_item(
- IN cl_map_t* const p_map,
- IN const cl_map_iterator_t itor )
+cl_map_remove_item(IN cl_map_t * const p_map, IN const cl_map_iterator_t itor)
{
- CL_ASSERT( itor->p_map == &p_map->qmap );
+ CL_ASSERT(itor->p_map == &p_map->qmap);
- if( itor == cl_map_end( p_map ) )
+ if (itor == cl_map_end(p_map))
return;
- cl_qmap_remove_item( &p_map->qmap, (cl_map_item_t*)itor );
- cl_qpool_put( &p_map->pool, &((cl_map_item_t*)itor)->pool_item );
+ cl_qmap_remove_item(&p_map->qmap, (cl_map_item_t *) itor);
+ cl_qpool_put(&p_map->pool, &((cl_map_item_t *) itor)->pool_item);
}
-void*
-cl_map_remove(
- IN cl_map_t* const p_map,
- IN const uint64_t key )
+void *cl_map_remove(IN cl_map_t * const p_map, IN const uint64_t key)
{
- cl_map_item_t *p_item;
- void *p_obj;
+ cl_map_item_t *p_item;
+ void *p_obj;
- CL_ASSERT( p_map );
+ CL_ASSERT(p_map);
- p_item = cl_qmap_remove( &p_map->qmap, key );
+ p_item = cl_qmap_remove(&p_map->qmap, key);
- if( p_item == cl_qmap_end( &p_map->qmap ) )
- return( NULL );
+ if (p_item == cl_qmap_end(&p_map->qmap))
+ return (NULL);
- p_obj = cl_qmap_obj( (cl_map_obj_t*)p_item );
- cl_qpool_put( &p_map->pool, &p_item->pool_item );
+ p_obj = cl_qmap_obj((cl_map_obj_t *) p_item);
+ cl_qpool_put(&p_map->pool, &p_item->pool_item);
- return( p_obj );
+ return (p_obj);
}
-void
-cl_map_remove_all(
- IN cl_map_t* const p_map )
+void cl_map_remove_all(IN cl_map_t * const p_map)
{
- cl_map_item_t *p_item;
+ cl_map_item_t *p_item;
- CL_ASSERT( p_map );
+ CL_ASSERT(p_map);
/* Return all map items to the pool. */
- while( !cl_is_qmap_empty( &p_map->qmap ) )
- {
- p_item = cl_qmap_head( &p_map->qmap );
- cl_qmap_remove_item( &p_map->qmap, p_item );
- cl_qpool_put( &p_map->pool, &p_item->pool_item );
-
- if( !cl_is_qmap_empty( &p_map->qmap ) )
- {
- p_item = cl_qmap_tail( &p_map->qmap );
- cl_qmap_remove_item( &p_map->qmap, p_item );
- cl_qpool_put( &p_map->pool, &p_item->pool_item );
+ while (!cl_is_qmap_empty(&p_map->qmap)) {
+ p_item = cl_qmap_head(&p_map->qmap);
+ cl_qmap_remove_item(&p_map->qmap, p_item);
+ cl_qpool_put(&p_map->pool, &p_item->pool_item);
+
+ if (!cl_is_qmap_empty(&p_map->qmap)) {
+ p_item = cl_qmap_tail(&p_map->qmap);
+ cl_qmap_remove_item(&p_map->qmap, p_item);
+ cl_qpool_put(&p_map->pool, &p_item->pool_item);
}
}
}
cl_status_t
-cl_map_merge(
- OUT cl_map_t* const p_dest_map,
- IN OUT cl_map_t* const p_src_map )
+cl_map_merge(OUT cl_map_t * const p_dest_map, IN OUT cl_map_t * const p_src_map)
{
- cl_status_t status = CL_SUCCESS;
- cl_map_iterator_t itor, next;
- uint64_t key;
- void *p_obj, *p_obj2;
+ cl_status_t status = CL_SUCCESS;
+ cl_map_iterator_t itor, next;
+ uint64_t key;
+ void *p_obj, *p_obj2;
- CL_ASSERT( p_dest_map );
- CL_ASSERT( p_src_map );
+ CL_ASSERT(p_dest_map);
+ CL_ASSERT(p_src_map);
- itor = cl_map_head( p_src_map );
- while( itor != cl_map_end( p_src_map ) )
- {
- next = cl_map_next( itor );
+ itor = cl_map_head(p_src_map);
+ while (itor != cl_map_end(p_src_map)) {
+ next = cl_map_next(itor);
- p_obj = cl_map_obj( itor );
- key = cl_map_key( itor );
+ p_obj = cl_map_obj(itor);
+ key = cl_map_key(itor);
- cl_map_remove_item( p_src_map, itor );
+ cl_map_remove_item(p_src_map, itor);
/* Insert the object into the destination map. */
- p_obj2 = cl_map_insert( p_dest_map, key, p_obj );
+ p_obj2 = cl_map_insert(p_dest_map, key, p_obj);
/* Trap for failure. */
- if( p_obj != p_obj2 )
- {
- if( !p_obj2 )
+ if (p_obj != p_obj2) {
+ if (!p_obj2)
status = CL_INSUFFICIENT_MEMORY;
/* Put the object back in the source map. This must succeed. */
- p_obj2 = cl_map_insert( p_src_map, key, p_obj );
- CL_ASSERT( p_obj == p_obj2 );
+ p_obj2 = cl_map_insert(p_src_map, key, p_obj);
+ CL_ASSERT(p_obj == p_obj2);
/* If the failure was due to insufficient memory, return. */
- if( status != CL_SUCCESS )
- return( status );
+ if (status != CL_SUCCESS)
+ return (status);
}
itor = next;
}
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
static void
-__cl_map_revert(
- IN OUT cl_map_t* const p_map1,
- IN OUT cl_map_t* const p_map2,
- IN OUT cl_map_t* const p_new,
- IN OUT cl_map_t* const p_old )
+__cl_map_revert(IN OUT cl_map_t * const p_map1,
+ IN OUT cl_map_t * const p_map2,
+ IN OUT cl_map_t * const p_new, IN OUT cl_map_t * const p_old)
{
- cl_status_t status;
+ cl_status_t status;
/* Restore the initial state. */
- status = cl_map_merge( p_map1, p_old );
- CL_ASSERT( status == CL_SUCCESS );
- status = cl_map_merge( p_map2, p_new );
- CL_ASSERT( status == CL_SUCCESS );
+ status = cl_map_merge(p_map1, p_old);
+ CL_ASSERT(status == CL_SUCCESS);
+ status = cl_map_merge(p_map2, p_new);
+ CL_ASSERT(status == CL_SUCCESS);
}
static cl_status_t
-__cl_map_delta_move(
- OUT cl_map_t* const p_dest,
- IN OUT cl_map_t* const p_src,
- IN OUT cl_map_iterator_t* const p_itor )
+__cl_map_delta_move(OUT cl_map_t * const p_dest,
+ IN OUT cl_map_t * const p_src,
+ IN OUT cl_map_iterator_t * const p_itor)
{
- cl_map_iterator_t next;
- void *p_obj, *p_obj2;
- uint64_t key;
+ cl_map_iterator_t next;
+ void *p_obj, *p_obj2;
+ uint64_t key;
/* Get a valid iterator so we can continue the loop. */
- next = cl_map_next( *p_itor );
+ next = cl_map_next(*p_itor);
/* Get the pointer to the object for insertion. */
- p_obj = cl_map_obj( *p_itor );
+ p_obj = cl_map_obj(*p_itor);
/* Get the key for the object. */
- key = cl_map_key( *p_itor );
+ key = cl_map_key(*p_itor);
/* Move the object. */
- cl_map_remove_item( p_src, *p_itor );
- p_obj2 = cl_map_insert( p_dest, key, p_obj );
+ cl_map_remove_item(p_src, *p_itor);
+ p_obj2 = cl_map_insert(p_dest, key, p_obj);
/* Check for failure. We should never get a duplicate. */
- if( !p_obj2 )
- {
- p_obj2 = cl_map_insert( p_src, key, p_obj );
- CL_ASSERT( p_obj2 == p_obj );
- return( CL_INSUFFICIENT_MEMORY );
+ if (!p_obj2) {
+ p_obj2 = cl_map_insert(p_src, key, p_obj);
+ CL_ASSERT(p_obj2 == p_obj);
+ return (CL_INSUFFICIENT_MEMORY);
}
/* We should never get a duplicate */
- CL_ASSERT( p_obj == p_obj2 );
+ CL_ASSERT(p_obj == p_obj2);
/* Update the iterator so that it is valid. */
(*p_itor) = next;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
cl_status_t
-cl_map_delta(
- IN OUT cl_map_t* const p_map1,
- IN OUT cl_map_t* const p_map2,
- OUT cl_map_t* const p_new,
- OUT cl_map_t* const p_old )
+cl_map_delta(IN OUT cl_map_t * const p_map1,
+ IN OUT cl_map_t * const p_map2,
+ OUT cl_map_t * const p_new, OUT cl_map_t * const p_old)
{
- cl_map_iterator_t itor1, itor2;
- uint64_t key1, key2;
- cl_status_t status;
+ cl_map_iterator_t itor1, itor2;
+ uint64_t key1, key2;
+ cl_status_t status;
- CL_ASSERT( p_map1 );
- CL_ASSERT( p_map2 );
- CL_ASSERT( p_new );
- CL_ASSERT( p_old );
- CL_ASSERT( cl_is_map_empty( p_new ) );
- CL_ASSERT( cl_is_map_empty( p_old ) );
+ CL_ASSERT(p_map1);
+ CL_ASSERT(p_map2);
+ CL_ASSERT(p_new);
+ CL_ASSERT(p_old);
+ CL_ASSERT(cl_is_map_empty(p_new));
+ CL_ASSERT(cl_is_map_empty(p_old));
- itor1 = cl_map_head( p_map1 );
- itor2 = cl_map_head( p_map2 );
+ itor1 = cl_map_head(p_map1);
+ itor2 = cl_map_head(p_map2);
/*
* Note that the check is for the end, since duplicate items will remain
* in their respective maps.
*/
- while( itor1 != cl_map_end( p_map1 ) &&
- itor2 != cl_map_end( p_map2 ) )
- {
- key1 = cl_map_key( itor1 );
- key2 = cl_map_key( itor2 );
- if( key1 < key2 )
- {
- status = __cl_map_delta_move( p_old, p_map1, &itor1 );
+ while (itor1 != cl_map_end(p_map1) && itor2 != cl_map_end(p_map2)) {
+ key1 = cl_map_key(itor1);
+ key2 = cl_map_key(itor2);
+ if (key1 < key2) {
+ status = __cl_map_delta_move(p_old, p_map1, &itor1);
/* Check for failure. */
- if( status != CL_SUCCESS )
- {
+ if (status != CL_SUCCESS) {
/* Restore the initial state. */
- __cl_map_revert( p_map1, p_map2, p_new, p_old );
+ __cl_map_revert(p_map1, p_map2, p_new, p_old);
/* Return the failure status. */
- return( status );
+ return (status);
}
- }
- else if( key1 > key2 )
- {
- status = __cl_map_delta_move( p_new, p_map2, &itor2 );
- if( status != CL_SUCCESS )
- {
+ } else if (key1 > key2) {
+ status = __cl_map_delta_move(p_new, p_map2, &itor2);
+ if (status != CL_SUCCESS) {
/* Restore the initial state. */
- __cl_map_revert( p_map1, p_map2, p_new, p_old );
+ __cl_map_revert(p_map1, p_map2, p_new, p_old);
/* Return the failure status. */
- return( status );
+ return (status);
}
- }
- else
- {
+ } else {
/* Move both forward since they have the same key. */
- itor1 = cl_map_next( itor1 );
- itor2 = cl_map_next( itor2 );
+ itor1 = cl_map_next(itor1);
+ itor2 = cl_map_next(itor2);
}
}
/* Process the remainder if either source map is empty. */
- while( itor2 != cl_map_end( p_map2 ) )
- {
- status = __cl_map_delta_move( p_new, p_map2, &itor2 );
- if( status != CL_SUCCESS )
- {
+ while (itor2 != cl_map_end(p_map2)) {
+ status = __cl_map_delta_move(p_new, p_map2, &itor2);
+ if (status != CL_SUCCESS) {
/* Restore the initial state. */
- __cl_map_revert( p_map1, p_map2, p_new, p_old );
+ __cl_map_revert(p_map1, p_map2, p_new, p_old);
/* Return the failure status. */
- return( status );
+ return (status);
}
}
- while( itor1 != cl_map_end( p_map1 ) )
- {
- status = __cl_map_delta_move( p_old, p_map1, &itor1 );
- if( status != CL_SUCCESS )
- {
+ while (itor1 != cl_map_end(p_map1)) {
+ status = __cl_map_delta_move(p_old, p_map1, &itor1);
+ if (status != CL_SUCCESS) {
/* Restore the initial state. */
- __cl_map_revert( p_map1, p_map2, p_new, p_old );
+ __cl_map_revert(p_map1, p_map2, p_new, p_old);
/* Return the failure status. */
- return( status );
+ return (status);
}
}
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
/******************************************************************************
@@ -1129,44 +1013,39 @@ cl_map_delta(
/*
* Get the root.
*/
-static inline cl_fmap_item_t*
-__cl_fmap_root(
- IN const cl_fmap_t* const p_map )
+static inline cl_fmap_item_t *__cl_fmap_root(IN const cl_fmap_t * const p_map)
{
- CL_ASSERT( p_map );
- return( p_map->root.p_left );
+ CL_ASSERT(p_map);
+ return (p_map->root.p_left);
}
/*
* Returns whether a given item is on the left of its parent.
*/
-static boolean_t
-__cl_fmap_is_left_child(
- IN const cl_fmap_item_t* const p_item )
+static boolean_t __cl_fmap_is_left_child(IN const cl_fmap_item_t * const p_item)
{
- CL_ASSERT( p_item );
- CL_ASSERT( p_item->p_up );
- CL_ASSERT( p_item->p_up != p_item );
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item->p_up);
+ CL_ASSERT(p_item->p_up != p_item);
- return( p_item->p_up->p_left == p_item );
+ return (p_item->p_up->p_left == p_item);
}
/*
* Retrieve the pointer to the parent's pointer to an item.
*/
-static cl_fmap_item_t**
-__cl_fmap_get_parent_ptr_to_item(
- IN cl_fmap_item_t* const p_item )
+static cl_fmap_item_t **__cl_fmap_get_parent_ptr_to_item(IN cl_fmap_item_t *
+ const p_item)
{
- CL_ASSERT( p_item );
- CL_ASSERT( p_item->p_up );
- CL_ASSERT( p_item->p_up != p_item );
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item->p_up);
+ CL_ASSERT(p_item->p_up != p_item);
- if( __cl_fmap_is_left_child( p_item ) )
- return( &p_item->p_up->p_left );
+ if (__cl_fmap_is_left_child(p_item))
+ return (&p_item->p_up->p_left);
- CL_ASSERT( p_item->p_up->p_right == p_item );
- return( &p_item->p_up->p_right );
+ CL_ASSERT(p_item->p_up->p_right == p_item);
+ return (&p_item->p_up->p_right);
}
/*
@@ -1185,17 +1064,15 @@ __cl_fmap_get_parent_ptr_to_item(
* X Y X Y
*/
static void
-__cl_fmap_rot_left(
- IN cl_fmap_t* const p_map,
- IN cl_fmap_item_t* const p_item )
+__cl_fmap_rot_left(IN cl_fmap_t * const p_map, IN cl_fmap_item_t * const p_item)
{
- cl_fmap_item_t **pp_root;
+ cl_fmap_item_t **pp_root;
- CL_ASSERT( p_map );
- CL_ASSERT( p_item );
- CL_ASSERT( p_item->p_right != &p_map->nil );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item->p_right != &p_map->nil);
- pp_root = __cl_fmap_get_parent_ptr_to_item( p_item );
+ pp_root = __cl_fmap_get_parent_ptr_to_item(p_item);
/* Point R to C instead of A. */
*pp_root = p_item->p_right;
@@ -1208,7 +1085,7 @@ __cl_fmap_rot_left(
* Set B's parent to A. We trap for B being NIL since the
* caller may depend on NIL not changing.
*/
- if( (*pp_root)->p_left != &p_map->nil )
+ if ((*pp_root)->p_left != &p_map->nil)
(*pp_root)->p_left->p_up = p_item;
/* Set C's left to A. */
@@ -1233,18 +1110,17 @@ __cl_fmap_rot_left(
* X Y X Y
*/
static void
-__cl_fmap_rot_right(
- IN cl_fmap_t* const p_map,
- IN cl_fmap_item_t* const p_item )
+__cl_fmap_rot_right(IN cl_fmap_t * const p_map,
+ IN cl_fmap_item_t * const p_item)
{
- cl_fmap_item_t **pp_root;
+ cl_fmap_item_t **pp_root;
- CL_ASSERT( p_map );
- CL_ASSERT( p_item );
- CL_ASSERT( p_item->p_left != &p_map->nil );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item->p_left != &p_map->nil);
/* Point R to A instead of C. */
- pp_root = __cl_fmap_get_parent_ptr_to_item( p_item );
+ pp_root = __cl_fmap_get_parent_ptr_to_item(p_item);
(*pp_root) = p_item->p_left;
/* Set A's parent to R. */
(*pp_root)->p_up = p_item->p_up;
@@ -1255,7 +1131,7 @@ __cl_fmap_rot_right(
* Set B's parent to C. We trap for B being NIL since the
* caller may depend on NIL not changing.
*/
- if( (*pp_root)->p_right != &p_map->nil )
+ if ((*pp_root)->p_right != &p_map->nil)
(*pp_root)->p_right->p_up = p_item;
/* Set A's right to C. */
@@ -1264,15 +1140,12 @@ __cl_fmap_rot_right(
p_item->p_up = *pp_root;
}
-void
-cl_fmap_init(
- IN cl_fmap_t* const p_map,
- IN cl_pfn_fmap_cmp_t pfn_compare )
+void cl_fmap_init(IN cl_fmap_t * const p_map, IN cl_pfn_fmap_cmp_t pfn_compare)
{
- CL_ASSERT( p_map );
- CL_ASSERT( pfn_compare );
+ CL_ASSERT(p_map);
+ CL_ASSERT(pfn_compare);
- memset( p_map, 0, sizeof(cl_fmap_t) );
+ memset(p_map, 0, sizeof(cl_fmap_t));
/* special setup for the root node */
p_map->root.p_up = &p_map->root;
@@ -1291,86 +1164,78 @@ cl_fmap_init(
p_map->state = CL_INITIALIZED;
- cl_fmap_remove_all( p_map );
+ cl_fmap_remove_all(p_map);
}
-cl_fmap_item_t*
-cl_fmap_get(
- IN const cl_fmap_t* const p_map,
- IN const void* const p_key )
+cl_fmap_item_t *cl_fmap_get(IN const cl_fmap_t * const p_map,
+ IN const void *const p_key)
{
- cl_fmap_item_t *p_item;
- intn_t cmp;
+ cl_fmap_item_t *p_item;
+ intn_t cmp;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
- p_item = __cl_fmap_root( p_map );
+ p_item = __cl_fmap_root(p_map);
- while( p_item != &p_map->nil )
- {
- cmp = p_map->pfn_compare( p_key, p_item->p_key );
+ while (p_item != &p_map->nil) {
+ cmp = p_map->pfn_compare(p_key, p_item->p_key);
- if( !cmp )
- break; /* just right */
+ if (!cmp)
+ break; /* just right */
- if( cmp < 0 )
+ if (cmp < 0)
p_item = p_item->p_left; /* too small */
else
p_item = p_item->p_right; /* too big */
}
- return( p_item );
+ return (p_item);
}
-cl_fmap_item_t*
-cl_fmap_get_next(
- IN const cl_fmap_t* const p_map,
- IN const void* const p_key )
+cl_fmap_item_t *cl_fmap_get_next(IN const cl_fmap_t * const p_map,
+ IN const void *const p_key)
{
- cl_fmap_item_t *p_item;
- cl_fmap_item_t *p_item_found;
- intn_t cmp;
+ cl_fmap_item_t *p_item;
+ cl_fmap_item_t *p_item_found;
+ intn_t cmp;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
- p_item = __cl_fmap_root( p_map );
- p_item_found = (cl_fmap_item_t*)&p_map->nil;
+ p_item = __cl_fmap_root(p_map);
+ p_item_found = (cl_fmap_item_t *) & p_map->nil;
- while( p_item != &p_map->nil )
- {
- cmp = p_map->pfn_compare( p_key, p_item->p_key );
+ while (p_item != &p_map->nil) {
+ cmp = p_map->pfn_compare(p_key, p_item->p_key);
- if( cmp < 0 ){
+ if (cmp < 0) {
p_item_found = p_item;
p_item = p_item->p_left; /* too small */
- }else{
+ } else {
p_item = p_item->p_right; /* too big or match */
}
}
- return( p_item_found );
+ return (p_item_found);
}
void
-cl_fmap_apply_func(
- IN const cl_fmap_t* const p_map,
- IN cl_pfn_fmap_apply_t pfn_func,
- IN const void* const context )
+cl_fmap_apply_func(IN const cl_fmap_t * const p_map,
+ IN cl_pfn_fmap_apply_t pfn_func,
+ IN const void *const context)
{
- cl_fmap_item_t* p_fmap_item;
+ cl_fmap_item_t *p_fmap_item;
/* Note that context can have any arbitrary value. */
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
- CL_ASSERT( pfn_func );
-
- p_fmap_item = cl_fmap_head( p_map );
- while( p_fmap_item != cl_fmap_end( p_map ) )
- {
- pfn_func( p_fmap_item, (void*)context );
- p_fmap_item = cl_fmap_next( p_fmap_item );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_func);
+
+ p_fmap_item = cl_fmap_head(p_map);
+ while (p_fmap_item != cl_fmap_end(p_map)) {
+ pfn_func(p_fmap_item, (void *)context);
+ p_fmap_item = cl_fmap_next(p_fmap_item);
}
}
@@ -1378,24 +1243,19 @@ cl_fmap_apply_func(
* Balance a tree starting at a given item back to the root.
*/
static void
-__cl_fmap_ins_bal(
- IN cl_fmap_t* const p_map,
- IN cl_fmap_item_t* p_item )
+__cl_fmap_ins_bal(IN cl_fmap_t * const p_map, IN cl_fmap_item_t * p_item)
{
- cl_fmap_item_t* p_grand_uncle;
+ cl_fmap_item_t *p_grand_uncle;
- CL_ASSERT( p_map );
- CL_ASSERT( p_item );
- CL_ASSERT( p_item != &p_map->root );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item != &p_map->root);
- while( p_item->p_up->color == CL_MAP_RED )
- {
- if( __cl_fmap_is_left_child( p_item->p_up ) )
- {
+ while (p_item->p_up->color == CL_MAP_RED) {
+ if (__cl_fmap_is_left_child(p_item->p_up)) {
p_grand_uncle = p_item->p_up->p_up->p_right;
- CL_ASSERT( p_grand_uncle );
- if( p_grand_uncle->color == CL_MAP_RED )
- {
+ CL_ASSERT(p_grand_uncle);
+ if (p_grand_uncle->color == CL_MAP_RED) {
p_grand_uncle->color = CL_MAP_BLACK;
p_item->p_up->color = CL_MAP_BLACK;
p_item->p_up->p_up->color = CL_MAP_RED;
@@ -1403,21 +1263,17 @@ __cl_fmap_ins_bal(
continue;
}
- if( !__cl_fmap_is_left_child( p_item ) )
- {
+ if (!__cl_fmap_is_left_child(p_item)) {
p_item = p_item->p_up;
- __cl_fmap_rot_left( p_map, p_item );
+ __cl_fmap_rot_left(p_map, p_item);
}
p_item->p_up->color = CL_MAP_BLACK;
p_item->p_up->p_up->color = CL_MAP_RED;
- __cl_fmap_rot_right( p_map, p_item->p_up->p_up );
- }
- else
- {
+ __cl_fmap_rot_right(p_map, p_item->p_up->p_up);
+ } else {
p_grand_uncle = p_item->p_up->p_up->p_left;
- CL_ASSERT( p_grand_uncle );
- if( p_grand_uncle->color == CL_MAP_RED )
- {
+ CL_ASSERT(p_grand_uncle);
+ if (p_grand_uncle->color == CL_MAP_RED) {
p_grand_uncle->color = CL_MAP_BLACK;
p_item->p_up->color = CL_MAP_BLACK;
p_item->p_up->p_up->color = CL_MAP_RED;
@@ -1425,33 +1281,30 @@ __cl_fmap_ins_bal(
continue;
}
- if( __cl_fmap_is_left_child( p_item ) )
- {
+ if (__cl_fmap_is_left_child(p_item)) {
p_item = p_item->p_up;
- __cl_fmap_rot_right( p_map, p_item );
+ __cl_fmap_rot_right(p_map, p_item);
}
p_item->p_up->color = CL_MAP_BLACK;
p_item->p_up->p_up->color = CL_MAP_RED;
- __cl_fmap_rot_left( p_map, p_item->p_up->p_up );
+ __cl_fmap_rot_left(p_map, p_item->p_up->p_up);
}
}
}
-cl_fmap_item_t*
-cl_fmap_insert(
- IN cl_fmap_t* const p_map,
- IN const void* const p_key,
- IN cl_fmap_item_t* const p_item )
+cl_fmap_item_t *cl_fmap_insert(IN cl_fmap_t * const p_map,
+ IN const void *const p_key,
+ IN cl_fmap_item_t * const p_item)
{
- cl_fmap_item_t *p_insert_at, *p_comp_item;
- intn_t cmp = 0;
+ cl_fmap_item_t *p_insert_at, *p_comp_item;
+ intn_t cmp = 0;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
- CL_ASSERT( p_item );
- CL_ASSERT( p_map->root.p_up == &p_map->root );
- CL_ASSERT( p_map->root.color != CL_MAP_RED );
- CL_ASSERT( p_map->nil.color != CL_MAP_RED );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_map->root.p_up == &p_map->root);
+ CL_ASSERT(p_map->root.color != CL_MAP_RED);
+ CL_ASSERT(p_map->nil.color != CL_MAP_RED);
p_item->p_left = &p_map->nil;
p_item->p_right = &p_map->nil;
@@ -1460,56 +1313,50 @@ cl_fmap_insert(
/* Find the insertion location. */
p_insert_at = &p_map->root;
- p_comp_item = __cl_fmap_root( p_map );
+ p_comp_item = __cl_fmap_root(p_map);
- while( p_comp_item != &p_map->nil )
- {
+ while (p_comp_item != &p_map->nil) {
p_insert_at = p_comp_item;
- cmp = p_map->pfn_compare( p_key, p_insert_at->p_key );
+ cmp = p_map->pfn_compare(p_key, p_insert_at->p_key);
- if( !cmp )
- return( p_insert_at );
+ if (!cmp)
+ return (p_insert_at);
/* Traverse the tree until the correct insertion point is found. */
- if( cmp < 0 )
+ if (cmp < 0)
p_comp_item = p_insert_at->p_left;
else
p_comp_item = p_insert_at->p_right;
}
- CL_ASSERT( p_insert_at != &p_map->nil );
- CL_ASSERT( p_comp_item == &p_map->nil );
+ CL_ASSERT(p_insert_at != &p_map->nil);
+ CL_ASSERT(p_comp_item == &p_map->nil);
/* Insert the item. */
- if( p_insert_at == &p_map->root )
- {
+ if (p_insert_at == &p_map->root) {
p_insert_at->p_left = p_item;
/*
* Primitive insert places the new item in front of
* the existing item.
*/
- __cl_primitive_insert( &p_map->nil.pool_item.list_item,
- &p_item->pool_item.list_item );
- }
- else if( cmp < 0 )
- {
+ __cl_primitive_insert(&p_map->nil.pool_item.list_item,
+ &p_item->pool_item.list_item);
+ } else if (cmp < 0) {
p_insert_at->p_left = p_item;
/*
* Primitive insert places the new item in front of
* the existing item.
*/
- __cl_primitive_insert( &p_insert_at->pool_item.list_item,
- &p_item->pool_item.list_item );
- }
- else
- {
+ __cl_primitive_insert(&p_insert_at->pool_item.list_item,
+ &p_item->pool_item.list_item);
+ } else {
p_insert_at->p_right = p_item;
/*
* Primitive insert places the new item in front of
* the existing item.
*/
- __cl_primitive_insert( p_insert_at->pool_item.list_item.p_next,
- &p_item->pool_item.list_item );
+ __cl_primitive_insert(p_insert_at->pool_item.list_item.p_next,
+ &p_item->pool_item.list_item);
}
/* Increase the count. */
p_map->count++;
@@ -1521,9 +1368,9 @@ cl_fmap_insert(
* Rebalance as necessary as we retrace our path through the tree
* and update colors.
*/
- __cl_fmap_ins_bal( p_map, p_item );
+ __cl_fmap_ins_bal(p_map, p_item);
- __cl_fmap_root( p_map )->color = CL_MAP_BLACK;
+ __cl_fmap_root(p_map)->color = CL_MAP_BLACK;
/*
* Note that it is not necessary to re-color the nil node black because all
@@ -1536,34 +1383,27 @@ cl_fmap_insert(
p_item->p_map = p_map;
#endif
- return( p_item );
+ return (p_item);
}
static void
-__cl_fmap_del_bal(
- IN cl_fmap_t* const p_map,
- IN cl_fmap_item_t* p_item )
+__cl_fmap_del_bal(IN cl_fmap_t * const p_map, IN cl_fmap_item_t * p_item)
{
- cl_fmap_item_t *p_uncle;
+ cl_fmap_item_t *p_uncle;
- while( (p_item->color != CL_MAP_RED) && (p_item->p_up != &p_map->root) )
- {
- if( __cl_fmap_is_left_child( p_item ) )
- {
+ while ((p_item->color != CL_MAP_RED) && (p_item->p_up != &p_map->root)) {
+ if (__cl_fmap_is_left_child(p_item)) {
p_uncle = p_item->p_up->p_right;
- if( p_uncle->color == CL_MAP_RED )
- {
+ if (p_uncle->color == CL_MAP_RED) {
p_uncle->color = CL_MAP_BLACK;
p_item->p_up->color = CL_MAP_RED;
- __cl_fmap_rot_left( p_map, p_item->p_up );
+ __cl_fmap_rot_left(p_map, p_item->p_up);
p_uncle = p_item->p_up->p_right;
}
- if( p_uncle->p_right->color != CL_MAP_RED )
- {
- if( p_uncle->p_left->color != CL_MAP_RED )
- {
+ if (p_uncle->p_right->color != CL_MAP_RED) {
+ if (p_uncle->p_left->color != CL_MAP_RED) {
p_uncle->color = CL_MAP_RED;
p_item = p_item->p_up;
continue;
@@ -1571,31 +1411,26 @@ __cl_fmap_del_bal(
p_uncle->p_left->color = CL_MAP_BLACK;
p_uncle->color = CL_MAP_RED;
- __cl_fmap_rot_right( p_map, p_uncle );
+ __cl_fmap_rot_right(p_map, p_uncle);
p_uncle = p_item->p_up->p_right;
}
p_uncle->color = p_item->p_up->color;
p_item->p_up->color = CL_MAP_BLACK;
p_uncle->p_right->color = CL_MAP_BLACK;
- __cl_fmap_rot_left( p_map, p_item->p_up );
+ __cl_fmap_rot_left(p_map, p_item->p_up);
break;
- }
- else
- {
+ } else {
p_uncle = p_item->p_up->p_left;
- if( p_uncle->color == CL_MAP_RED )
- {
+ if (p_uncle->color == CL_MAP_RED) {
p_uncle->color = CL_MAP_BLACK;
p_item->p_up->color = CL_MAP_RED;
- __cl_fmap_rot_right( p_map, p_item->p_up );
+ __cl_fmap_rot_right(p_map, p_item->p_up);
p_uncle = p_item->p_up->p_left;
}
- if( p_uncle->p_left->color != CL_MAP_RED )
- {
- if( p_uncle->p_right->color != CL_MAP_RED )
- {
+ if (p_uncle->p_left->color != CL_MAP_RED) {
+ if (p_uncle->p_right->color != CL_MAP_RED) {
p_uncle->color = CL_MAP_RED;
p_item = p_item->p_up;
continue;
@@ -1603,13 +1438,13 @@ __cl_fmap_del_bal(
p_uncle->p_right->color = CL_MAP_BLACK;
p_uncle->color = CL_MAP_RED;
- __cl_fmap_rot_left( p_map, p_uncle );
+ __cl_fmap_rot_left(p_map, p_uncle);
p_uncle = p_item->p_up->p_left;
}
p_uncle->color = p_item->p_up->color;
p_item->p_up->color = CL_MAP_BLACK;
p_uncle->p_left->color = CL_MAP_BLACK;
- __cl_fmap_rot_right( p_map, p_item->p_up );
+ __cl_fmap_rot_right(p_map, p_item->p_up);
break;
}
}
@@ -1617,27 +1452,23 @@ __cl_fmap_del_bal(
}
void
-cl_fmap_remove_item(
- IN cl_fmap_t* const p_map,
- IN cl_fmap_item_t* const p_item )
+cl_fmap_remove_item(IN cl_fmap_t * const p_map,
+ IN cl_fmap_item_t * const p_item)
{
- cl_fmap_item_t *p_child, *p_del_item;
+ cl_fmap_item_t *p_child, *p_del_item;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
- CL_ASSERT( p_item );
- CL_ASSERT( p_item->p_map == p_map );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
+ CL_ASSERT(p_item);
+ CL_ASSERT(p_item->p_map == p_map);
- if( p_item == cl_fmap_end( p_map ) )
+ if (p_item == cl_fmap_end(p_map))
return;
- if( (p_item->p_right == &p_map->nil) || (p_item->p_left == &p_map->nil ) )
- {
+ if ((p_item->p_right == &p_map->nil) || (p_item->p_left == &p_map->nil)) {
/* The item being removed has children on at most on side. */
p_del_item = p_item;
- }
- else
- {
+ } else {
/*
* The item being removed has children on both side.
* We select the item that will replace it. After removing
@@ -1645,17 +1476,17 @@ cl_fmap_remove_item(
* correct topology. Exchanging the substitute for the item
* will finalize the removal.
*/
- p_del_item = cl_fmap_next( p_item );
- CL_ASSERT( p_del_item != &p_map->nil );
+ p_del_item = cl_fmap_next(p_item);
+ CL_ASSERT(p_del_item != &p_map->nil);
}
/* Remove the item from the list. */
- __cl_primitive_remove( &p_item->pool_item.list_item );
+ __cl_primitive_remove(&p_item->pool_item.list_item);
/* Decrement the item count. */
p_map->count--;
/* Get the pointer to the new root's child, if any. */
- if( p_del_item->p_left != &p_map->nil )
+ if (p_del_item->p_left != &p_map->nil)
p_child = p_del_item->p_left;
else
p_child = p_del_item->p_right;
@@ -1665,10 +1496,10 @@ cl_fmap_remove_item(
* This is inconsequential.
*/
p_child->p_up = p_del_item->p_up;
- (*__cl_fmap_get_parent_ptr_to_item( p_del_item )) = p_child;
+ (*__cl_fmap_get_parent_ptr_to_item(p_del_item)) = p_child;
- if( p_del_item->color != CL_MAP_RED )
- __cl_fmap_del_bal( p_map, p_child );
+ if (p_del_item->color != CL_MAP_RED)
+ __cl_fmap_del_bal(p_map, p_child);
/*
* Note that the splicing done below does not need to occur before
@@ -1676,8 +1507,7 @@ cl_fmap_remove_item(
* preceding code. The topology is preserved by the color assignment made
* below (reader should be reminded that p_del_item == p_item in some cases).
*/
- if( p_del_item != p_item )
- {
+ if (p_del_item != p_item) {
/*
* Finalize the removal of the specified item by exchanging it with
* the substitute which we removed above.
@@ -1685,13 +1515,13 @@ cl_fmap_remove_item(
p_del_item->p_up = p_item->p_up;
p_del_item->p_left = p_item->p_left;
p_del_item->p_right = p_item->p_right;
- (*__cl_fmap_get_parent_ptr_to_item( p_item )) = p_del_item;
+ (*__cl_fmap_get_parent_ptr_to_item(p_item)) = p_del_item;
p_item->p_right->p_up = p_del_item;
p_item->p_left->p_up = p_del_item;
p_del_item->color = p_item->color;
}
- CL_ASSERT( p_map->nil.color != CL_MAP_RED );
+ CL_ASSERT(p_map->nil.color != CL_MAP_RED);
#ifdef _DEBUG_
/* Clear the pointer to the map since the item has been removed. */
@@ -1699,125 +1529,112 @@ cl_fmap_remove_item(
#endif
}
-cl_fmap_item_t*
-cl_fmap_remove(
- IN cl_fmap_t* const p_map,
- IN const void* const p_key )
+cl_fmap_item_t *cl_fmap_remove(IN cl_fmap_t * const p_map,
+ IN const void *const p_key)
{
- cl_fmap_item_t *p_item;
+ cl_fmap_item_t *p_item;
- CL_ASSERT( p_map );
- CL_ASSERT( p_map->state == CL_INITIALIZED );
+ CL_ASSERT(p_map);
+ CL_ASSERT(p_map->state == CL_INITIALIZED);
/* Seek the node with the specified key */
- p_item = cl_fmap_get( p_map, p_key );
+ p_item = cl_fmap_get(p_map, p_key);
- cl_fmap_remove_item( p_map, p_item );
+ cl_fmap_remove_item(p_map, p_item);
- return( p_item );
+ return (p_item);
}
void
-cl_fmap_merge(
- OUT cl_fmap_t* const p_dest_map,
- IN OUT cl_fmap_t* const p_src_map )
+cl_fmap_merge(OUT cl_fmap_t * const p_dest_map,
+ IN OUT cl_fmap_t * const p_src_map)
{
- cl_fmap_item_t *p_item, *p_item2, *p_next;
+ cl_fmap_item_t *p_item, *p_item2, *p_next;
- CL_ASSERT( p_dest_map );
- CL_ASSERT( p_src_map );
+ CL_ASSERT(p_dest_map);
+ CL_ASSERT(p_src_map);
- p_item = cl_fmap_head( p_src_map );
+ p_item = cl_fmap_head(p_src_map);
- while( p_item != cl_fmap_end( p_src_map ) )
- {
- p_next = cl_fmap_next( p_item );
+ while (p_item != cl_fmap_end(p_src_map)) {
+ p_next = cl_fmap_next(p_item);
/* Remove the item from its current map. */
- cl_fmap_remove_item( p_src_map, p_item );
+ cl_fmap_remove_item(p_src_map, p_item);
/* Insert the item into the destination map. */
- p_item2 = cl_fmap_insert( p_dest_map, cl_fmap_key( p_item ), p_item );
+ p_item2 =
+ cl_fmap_insert(p_dest_map, cl_fmap_key(p_item), p_item);
/* Check that the item was successfully inserted. */
- if( p_item2 != p_item )
- {
+ if (p_item2 != p_item) {
/* Put the item in back in the source map. */
p_item2 =
- cl_fmap_insert( p_src_map, cl_fmap_key( p_item ), p_item );
- CL_ASSERT( p_item2 == p_item );
+ cl_fmap_insert(p_src_map, cl_fmap_key(p_item),
+ p_item);
+ CL_ASSERT(p_item2 == p_item);
}
p_item = p_next;
}
}
static void
-__cl_fmap_delta_move(
- IN OUT cl_fmap_t* const p_dest,
- IN OUT cl_fmap_t* const p_src,
- IN OUT cl_fmap_item_t** const pp_item )
+__cl_fmap_delta_move(IN OUT cl_fmap_t * const p_dest,
+ IN OUT cl_fmap_t * const p_src,
+ IN OUT cl_fmap_item_t ** const pp_item)
{
- cl_fmap_item_t *p_temp, *p_next;
+ cl_fmap_item_t *p_temp, *p_next;
/*
* Get the next item so that we can ensure that pp_item points to
* a valid item upon return from the function.
*/
- p_next = cl_fmap_next( *pp_item );
+ p_next = cl_fmap_next(*pp_item);
/* Move the old item from its current map the the old map. */
- cl_fmap_remove_item( p_src, *pp_item );
- p_temp = cl_fmap_insert( p_dest, cl_fmap_key( *pp_item ), *pp_item );
+ cl_fmap_remove_item(p_src, *pp_item);
+ p_temp = cl_fmap_insert(p_dest, cl_fmap_key(*pp_item), *pp_item);
/* We should never have duplicates. */
- CL_ASSERT( p_temp == *pp_item );
+ CL_ASSERT(p_temp == *pp_item);
/* Point pp_item to a valid item in the source map. */
(*pp_item) = p_next;
}
void
-cl_fmap_delta(
- IN OUT cl_fmap_t* const p_map1,
- IN OUT cl_fmap_t* const p_map2,
- OUT cl_fmap_t* const p_new,
- OUT cl_fmap_t* const p_old )
+cl_fmap_delta(IN OUT cl_fmap_t * const p_map1,
+ IN OUT cl_fmap_t * const p_map2,
+ OUT cl_fmap_t * const p_new, OUT cl_fmap_t * const p_old)
{
- cl_fmap_item_t *p_item1, *p_item2;
- intn_t cmp;
-
- CL_ASSERT( p_map1 );
- CL_ASSERT( p_map2 );
- CL_ASSERT( p_new );
- CL_ASSERT( p_old );
- CL_ASSERT( cl_is_fmap_empty( p_new ) );
- CL_ASSERT( cl_is_fmap_empty( p_old ) );
-
- p_item1 = cl_fmap_head( p_map1 );
- p_item2 = cl_fmap_head( p_map2 );
-
- while( p_item1 != cl_fmap_end( p_map1 ) &&
- p_item2 != cl_fmap_end( p_map2 ) )
- {
- cmp = p_map1->pfn_compare( cl_fmap_key( p_item1 ),
- cl_fmap_key( p_item2 ) );
- if( cmp < 0 )
- {
+ cl_fmap_item_t *p_item1, *p_item2;
+ intn_t cmp;
+
+ CL_ASSERT(p_map1);
+ CL_ASSERT(p_map2);
+ CL_ASSERT(p_new);
+ CL_ASSERT(p_old);
+ CL_ASSERT(cl_is_fmap_empty(p_new));
+ CL_ASSERT(cl_is_fmap_empty(p_old));
+
+ p_item1 = cl_fmap_head(p_map1);
+ p_item2 = cl_fmap_head(p_map2);
+
+ while (p_item1 != cl_fmap_end(p_map1) && p_item2 != cl_fmap_end(p_map2)) {
+ cmp = p_map1->pfn_compare(cl_fmap_key(p_item1),
+ cl_fmap_key(p_item2));
+ if (cmp < 0) {
/* We found an old item. */
- __cl_fmap_delta_move( p_old, p_map1, &p_item1 );
- }
- else if( cmp > 0 )
- {
+ __cl_fmap_delta_move(p_old, p_map1, &p_item1);
+ } else if (cmp > 0) {
/* We found a new item. */
- __cl_fmap_delta_move( p_new, p_map2, &p_item2 );
- }
- else
- {
+ __cl_fmap_delta_move(p_new, p_map2, &p_item2);
+ } else {
/* Move both forward since they have the same key. */
- p_item1 = cl_fmap_next( p_item1 );
- p_item2 = cl_fmap_next( p_item2 );
+ p_item1 = cl_fmap_next(p_item1);
+ p_item2 = cl_fmap_next(p_item2);
}
}
/* Process the remainder if the end of either source map was reached. */
- while( p_item2 != cl_fmap_end( p_map2 ) )
- __cl_fmap_delta_move( p_new, p_map2, &p_item2 );
+ while (p_item2 != cl_fmap_end(p_map2))
+ __cl_fmap_delta_move(p_new, p_map2, &p_item2);
- while( p_item1 != cl_fmap_end( p_map1 ) )
- __cl_fmap_delta_move( p_old, p_map1, &p_item1 );
+ while (p_item1 != cl_fmap_end(p_map1))
+ __cl_fmap_delta_move(p_old, p_map1, &p_item1);
}
diff --git a/opensm/complib/cl_pool.c b/opensm/complib/cl_pool.c
index 6ee1d98..1b3db3f 100644
--- a/opensm/complib/cl_pool.c
+++ b/opensm/complib/cl_pool.c
@@ -46,7 +46,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <string.h>
@@ -59,88 +59,85 @@
/*
* IMPLEMENTATION OF QUICK COMPOSITE POOL
*/
-void
-cl_qcpool_construct(
- IN cl_qcpool_t* const p_pool )
+void cl_qcpool_construct(IN cl_qcpool_t * const p_pool)
{
- CL_ASSERT( p_pool );
+ CL_ASSERT(p_pool);
- memset( p_pool, 0, sizeof(cl_qcpool_t) );
+ memset(p_pool, 0, sizeof(cl_qcpool_t));
p_pool->state = CL_UNINITIALIZED;
}
cl_status_t
-cl_qcpool_init(
- IN cl_qcpool_t* const p_pool,
- IN const size_t min_size,
- IN const size_t max_size,
- IN const size_t grow_size,
- IN const size_t* const component_sizes,
- IN const uint32_t num_components,
- IN cl_pfn_qcpool_init_t pfn_initializer OPTIONAL,
- IN cl_pfn_qcpool_dtor_t pfn_destructor OPTIONAL,
- IN const void* const context )
+cl_qcpool_init(IN cl_qcpool_t * const p_pool,
+ IN const size_t min_size,
+ IN const size_t max_size,
+ IN const size_t grow_size,
+ IN const size_t * const component_sizes,
+ IN const uint32_t num_components,
+ IN cl_pfn_qcpool_init_t pfn_initializer OPTIONAL,
+ IN cl_pfn_qcpool_dtor_t pfn_destructor OPTIONAL,
+ IN const void *const context)
{
- cl_status_t status;
- uint32_t i;
+ cl_status_t status;
+ uint32_t i;
- CL_ASSERT( p_pool );
+ CL_ASSERT(p_pool);
/* Must have a minimum of 1 component. */
- CL_ASSERT( num_components );
+ CL_ASSERT(num_components);
/* A component size array is required. */
- CL_ASSERT( component_sizes );
+ CL_ASSERT(component_sizes);
/*
* If no initializer is provided, the first component must be large
* enough to hold a pool item.
*/
- CL_ASSERT( pfn_initializer ||
- (component_sizes[0] >= sizeof(cl_pool_item_t)) );
+ CL_ASSERT(pfn_initializer ||
+ (component_sizes[0] >= sizeof(cl_pool_item_t)));
- cl_qcpool_construct( p_pool );
+ cl_qcpool_construct(p_pool);
- if( num_components > 1 && !pfn_initializer )
- return( CL_INVALID_SETTING );
+ if (num_components > 1 && !pfn_initializer)
+ return (CL_INVALID_SETTING);
- if( max_size && max_size < min_size )
- return( CL_INVALID_SETTING );
+ if (max_size && max_size < min_size)
+ return (CL_INVALID_SETTING);
/*
* Allocate the array of component sizes and component pointers all
* in one allocation.
*/
- p_pool->component_sizes = (size_t*)malloc(
- (sizeof(size_t) + sizeof(void*)) * num_components );
+ p_pool->component_sizes = (size_t *) malloc((sizeof(size_t) +
+ sizeof(void *)) *
+ num_components);
- if( !p_pool->component_sizes )
- return( CL_INSUFFICIENT_MEMORY );
+ if (!p_pool->component_sizes)
+ return (CL_INSUFFICIENT_MEMORY);
else
- memset( p_pool->component_sizes, 0,
- (sizeof(size_t) + sizeof(void*)) * num_components );
+ memset(p_pool->component_sizes, 0,
+ (sizeof(size_t) + sizeof(void *)) * num_components);
/* Calculate the pointer to the array of pointers, used for callbacks. */
p_pool->p_components =
- (void**)(p_pool->component_sizes + num_components);
+ (void **)(p_pool->component_sizes + num_components);
/* Copy the user's sizes into our array for future use. */
- memcpy( p_pool->component_sizes, component_sizes,
- sizeof(component_sizes[0]) * num_components );
+ memcpy(p_pool->component_sizes, component_sizes,
+ sizeof(component_sizes[0]) * num_components);
/* Store the number of components per object. */
p_pool->num_components = num_components;
/* Round up and store the size of the components. */
- for( i = 0; i < num_components; i++ )
- {
+ for (i = 0; i < num_components; i++) {
/*
* We roundup each component size so that all components
* are aligned on a natural boundary.
*/
p_pool->component_sizes[i] =
- ROUNDUP( p_pool->component_sizes[i], sizeof(uintn_t) );
+ ROUNDUP(p_pool->component_sizes[i], sizeof(uintn_t));
}
- p_pool->max_objects = max_size? max_size : ~(size_t)0;
+ p_pool->max_objects = max_size ? max_size : ~(size_t) 0;
p_pool->grow_size = grow_size;
/* Store callback function pointers. */
@@ -148,9 +145,9 @@ cl_qcpool_init(
p_pool->pfn_dtor = pfn_destructor; /* may be NULL */
p_pool->context = context;
- cl_qlist_init( &p_pool->alloc_list );
+ cl_qlist_init(&p_pool->alloc_list);
- cl_qlist_init( &p_pool->free_list );
+ cl_qlist_init(&p_pool->free_list);
/*
* We are now initialized. We change the initialized flag before
@@ -159,28 +156,25 @@ cl_qcpool_init(
p_pool->state = CL_INITIALIZED;
/* Allocate the minimum number of objects as requested. */
- if( !min_size )
- return( CL_SUCCESS );
+ if (!min_size)
+ return (CL_SUCCESS);
- status = cl_qcpool_grow( p_pool, min_size );
+ status = cl_qcpool_grow(p_pool, min_size);
/* Trap for error and cleanup if necessary. */
- if( status != CL_SUCCESS )
- cl_qcpool_destroy( p_pool );
+ if (status != CL_SUCCESS)
+ cl_qcpool_destroy(p_pool);
- return( status );
+ return (status);
}
-void
-cl_qcpool_destroy(
- IN cl_qcpool_t* const p_pool )
+void cl_qcpool_destroy(IN cl_qcpool_t * const p_pool)
{
/* CL_ASSERT that a non-NULL pointer was provided. */
- CL_ASSERT( p_pool );
+ CL_ASSERT(p_pool);
/* CL_ASSERT that we are in a valid state (not uninitialized memory). */
- CL_ASSERT( cl_is_state_valid( p_pool->state ) );
+ CL_ASSERT(cl_is_state_valid(p_pool->state));
- if( p_pool->state == CL_INITIALIZED )
- {
+ if (p_pool->state == CL_INITIALIZED) {
/*
* Assert if the user hasn't put everything back in the pool
* before destroying it
@@ -188,31 +182,27 @@ cl_qcpool_destroy(
* that will be freed, and the destructor will not be called!
*/
#ifdef _DEBUG_
- /* but we do not want "free" version to assert on this one */
- CL_ASSERT( cl_qcpool_count( p_pool ) == p_pool->num_objects );
+ /* but we do not want "free" version to assert on this one */
+ CL_ASSERT(cl_qcpool_count(p_pool) == p_pool->num_objects);
#endif
/* call the user's destructor for each object in the pool */
- if( p_pool->pfn_dtor )
- {
- while( !cl_is_qlist_empty( &p_pool->free_list ) )
- {
- p_pool->pfn_dtor( (cl_pool_item_t*)
- cl_qlist_remove_head( &p_pool->free_list ),
- (void*)p_pool->context );
+ if (p_pool->pfn_dtor) {
+ while (!cl_is_qlist_empty(&p_pool->free_list)) {
+ p_pool->pfn_dtor((cl_pool_item_t *)
+ cl_qlist_remove_head(&p_pool->
+ free_list),
+ (void *)p_pool->context);
}
- }
- else
- {
- cl_qlist_remove_all( &p_pool->free_list );
+ } else {
+ cl_qlist_remove_all(&p_pool->free_list);
}
/* Free all allocated memory blocks. */
- while( !cl_is_qlist_empty( &p_pool->alloc_list ) )
- free( cl_qlist_remove_head( &p_pool->alloc_list ) );
+ while (!cl_is_qlist_empty(&p_pool->alloc_list))
+ free(cl_qlist_remove_head(&p_pool->alloc_list));
- if( p_pool->component_sizes )
- {
- free( p_pool->component_sizes );
+ if (p_pool->component_sizes) {
+ free(p_pool->component_sizes);
p_pool->component_sizes = NULL;
}
}
@@ -220,93 +210,90 @@ cl_qcpool_destroy(
p_pool->state = CL_UNINITIALIZED;
}
-cl_status_t
-cl_qcpool_grow(
- IN cl_qcpool_t* const p_pool,
- IN size_t obj_count )
+cl_status_t cl_qcpool_grow(IN cl_qcpool_t * const p_pool, IN size_t obj_count)
{
- cl_status_t status = CL_SUCCESS;
- uint8_t *p_objects;
- cl_pool_item_t *p_pool_item;
- uint32_t i;
- size_t obj_size;
+ cl_status_t status = CL_SUCCESS;
+ uint8_t *p_objects;
+ cl_pool_item_t *p_pool_item;
+ uint32_t i;
+ size_t obj_size;
- CL_ASSERT( p_pool );
- CL_ASSERT( p_pool->state == CL_INITIALIZED );
- CL_ASSERT( obj_count );
+ CL_ASSERT(p_pool);
+ CL_ASSERT(p_pool->state == CL_INITIALIZED);
+ CL_ASSERT(obj_count);
/* Validate that growth is possible. */
- if( p_pool->num_objects == p_pool->max_objects )
- return( CL_INSUFFICIENT_MEMORY );
+ if (p_pool->num_objects == p_pool->max_objects)
+ return (CL_INSUFFICIENT_MEMORY);
/* Cap the growth to the desired maximum. */
- if( obj_count > (p_pool->max_objects - p_pool->num_objects) )
+ if (obj_count > (p_pool->max_objects - p_pool->num_objects))
obj_count = p_pool->max_objects - p_pool->num_objects;
/* Calculate the size of an object. */
obj_size = 0;
- for( i = 0; i < p_pool->num_components; i++ )
+ for (i = 0; i < p_pool->num_components; i++)
obj_size += p_pool->component_sizes[i];
/* Allocate the buffer for the new objects. */
- p_objects = (uint8_t*)
- malloc( sizeof(cl_list_item_t) + (obj_size * obj_count) );
+ p_objects = (uint8_t *)
+ malloc(sizeof(cl_list_item_t) + (obj_size * obj_count));
/* Make sure the allocation succeeded. */
- if( !p_objects )
- return( CL_INSUFFICIENT_MEMORY );
+ if (!p_objects)
+ return (CL_INSUFFICIENT_MEMORY);
else
- memset( p_objects, 0,
- sizeof(cl_list_item_t) + (obj_size * obj_count) );
+ memset(p_objects, 0,
+ sizeof(cl_list_item_t) + (obj_size * obj_count));
/* Insert the allocation in our list. */
- cl_qlist_insert_tail( &p_pool->alloc_list, (cl_list_item_t*)p_objects );
+ cl_qlist_insert_tail(&p_pool->alloc_list, (cl_list_item_t *) p_objects);
p_objects += sizeof(cl_list_item_t);
/* initialize the new elements and add them to the free list */
- while( obj_count-- )
- {
+ while (obj_count--) {
/* Setup the array of components for the current object. */
p_pool->p_components[0] = p_objects;
- for( i = 1; i < p_pool->num_components; i++ )
- {
+ for (i = 1; i < p_pool->num_components; i++) {
/* Calculate the pointer to the next component. */
- p_pool->p_components[i] = (uint8_t*)p_pool->p_components[i-1] +
- p_pool->component_sizes[i-1];
+ p_pool->p_components[i] =
+ (uint8_t *) p_pool->p_components[i - 1] +
+ p_pool->component_sizes[i - 1];
}
/*
* call the user's initializer
* this can fail!
*/
- if( p_pool->pfn_init )
- {
+ if (p_pool->pfn_init) {
p_pool_item = NULL;
- status = p_pool->pfn_init( p_pool->p_components,
- p_pool->num_components, (void*)p_pool->context, &p_pool_item );
- if( status != CL_SUCCESS )
- {
+ status = p_pool->pfn_init(p_pool->p_components,
+ p_pool->num_components,
+ (void *)p_pool->context,
+ &p_pool_item);
+ if (status != CL_SUCCESS) {
/*
* User initialization failed
* we may have only grown the pool by some partial amount
* Invoke the destructor for the object that failed
* initialization.
*/
- if( p_pool->pfn_dtor )
- p_pool->pfn_dtor( p_pool_item, (void*)p_pool->context );
+ if (p_pool->pfn_dtor)
+ p_pool->pfn_dtor(p_pool_item,
+ (void *)p_pool->
+ context);
/* Return the user's status. */
- return( status );
+ return (status);
}
- CL_ASSERT( p_pool_item );
- }
- else
- {
+ CL_ASSERT(p_pool_item);
+ } else {
/*
* If no initializer is provided, assume that the pool item
* is stored at the beginning of the first component.
*/
- p_pool_item = (cl_pool_item_t*)p_pool->p_components[0];
+ p_pool_item =
+ (cl_pool_item_t *) p_pool->p_components[0];
}
#ifdef _DEBUG_
@@ -318,7 +305,8 @@ cl_qcpool_grow(
#endif
/* Insert the new item in the free list, traping for failure. */
- cl_qlist_insert_head( &p_pool->free_list, &p_pool_item->list_item );
+ cl_qlist_insert_head(&p_pool->free_list,
+ &p_pool_item->list_item);
p_pool->num_objects++;
@@ -326,75 +314,69 @@ cl_qcpool_grow(
p_objects += obj_size;
}
- return( status );
+ return (status);
}
-cl_pool_item_t*
-cl_qcpool_get(
- IN cl_qcpool_t* const p_pool )
+cl_pool_item_t *cl_qcpool_get(IN cl_qcpool_t * const p_pool)
{
- cl_list_item_t *p_list_item;
+ cl_list_item_t *p_list_item;
- CL_ASSERT( p_pool );
- CL_ASSERT( p_pool->state == CL_INITIALIZED );
+ CL_ASSERT(p_pool);
+ CL_ASSERT(p_pool->state == CL_INITIALIZED);
- if( cl_is_qlist_empty( &p_pool->free_list ) )
- {
+ if (cl_is_qlist_empty(&p_pool->free_list)) {
/*
* No object is available.
* Return NULL if the user does not want automatic growth.
*/
- if( !p_pool->grow_size )
- return( NULL );
+ if (!p_pool->grow_size)
+ return (NULL);
/* We ran out of elements. Get more */
- cl_qcpool_grow( p_pool, p_pool->grow_size );
+ cl_qcpool_grow(p_pool, p_pool->grow_size);
/*
* We may not have gotten everything we wanted but we might have
* gotten something.
*/
- if( cl_is_qlist_empty( &p_pool->free_list ) )
- return( NULL );
+ if (cl_is_qlist_empty(&p_pool->free_list))
+ return (NULL);
}
- p_list_item = cl_qlist_remove_head( &p_pool->free_list );
+ p_list_item = cl_qlist_remove_head(&p_pool->free_list);
/* OK, at this point we have an object */
- CL_ASSERT( p_list_item != cl_qlist_end( &p_pool->free_list ) );
- return( (cl_pool_item_t*)p_list_item );
+ CL_ASSERT(p_list_item != cl_qlist_end(&p_pool->free_list));
+ return ((cl_pool_item_t *) p_list_item);
}
-cl_pool_item_t*
-cl_qcpool_get_tail(
- IN cl_qcpool_t* const p_pool )
+cl_pool_item_t *cl_qcpool_get_tail(IN cl_qcpool_t * const p_pool)
{
- cl_list_item_t *p_list_item;
+ cl_list_item_t *p_list_item;
- CL_ASSERT( p_pool );
- CL_ASSERT( p_pool->state == CL_INITIALIZED );
+ CL_ASSERT(p_pool);
+ CL_ASSERT(p_pool->state == CL_INITIALIZED);
- if( cl_is_qlist_empty( &p_pool->free_list ) )
- {
+ if (cl_is_qlist_empty(&p_pool->free_list)) {
/*
* No object is available.
* Return NULL if the user does not want automatic growth.
*/
- if( !p_pool->grow_size )
- return( NULL );
+ if (!p_pool->grow_size)
+ return (NULL);
/* We ran out of elements. Get more */
- cl_qcpool_grow( p_pool, p_pool->grow_size );
+ cl_qcpool_grow(p_pool, p_pool->grow_size);
/*
* We may not have gotten everything we wanted but we might have
* gotten something.
*/
- if( cl_is_qlist_empty( &p_pool->free_list ) )
- return( NULL );
+ if (cl_is_qlist_empty(&p_pool->free_list))
+ return (NULL);
}
- p_list_item = cl_qlist_remove_tail( &p_pool->free_list );
+ p_list_item = cl_qlist_remove_tail(&p_pool->free_list);
/* OK, at this point we have an object */
- CL_ASSERT( p_list_item != cl_qlist_end( &p_pool->free_list ) );
- return( (cl_pool_item_t*)p_list_item );
+ CL_ASSERT(p_list_item != cl_qlist_end(&p_pool->free_list));
+ return ((cl_pool_item_t *) p_list_item);
}
/*
@@ -406,22 +388,21 @@ cl_qcpool_get_tail(
* initializer callback.
*/
static cl_status_t
-__cl_qpool_init_cb(
- IN void** const p_comp_array,
- IN const uint32_t num_components,
- IN void* const context,
- OUT cl_pool_item_t** const pp_pool_item )
+__cl_qpool_init_cb(IN void **const p_comp_array,
+ IN const uint32_t num_components,
+ IN void *const context,
+ OUT cl_pool_item_t ** const pp_pool_item)
{
- cl_qpool_t *p_pool = (cl_qpool_t*)context;
+ cl_qpool_t *p_pool = (cl_qpool_t *) context;
- CL_ASSERT( p_pool );
- CL_ASSERT( p_pool->pfn_init );
- CL_ASSERT( num_components == 1 );
+ CL_ASSERT(p_pool);
+ CL_ASSERT(p_pool->pfn_init);
+ CL_ASSERT(num_components == 1);
- UNUSED_PARAM( num_components );
+ UNUSED_PARAM(num_components);
- return( p_pool->pfn_init( p_comp_array[0], (void*)p_pool->context,
- pp_pool_item ) );
+ return (p_pool->pfn_init(p_comp_array[0], (void *)p_pool->context,
+ pp_pool_item));
}
/*
@@ -429,51 +410,49 @@ __cl_qpool_init_cb(
* destructor callback.
*/
static void
-__cl_qpool_dtor_cb(
- IN const cl_pool_item_t* const p_pool_item,
- IN void* const context )
+__cl_qpool_dtor_cb(IN const cl_pool_item_t * const p_pool_item,
+ IN void *const context)
{
- cl_qpool_t *p_pool = (cl_qpool_t*)context;
+ cl_qpool_t *p_pool = (cl_qpool_t *) context;
- CL_ASSERT( p_pool );
- CL_ASSERT( p_pool->pfn_dtor );
+ CL_ASSERT(p_pool);
+ CL_ASSERT(p_pool->pfn_dtor);
- p_pool->pfn_dtor( p_pool_item, (void*)p_pool->context );
+ p_pool->pfn_dtor(p_pool_item, (void *)p_pool->context);
}
-void
-cl_qpool_construct(
- IN cl_qpool_t* const p_pool )
+void cl_qpool_construct(IN cl_qpool_t * const p_pool)
{
- memset( p_pool, 0, sizeof(cl_qpool_t) );
+ memset(p_pool, 0, sizeof(cl_qpool_t));
- cl_qcpool_construct( &p_pool->qcpool );
+ cl_qcpool_construct(&p_pool->qcpool);
}
cl_status_t
-cl_qpool_init(
- IN cl_qpool_t* const p_pool,
- IN const size_t min_size,
- IN const size_t max_size,
- IN const size_t grow_size,
- IN const size_t object_size,
- IN cl_pfn_qpool_init_t pfn_initializer OPTIONAL,
- IN cl_pfn_qpool_dtor_t pfn_destructor OPTIONAL,
- IN const void* const context )
+cl_qpool_init(IN cl_qpool_t * const p_pool,
+ IN const size_t min_size,
+ IN const size_t max_size,
+ IN const size_t grow_size,
+ IN const size_t object_size,
+ IN cl_pfn_qpool_init_t pfn_initializer OPTIONAL,
+ IN cl_pfn_qpool_dtor_t pfn_destructor OPTIONAL,
+ IN const void *const context)
{
cl_status_t status;
- CL_ASSERT( p_pool );
+ CL_ASSERT(p_pool);
p_pool->pfn_init = pfn_initializer; /* may be NULL */
p_pool->pfn_dtor = pfn_destructor; /* may be NULL */
p_pool->context = context;
- status = cl_qcpool_init( &p_pool->qcpool, min_size, max_size, grow_size,
- &object_size, 1, pfn_initializer ? __cl_qpool_init_cb : NULL,
- pfn_destructor ? __cl_qpool_dtor_cb : NULL, p_pool );
+ status = cl_qcpool_init(&p_pool->qcpool, min_size, max_size, grow_size,
+ &object_size, 1,
+ pfn_initializer ? __cl_qpool_init_cb : NULL,
+ pfn_destructor ? __cl_qpool_dtor_cb : NULL,
+ p_pool);
- return( status );
+ return (status);
}
/*
@@ -485,28 +464,27 @@ cl_qpool_init(
* initializer callback.
*/
static cl_status_t
-__cl_cpool_init_cb(
- IN void** const p_comp_array,
- IN const uint32_t num_components,
- IN void* const context,
- OUT cl_pool_item_t** const pp_pool_item )
+__cl_cpool_init_cb(IN void **const p_comp_array,
+ IN const uint32_t num_components,
+ IN void *const context,
+ OUT cl_pool_item_t ** const pp_pool_item)
{
- cl_cpool_t *p_pool = (cl_cpool_t*)context;
- cl_pool_obj_t *p_pool_obj;
- cl_status_t status = CL_SUCCESS;
+ cl_cpool_t *p_pool = (cl_cpool_t *) context;
+ cl_pool_obj_t *p_pool_obj;
+ cl_status_t status = CL_SUCCESS;
- CL_ASSERT( p_pool );
+ CL_ASSERT(p_pool);
/*
* Set our pointer to the list item, which is stored at the beginning of
* the first component.
*/
- p_pool_obj = (cl_pool_obj_t*)p_comp_array[0];
+ p_pool_obj = (cl_pool_obj_t *) p_comp_array[0];
/* Set the pool item pointer for the caller. */
*pp_pool_item = &p_pool_obj->pool_item;
/* Calculate the pointer to the user's first component. */
- p_comp_array[0] = ((uint8_t*)p_comp_array[0]) + sizeof(cl_pool_obj_t);
+ p_comp_array[0] = ((uint8_t *) p_comp_array[0]) + sizeof(cl_pool_obj_t);
/*
* Set the object pointer in the pool object to point to the first of the
@@ -515,13 +493,12 @@ __cl_cpool_init_cb(
p_pool_obj->p_object = p_comp_array[0];
/* Invoke the user's constructor callback. */
- if( p_pool->pfn_init )
- {
- status = p_pool->pfn_init( p_comp_array, num_components,
- (void*)p_pool->context );
+ if (p_pool->pfn_init) {
+ status = p_pool->pfn_init(p_comp_array, num_components,
+ (void *)p_pool->context);
}
- return( status );
+ return (status);
}
/*
@@ -529,49 +506,45 @@ __cl_cpool_init_cb(
* destructor callback.
*/
static void
-__cl_cpool_dtor_cb(
- IN const cl_pool_item_t* const p_pool_item,
- IN void* const context )
+__cl_cpool_dtor_cb(IN const cl_pool_item_t * const p_pool_item,
+ IN void *const context)
{
- cl_cpool_t *p_pool = (cl_cpool_t*)context;
+ cl_cpool_t *p_pool = (cl_cpool_t *) context;
- CL_ASSERT( p_pool );
- CL_ASSERT( p_pool->pfn_dtor );
- CL_ASSERT( ((cl_pool_obj_t*)p_pool_item)->p_object );
+ CL_ASSERT(p_pool);
+ CL_ASSERT(p_pool->pfn_dtor);
+ CL_ASSERT(((cl_pool_obj_t *) p_pool_item)->p_object);
/* Invoke the user's destructor callback. */
- p_pool->pfn_dtor( (void*)((cl_pool_obj_t*)p_pool_item)->p_object,
- (void*)p_pool->context );
+ p_pool->pfn_dtor((void *)((cl_pool_obj_t *) p_pool_item)->p_object,
+ (void *)p_pool->context);
}
-void
-cl_cpool_construct(
- IN cl_cpool_t* const p_pool )
+void cl_cpool_construct(IN cl_cpool_t * const p_pool)
{
- CL_ASSERT( p_pool );
+ CL_ASSERT(p_pool);
- memset( p_pool, 0, sizeof(cl_cpool_t) );
+ memset(p_pool, 0, sizeof(cl_cpool_t));
- cl_qcpool_construct( &p_pool->qcpool );
+ cl_qcpool_construct(&p_pool->qcpool);
}
cl_status_t
-cl_cpool_init(
- IN cl_cpool_t* const p_pool,
- IN const size_t min_size,
- IN const size_t max_size,
- IN const size_t grow_size,
- IN size_t* const component_sizes,
- IN const uint32_t num_components,
- IN cl_pfn_cpool_init_t pfn_initializer OPTIONAL,
- IN cl_pfn_cpool_dtor_t pfn_destructor OPTIONAL,
- IN const void* const context )
+cl_cpool_init(IN cl_cpool_t * const p_pool,
+ IN const size_t min_size,
+ IN const size_t max_size,
+ IN const size_t grow_size,
+ IN size_t * const component_sizes,
+ IN const uint32_t num_components,
+ IN cl_pfn_cpool_init_t pfn_initializer OPTIONAL,
+ IN cl_pfn_cpool_dtor_t pfn_destructor OPTIONAL,
+ IN const void *const context)
{
- cl_status_t status;
+ cl_status_t status;
- CL_ASSERT( p_pool );
- CL_ASSERT( num_components );
- CL_ASSERT( component_sizes );
+ CL_ASSERT(p_pool);
+ CL_ASSERT(num_components);
+ CL_ASSERT(component_sizes);
/* Add the size of the pool object to the first component. */
component_sizes[0] += sizeof(cl_pool_obj_t);
@@ -581,15 +554,16 @@ cl_cpool_init(
p_pool->pfn_dtor = pfn_destructor; /* may be NULL */
p_pool->context = context;
- status = cl_qcpool_init( &p_pool->qcpool, min_size, max_size, grow_size,
- component_sizes, num_components, __cl_cpool_init_cb,
- pfn_destructor ? __cl_cpool_dtor_cb : NULL,
- p_pool );
+ status = cl_qcpool_init(&p_pool->qcpool, min_size, max_size, grow_size,
+ component_sizes, num_components,
+ __cl_cpool_init_cb,
+ pfn_destructor ? __cl_cpool_dtor_cb : NULL,
+ p_pool);
/* Restore the original value of the first component. */
component_sizes[0] -= sizeof(cl_pool_obj_t);
- return( status );
+ return (status);
}
/*
@@ -600,31 +574,30 @@ cl_cpool_init(
* Callback to translate quick composite to grow pool constructor callback.
*/
static cl_status_t
-__cl_pool_init_cb(
- IN void** const pp_obj,
- IN const uint32_t count,
- IN void* const context,
- OUT cl_pool_item_t** const pp_pool_item )
+__cl_pool_init_cb(IN void **const pp_obj,
+ IN const uint32_t count,
+ IN void *const context,
+ OUT cl_pool_item_t ** const pp_pool_item)
{
- cl_pool_t *p_pool = (cl_pool_t*)context;
- cl_pool_obj_t *p_pool_obj;
- cl_status_t status = CL_SUCCESS;
+ cl_pool_t *p_pool = (cl_pool_t *) context;
+ cl_pool_obj_t *p_pool_obj;
+ cl_status_t status = CL_SUCCESS;
- CL_ASSERT( p_pool );
- CL_ASSERT( pp_obj );
- CL_ASSERT( count == 1 );
+ CL_ASSERT(p_pool);
+ CL_ASSERT(pp_obj);
+ CL_ASSERT(count == 1);
- UNUSED_PARAM( count );
+ UNUSED_PARAM(count);
/*
* Set our pointer to the list item, which is stored at the beginning of
* the first component.
*/
- p_pool_obj = (cl_pool_obj_t*)*pp_obj;
+ p_pool_obj = (cl_pool_obj_t *) * pp_obj;
*pp_pool_item = &p_pool_obj->pool_item;
/* Calculate the pointer to the user's first component. */
- *pp_obj = ((uint8_t*)*pp_obj) + sizeof(cl_pool_obj_t);
+ *pp_obj = ((uint8_t *) * pp_obj) + sizeof(cl_pool_obj_t);
/*
* Set the object pointer in the pool item to point to the first of the
@@ -633,57 +606,53 @@ __cl_pool_init_cb(
p_pool_obj->p_object = *pp_obj;
/* Invoke the user's constructor callback. */
- if( p_pool->pfn_init )
- status = p_pool->pfn_init( *pp_obj, (void*)p_pool->context );
+ if (p_pool->pfn_init)
+ status = p_pool->pfn_init(*pp_obj, (void *)p_pool->context);
- return( status );
+ return (status);
}
/*
* Callback to translate quick composite to grow pool destructor callback.
*/
static void
-__cl_pool_dtor_cb(
- IN const cl_pool_item_t* const p_pool_item,
- IN void* const context )
+__cl_pool_dtor_cb(IN const cl_pool_item_t * const p_pool_item,
+ IN void *const context)
{
- cl_pool_t *p_pool = (cl_pool_t*)context;
+ cl_pool_t *p_pool = (cl_pool_t *) context;
- CL_ASSERT( p_pool );
- CL_ASSERT( p_pool->pfn_dtor );
- CL_ASSERT( ((cl_pool_obj_t*)p_pool_item)->p_object );
+ CL_ASSERT(p_pool);
+ CL_ASSERT(p_pool->pfn_dtor);
+ CL_ASSERT(((cl_pool_obj_t *) p_pool_item)->p_object);
/* Invoke the user's destructor callback. */
- p_pool->pfn_dtor( (void*)((cl_pool_obj_t*)p_pool_item)->p_object,
- (void*)p_pool->context );
+ p_pool->pfn_dtor((void *)((cl_pool_obj_t *) p_pool_item)->p_object,
+ (void *)p_pool->context);
}
-void
-cl_pool_construct(
- IN cl_pool_t* const p_pool )
+void cl_pool_construct(IN cl_pool_t * const p_pool)
{
- CL_ASSERT( p_pool );
+ CL_ASSERT(p_pool);
- memset( p_pool, 0, sizeof(cl_pool_t) );
+ memset(p_pool, 0, sizeof(cl_pool_t));
- cl_qcpool_construct( &p_pool->qcpool );
+ cl_qcpool_construct(&p_pool->qcpool);
}
cl_status_t
-cl_pool_init(
- IN cl_pool_t* const p_pool,
- IN const size_t min_size,
- IN const size_t max_size,
- IN const size_t grow_size,
- IN const size_t object_size,
- IN cl_pfn_pool_init_t pfn_initializer OPTIONAL,
- IN cl_pfn_pool_dtor_t pfn_destructor OPTIONAL,
- IN const void* const context )
+cl_pool_init(IN cl_pool_t * const p_pool,
+ IN const size_t min_size,
+ IN const size_t max_size,
+ IN const size_t grow_size,
+ IN const size_t object_size,
+ IN cl_pfn_pool_init_t pfn_initializer OPTIONAL,
+ IN cl_pfn_pool_dtor_t pfn_destructor OPTIONAL,
+ IN const void *const context)
{
- cl_status_t status;
- size_t total_size;
+ cl_status_t status;
+ size_t total_size;
- CL_ASSERT( p_pool );
+ CL_ASSERT(p_pool);
/* Add the size of the list item to the first component. */
total_size = object_size + sizeof(cl_pool_obj_t);
@@ -697,9 +666,10 @@ cl_pool_init(
* We need an initializer in all cases for quick composite pool, since
* the user pointer must be manipulated to hide the prefixed cl_pool_obj_t.
*/
- status = cl_qcpool_init( &p_pool->qcpool, min_size, max_size, grow_size,
- &total_size, 1, __cl_pool_init_cb,
- pfn_destructor ? __cl_pool_dtor_cb : NULL, p_pool );
+ status = cl_qcpool_init(&p_pool->qcpool, min_size, max_size, grow_size,
+ &total_size, 1, __cl_pool_init_cb,
+ pfn_destructor ? __cl_pool_dtor_cb : NULL,
+ p_pool);
- return( status );
+ return (status);
}
diff --git a/opensm/complib/cl_ptr_vector.c b/opensm/complib/cl_ptr_vector.c
index 1ee7bfb..333cf0f 100644
--- a/opensm/complib/cl_ptr_vector.c
+++ b/opensm/complib/cl_ptr_vector.c
@@ -45,34 +45,30 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <string.h>
#include <complib/cl_ptr_vector.h>
-void
-cl_ptr_vector_construct(
- IN cl_ptr_vector_t* const p_vector )
+void cl_ptr_vector_construct(IN cl_ptr_vector_t * const p_vector)
{
- CL_ASSERT( p_vector );
+ CL_ASSERT(p_vector);
- memset( p_vector, 0, sizeof(cl_ptr_vector_t) );
+ memset(p_vector, 0, sizeof(cl_ptr_vector_t));
p_vector->state = CL_UNINITIALIZED;
}
cl_status_t
-cl_ptr_vector_init(
- IN cl_ptr_vector_t* const p_vector,
- IN const size_t min_size,
- IN const size_t grow_size )
+cl_ptr_vector_init(IN cl_ptr_vector_t * const p_vector,
+ IN const size_t min_size, IN const size_t grow_size)
{
- cl_status_t status = CL_SUCCESS;
+ cl_status_t status = CL_SUCCESS;
- CL_ASSERT( p_vector );
+ CL_ASSERT(p_vector);
- cl_ptr_vector_construct( p_vector );
+ cl_ptr_vector_construct(p_vector);
p_vector->grow_size = grow_size;
@@ -83,30 +79,25 @@ cl_ptr_vector_init(
p_vector->state = CL_INITIALIZED;
/* get the storage needed by the user */
- if( min_size )
- {
- status = cl_ptr_vector_set_size( p_vector, min_size );
- if( status != CL_SUCCESS )
- cl_ptr_vector_destroy( p_vector );
+ if (min_size) {
+ status = cl_ptr_vector_set_size(p_vector, min_size);
+ if (status != CL_SUCCESS)
+ cl_ptr_vector_destroy(p_vector);
}
- return( status );
+ return (status);
}
-void
-cl_ptr_vector_destroy(
- IN cl_ptr_vector_t* const p_vector )
+void cl_ptr_vector_destroy(IN cl_ptr_vector_t * const p_vector)
{
- CL_ASSERT( p_vector );
- CL_ASSERT( cl_is_state_valid( p_vector->state ) );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(cl_is_state_valid(p_vector->state));
/* Call the user's destructor for each element in the array. */
- if( p_vector->state == CL_INITIALIZED )
- {
+ if (p_vector->state == CL_INITIALIZED) {
/* Destroy the page vector. */
- if( p_vector->p_ptr_array )
- {
- free( (void*)p_vector->p_ptr_array );
+ if (p_vector->p_ptr_array) {
+ free((void *)p_vector->p_ptr_array);
p_vector->p_ptr_array = NULL;
}
}
@@ -115,108 +106,98 @@ cl_ptr_vector_destroy(
}
cl_status_t
-cl_ptr_vector_at(
- IN const cl_ptr_vector_t* const p_vector,
- IN const size_t index,
- OUT void** const p_element )
+cl_ptr_vector_at(IN const cl_ptr_vector_t * const p_vector,
+ IN const size_t index, OUT void **const p_element)
{
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
/* Range check */
- if( index >= p_vector->size )
- return( CL_INVALID_PARAMETER );
+ if (index >= p_vector->size)
+ return (CL_INVALID_PARAMETER);
- *p_element = cl_ptr_vector_get( p_vector, index );
- return( CL_SUCCESS );
+ *p_element = cl_ptr_vector_get(p_vector, index);
+ return (CL_SUCCESS);
}
cl_status_t
-cl_ptr_vector_set(
- IN cl_ptr_vector_t* const p_vector,
- IN const size_t index,
- IN const void* const element )
+cl_ptr_vector_set(IN cl_ptr_vector_t * const p_vector,
+ IN const size_t index, IN const void *const element)
{
- cl_status_t status;
+ cl_status_t status;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
/* Determine if the vector has room for this element. */
- if( index >= p_vector->size )
- {
+ if (index >= p_vector->size) {
/* Resize to accomodate the given index. */
- status = cl_ptr_vector_set_size( p_vector, index + 1 );
+ status = cl_ptr_vector_set_size(p_vector, index + 1);
/* Check for failure on or before the given index. */
- if( (status != CL_SUCCESS) && (p_vector->size < index) )
- return( status );
+ if ((status != CL_SUCCESS) && (p_vector->size < index))
+ return (status);
}
/* At this point, the array is guaranteed to be big enough */
p_vector->p_ptr_array[index] = element;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
-void*
-cl_ptr_vector_remove(
- IN cl_ptr_vector_t* const p_vector,
- IN const size_t index )
+void *cl_ptr_vector_remove(IN cl_ptr_vector_t * const p_vector,
+ IN const size_t index)
{
- size_t src;
- const void *element;
+ size_t src;
+ const void *element;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
- CL_ASSERT( p_vector->size > index );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
+ CL_ASSERT(p_vector->size > index);
/* Store a copy of the element to return. */
element = p_vector->p_ptr_array[index];
/* Shift all items above the removed item down. */
- if( index < --p_vector->size )
- {
- for( src = index; src < p_vector->size; src++ )
- p_vector->p_ptr_array[src] = p_vector->p_ptr_array[src + 1];
+ if (index < --p_vector->size) {
+ for (src = index; src < p_vector->size; src++)
+ p_vector->p_ptr_array[src] =
+ p_vector->p_ptr_array[src + 1];
}
/* Clear the entry for the element just outside of the new upper bound. */
p_vector->p_ptr_array[p_vector->size] = NULL;
- return( (void*)element );
+ return ((void *)element);
}
cl_status_t
-cl_ptr_vector_set_capacity(
- IN cl_ptr_vector_t* const p_vector,
- IN const size_t new_capacity )
+cl_ptr_vector_set_capacity(IN cl_ptr_vector_t * const p_vector,
+ IN const size_t new_capacity)
{
- void *p_new_ptr_array;
+ void *p_new_ptr_array;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
/* Do we have to do anything here? */
- if( new_capacity <= p_vector->capacity )
- {
+ if (new_capacity <= p_vector->capacity) {
/* Nope */
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
/* Allocate our pointer array. */
- p_new_ptr_array = malloc( new_capacity * sizeof(void*) );
- if( !p_new_ptr_array )
- return( CL_INSUFFICIENT_MEMORY );
+ p_new_ptr_array = malloc(new_capacity * sizeof(void *));
+ if (!p_new_ptr_array)
+ return (CL_INSUFFICIENT_MEMORY);
else
- memset( p_new_ptr_array, 0, new_capacity * sizeof(void*) );
+ memset(p_new_ptr_array, 0, new_capacity * sizeof(void *));
- if( p_vector->p_ptr_array )
- {
+ if (p_vector->p_ptr_array) {
/* Copy the old pointer array into the new. */
- memcpy( p_new_ptr_array, p_vector->p_ptr_array,
- p_vector->capacity * sizeof(void*) );
+ memcpy(p_new_ptr_array, p_vector->p_ptr_array,
+ p_vector->capacity * sizeof(void *));
/* Free the old pointer array. */
- free( (void*)p_vector->p_ptr_array );
+ free((void *)p_vector->p_ptr_array);
}
/* Set the new array. */
@@ -225,130 +206,118 @@ cl_ptr_vector_set_capacity(
/* Update the vector with the new capactity. */
p_vector->capacity = new_capacity;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
cl_status_t
-cl_ptr_vector_set_size(
- IN cl_ptr_vector_t* const p_vector,
- IN const size_t size )
+cl_ptr_vector_set_size(IN cl_ptr_vector_t * const p_vector,
+ IN const size_t size)
{
- cl_status_t status;
- size_t new_capacity;
+ cl_status_t status;
+ size_t new_capacity;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
/* Check to see if the requested size is the same as the existing size. */
- if( size == p_vector->size )
- return( CL_SUCCESS );
+ if (size == p_vector->size)
+ return (CL_SUCCESS);
/* Determine if the vector has room for this element. */
- if( size >= p_vector->capacity )
- {
- if( !p_vector->grow_size )
- return( CL_INSUFFICIENT_MEMORY );
+ if (size >= p_vector->capacity) {
+ if (!p_vector->grow_size)
+ return (CL_INSUFFICIENT_MEMORY);
/* Calculate the new capacity, taking into account the grow size. */
new_capacity = size;
- if( size % p_vector->grow_size )
- {
+ if (size % p_vector->grow_size) {
/* Round up to nearest grow_size boundary. */
new_capacity += p_vector->grow_size -
- (size % p_vector->grow_size);
+ (size % p_vector->grow_size);
}
- status = cl_ptr_vector_set_capacity( p_vector, new_capacity );
- if( status != CL_SUCCESS )
- return( status );
+ status = cl_ptr_vector_set_capacity(p_vector, new_capacity);
+ if (status != CL_SUCCESS)
+ return (status);
}
p_vector->size = size;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
cl_status_t
-cl_ptr_vector_set_min_size(
- IN cl_ptr_vector_t* const p_vector,
- IN const size_t min_size )
+cl_ptr_vector_set_min_size(IN cl_ptr_vector_t * const p_vector,
+ IN const size_t min_size)
{
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
- if( min_size > p_vector->size )
- {
+ if (min_size > p_vector->size) {
/* We have to resize the array */
- return( cl_ptr_vector_set_size( p_vector, min_size ) );
+ return (cl_ptr_vector_set_size(p_vector, min_size));
}
/* We didn't have to do anything */
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
void
-cl_ptr_vector_apply_func(
- IN const cl_ptr_vector_t* const p_vector,
- IN cl_pfn_ptr_vec_apply_t pfn_callback,
- IN const void* const context )
+cl_ptr_vector_apply_func(IN const cl_ptr_vector_t * const p_vector,
+ IN cl_pfn_ptr_vec_apply_t pfn_callback,
+ IN const void *const context)
{
- size_t i;
+ size_t i;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
- CL_ASSERT( pfn_callback );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_callback);
- for( i = 0; i < p_vector->size; i++ )
- pfn_callback( i, (void*)p_vector->p_ptr_array[i], (void*)context );
+ for (i = 0; i < p_vector->size; i++)
+ pfn_callback(i, (void *)p_vector->p_ptr_array[i],
+ (void *)context);
}
size_t
-cl_ptr_vector_find_from_start(
- IN const cl_ptr_vector_t* const p_vector,
- IN cl_pfn_ptr_vec_find_t pfn_callback,
- IN const void* const context )
+cl_ptr_vector_find_from_start(IN const cl_ptr_vector_t * const p_vector,
+ IN cl_pfn_ptr_vec_find_t pfn_callback,
+ IN const void *const context)
{
- size_t i;
+ size_t i;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
- CL_ASSERT( pfn_callback );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_callback);
- for( i = 0; i < p_vector->size; i++ )
- {
+ for (i = 0; i < p_vector->size; i++) {
/* Invoke the callback */
- if( pfn_callback( i, (void*)p_vector->p_ptr_array[i],
- (void*)context ) == CL_SUCCESS )
- {
+ if (pfn_callback(i, (void *)p_vector->p_ptr_array[i],
+ (void *)context) == CL_SUCCESS) {
break;
}
}
- return( i );
+ return (i);
}
size_t
-cl_ptr_vector_find_from_end(
- IN const cl_ptr_vector_t* const p_vector,
- IN cl_pfn_ptr_vec_find_t pfn_callback,
- IN const void* const context )
+cl_ptr_vector_find_from_end(IN const cl_ptr_vector_t * const p_vector,
+ IN cl_pfn_ptr_vec_find_t pfn_callback,
+ IN const void *const context)
{
- size_t i;
+ size_t i;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
- CL_ASSERT( pfn_callback );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_callback);
i = p_vector->size;
- while( i )
- {
+ while (i) {
/* Invoke the callback for the current element. */
- if( pfn_callback( i, (void*)p_vector->p_ptr_array[--i],
- (void*)context ) == CL_SUCCESS )
- {
- return( i );
+ if (pfn_callback(i, (void *)p_vector->p_ptr_array[--i],
+ (void *)context) == CL_SUCCESS) {
+ return (i);
}
}
- return( p_vector->size );
+ return (p_vector->size);
}
-
diff --git a/opensm/complib/cl_spinlock.c b/opensm/complib/cl_spinlock.c
index b453f52..2d81696 100644
--- a/opensm/complib/cl_spinlock.c
+++ b/opensm/complib/cl_spinlock.c
@@ -35,68 +35,57 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <complib/cl_spinlock.h>
-void
-cl_spinlock_construct(
- IN cl_spinlock_t* const p_spinlock )
+void cl_spinlock_construct(IN cl_spinlock_t * const p_spinlock)
{
- CL_ASSERT( p_spinlock );
+ CL_ASSERT(p_spinlock);
p_spinlock->state = CL_UNINITIALIZED;
}
-cl_status_t
-cl_spinlock_init(
- IN cl_spinlock_t* const p_spinlock )
+cl_status_t cl_spinlock_init(IN cl_spinlock_t * const p_spinlock)
{
- CL_ASSERT( p_spinlock );
+ CL_ASSERT(p_spinlock);
- cl_spinlock_construct( p_spinlock );
+ cl_spinlock_construct(p_spinlock);
/* Initialize with pthread_mutexattr_t = NULL */
- if( pthread_mutex_init( &p_spinlock->mutex, NULL ) )
- return( CL_ERROR );
+ if (pthread_mutex_init(&p_spinlock->mutex, NULL))
+ return (CL_ERROR);
p_spinlock->state = CL_INITIALIZED;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
-void
-cl_spinlock_destroy(
- IN cl_spinlock_t* const p_spinlock )
+void cl_spinlock_destroy(IN cl_spinlock_t * const p_spinlock)
{
- CL_ASSERT( p_spinlock );
- CL_ASSERT( cl_is_state_valid( p_spinlock->state ) );
+ CL_ASSERT(p_spinlock);
+ CL_ASSERT(cl_is_state_valid(p_spinlock->state));
- if( p_spinlock->state == CL_INITIALIZED )
- {
- p_spinlock->state = CL_UNINITIALIZED;
- pthread_mutex_lock( &p_spinlock->mutex );
- pthread_mutex_unlock( &p_spinlock->mutex );
- pthread_mutex_destroy( &p_spinlock->mutex );
- }
- p_spinlock->state = CL_UNINITIALIZED;
+ if (p_spinlock->state == CL_INITIALIZED) {
+ p_spinlock->state = CL_UNINITIALIZED;
+ pthread_mutex_lock(&p_spinlock->mutex);
+ pthread_mutex_unlock(&p_spinlock->mutex);
+ pthread_mutex_destroy(&p_spinlock->mutex);
+ }
+ p_spinlock->state = CL_UNINITIALIZED;
}
-void
-cl_spinlock_acquire(
- IN cl_spinlock_t* const p_spinlock )
+void cl_spinlock_acquire(IN cl_spinlock_t * const p_spinlock)
{
- CL_ASSERT( p_spinlock );
- CL_ASSERT( p_spinlock->state == CL_INITIALIZED );
+ CL_ASSERT(p_spinlock);
+ CL_ASSERT(p_spinlock->state == CL_INITIALIZED);
- pthread_mutex_lock( &p_spinlock->mutex );
+ pthread_mutex_lock(&p_spinlock->mutex);
}
-void
-cl_spinlock_release(
- IN cl_spinlock_t* const p_spinlock )
+void cl_spinlock_release(IN cl_spinlock_t * const p_spinlock)
{
- CL_ASSERT( p_spinlock );
- CL_ASSERT( p_spinlock->state == CL_INITIALIZED );
+ CL_ASSERT(p_spinlock);
+ CL_ASSERT(p_spinlock->state == CL_INITIALIZED);
- pthread_mutex_unlock( &p_spinlock->mutex );
+ pthread_mutex_unlock(&p_spinlock->mutex);
}
diff --git a/opensm/complib/cl_statustext.c b/opensm/complib/cl_statustext.c
index 1d68db3..0a7d32b 100644
--- a/opensm/complib/cl_statustext.c
+++ b/opensm/complib/cl_statustext.c
@@ -45,13 +45,12 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <complib/cl_types.h>
/* Status values above converted to text for easier printing. */
-const char* cl_status_text[] =
-{
+const char *cl_status_text[] = {
"CL_SUCCESS",
"CL_ERROR",
"CL_INVALID_STATE",
diff --git a/opensm/complib/cl_thread.c b/opensm/complib/cl_thread.c
index 0e5ef3c..004b118 100644
--- a/opensm/complib/cl_thread.c
+++ b/opensm/complib/cl_thread.c
@@ -35,7 +35,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <unistd.h>
@@ -47,109 +47,95 @@
* This function is always run as a result of creation a new user mode thread.
* Its main job is to synchronize the creation and running of the new thread.
*/
-void*
-__cl_thread_wrapper( void* arg )
+void *__cl_thread_wrapper(void *arg)
{
- cl_thread_t *p_thread = (cl_thread_t*)arg;
+ cl_thread_t *p_thread = (cl_thread_t *) arg;
- CL_ASSERT( p_thread );
- CL_ASSERT( p_thread->pfn_callback );
+ CL_ASSERT(p_thread);
+ CL_ASSERT(p_thread->pfn_callback);
- p_thread->pfn_callback( (void*)p_thread->context );
+ p_thread->pfn_callback((void *)p_thread->context);
- return( NULL );
+ return (NULL);
}
-void
-cl_thread_construct(
- IN cl_thread_t* const p_thread )
+void cl_thread_construct(IN cl_thread_t * const p_thread)
{
- CL_ASSERT( p_thread );
+ CL_ASSERT(p_thread);
p_thread->osd.state = CL_UNINITIALIZED;
}
cl_status_t
-cl_thread_init(
- IN cl_thread_t* const p_thread,
- IN cl_pfn_thread_callback_t pfn_callback,
- IN const void* const context,
- IN const char* const name )
+cl_thread_init(IN cl_thread_t * const p_thread,
+ IN cl_pfn_thread_callback_t pfn_callback,
+ IN const void *const context, IN const char *const name)
{
- int ret;
+ int ret;
- CL_ASSERT( p_thread );
+ CL_ASSERT(p_thread);
- cl_thread_construct( p_thread );
+ cl_thread_construct(p_thread);
/* Initialize the thread structure */
p_thread->pfn_callback = pfn_callback;
p_thread->context = context;
- ret = pthread_create( &p_thread->osd.id, NULL,
- __cl_thread_wrapper, (void*)p_thread );
+ ret = pthread_create(&p_thread->osd.id, NULL,
+ __cl_thread_wrapper, (void *)p_thread);
- if( ret != 0 ) /* pthread_create returns a "0" for success */
- return( CL_ERROR );
+ if (ret != 0) /* pthread_create returns a "0" for success */
+ return (CL_ERROR);
p_thread->osd.state = CL_INITIALIZED;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
-void
-cl_thread_destroy(
- IN cl_thread_t* const p_thread )
+void cl_thread_destroy(IN cl_thread_t * const p_thread)
{
- CL_ASSERT( p_thread );
- CL_ASSERT( cl_is_state_valid( p_thread->osd.state ) );
+ CL_ASSERT(p_thread);
+ CL_ASSERT(cl_is_state_valid(p_thread->osd.state));
- if( p_thread->osd.state == CL_INITIALIZED )
- pthread_join( p_thread->osd.id, NULL );
+ if (p_thread->osd.state == CL_INITIALIZED)
+ pthread_join(p_thread->osd.id, NULL);
p_thread->osd.state = CL_UNINITIALIZED;
}
-void
-cl_thread_suspend(
- IN const uint32_t pause_ms )
+void cl_thread_suspend(IN const uint32_t pause_ms)
{
/* Convert to micro seconds */
- usleep( pause_ms * 1000 );
+ usleep(pause_ms * 1000);
}
-void
-cl_thread_stall(
- IN const uint32_t pause_us )
+void cl_thread_stall(IN const uint32_t pause_us)
{
/*
* Not quite a busy wait, but Linux is lacking in terms of high
* resolution time stamp information in user mode.
*/
- usleep( pause_us );
+ usleep(pause_us);
}
-int
-cl_proc_count( void )
+int cl_proc_count(void)
{
uint32_t ret;
ret = get_nprocs();
- if( !ret)
- return 1;/* Workaround for PPC where get_nprocs() returns 0 */
+ if (!ret)
+ return 1; /* Workaround for PPC where get_nprocs() returns 0 */
return ret;
}
-boolean_t
-cl_is_current_thread(
- IN const cl_thread_t* const p_thread )
+boolean_t cl_is_current_thread(IN const cl_thread_t * const p_thread)
{
- pthread_t current;
+ pthread_t current;
- CL_ASSERT( p_thread );
- CL_ASSERT( p_thread->osd.state == CL_INITIALIZED );
+ CL_ASSERT(p_thread);
+ CL_ASSERT(p_thread->osd.state == CL_INITIALIZED);
current = pthread_self();
- return( pthread_equal( current, p_thread->osd.id ) );
+ return (pthread_equal(current, p_thread->osd.id));
}
diff --git a/opensm/complib/cl_threadpool.c b/opensm/complib/cl_threadpool.c
index 6fe05b6..34fe322 100644
--- a/opensm/complib/cl_threadpool.c
+++ b/opensm/complib/cl_threadpool.c
@@ -45,7 +45,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <string.h>
@@ -54,44 +54,42 @@
static void cleanup_mutex(void *arg)
{
- pthread_mutex_unlock(&((cl_thread_pool_t *)arg)->mutex);
+ pthread_mutex_unlock(&((cl_thread_pool_t *) arg)->mutex);
}
-static void *thread_pool_routine(void* context)
+static void *thread_pool_routine(void *context)
{
- cl_thread_pool_t *p_thread_pool = (cl_thread_pool_t*)context;
+ cl_thread_pool_t *p_thread_pool = (cl_thread_pool_t *) context;
do {
pthread_mutex_lock(&p_thread_pool->mutex);
pthread_cleanup_push(cleanup_mutex, p_thread_pool);
- while(!p_thread_pool->events)
+ while (!p_thread_pool->events)
pthread_cond_wait(&p_thread_pool->cond,
&p_thread_pool->mutex);
p_thread_pool->events--;
pthread_cleanup_pop(1);
/* The event has been signalled. Invoke the callback. */
- (*p_thread_pool->pfn_callback)(p_thread_pool->context);
+ (*p_thread_pool->pfn_callback) (p_thread_pool->context);
} while (1);
return NULL;
}
cl_status_t
-cl_thread_pool_init(
- IN cl_thread_pool_t* const p_thread_pool,
- IN unsigned count,
- IN void (*pfn_callback)(void*),
- IN void *context,
- IN const char* const name )
+cl_thread_pool_init(IN cl_thread_pool_t * const p_thread_pool,
+ IN unsigned count,
+ IN void (*pfn_callback) (void *),
+ IN void *context, IN const char *const name)
{
int i;
- CL_ASSERT( p_thread_pool );
- CL_ASSERT( pfn_callback );
+ CL_ASSERT(p_thread_pool);
+ CL_ASSERT(pfn_callback);
memset(p_thread_pool, 0, sizeof(*p_thread_pool));
- if(!count)
+ if (!count)
count = cl_proc_count();
pthread_mutex_init(&p_thread_pool->mutex, NULL);
@@ -104,37 +102,34 @@ cl_thread_pool_init(
p_thread_pool->tid = calloc(count, sizeof(*p_thread_pool->tid));
if (!p_thread_pool->tid) {
- cl_thread_pool_destroy( p_thread_pool );
+ cl_thread_pool_destroy(p_thread_pool);
return CL_INSUFFICIENT_MEMORY;
}
p_thread_pool->running_count = count;
- for( i = 0; i < count; i++ )
- {
+ for (i = 0; i < count; i++) {
if (pthread_create(&p_thread_pool->tid[i], NULL,
thread_pool_routine, p_thread_pool) < 0) {
- cl_thread_pool_destroy( p_thread_pool );
+ cl_thread_pool_destroy(p_thread_pool);
return CL_INSUFFICIENT_RESOURCES;
}
}
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
-void
-cl_thread_pool_destroy(
- IN cl_thread_pool_t* const p_thread_pool )
+void cl_thread_pool_destroy(IN cl_thread_pool_t * const p_thread_pool)
{
int i;
- CL_ASSERT( p_thread_pool );
+ CL_ASSERT(p_thread_pool);
- for (i = 0 ; i < p_thread_pool->running_count; i++)
+ for (i = 0; i < p_thread_pool->running_count; i++)
if (p_thread_pool->tid[i])
pthread_cancel(p_thread_pool->tid[i]);
- for (i = 0 ; i < p_thread_pool->running_count; i++)
+ for (i = 0; i < p_thread_pool->running_count; i++)
if (p_thread_pool->tid[i])
pthread_join(p_thread_pool->tid[i], NULL);
@@ -145,12 +140,10 @@ cl_thread_pool_destroy(
p_thread_pool->events = 0;
}
-cl_status_t
-cl_thread_pool_signal(
- IN cl_thread_pool_t* const p_thread_pool )
+cl_status_t cl_thread_pool_signal(IN cl_thread_pool_t * const p_thread_pool)
{
int ret;
- CL_ASSERT( p_thread_pool );
+ CL_ASSERT(p_thread_pool);
pthread_mutex_lock(&p_thread_pool->mutex);
p_thread_pool->events++;
ret = pthread_cond_signal(&p_thread_pool->cond);
diff --git a/opensm/complib/cl_timer.c b/opensm/complib/cl_timer.c
index c8e2feb..7393aee 100644
--- a/opensm/complib/cl_timer.c
+++ b/opensm/complib/cl_timer.c
@@ -45,7 +45,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <string.h>
@@ -55,222 +55,208 @@
#include <stdio.h>
/* Timer provider (emulates timers in user mode). */
-typedef struct _cl_timer_prov
-{
- pthread_t thread;
- pthread_mutex_t mutex;
- pthread_cond_t cond;
- cl_qlist_t queue;
+typedef struct _cl_timer_prov {
+ pthread_t thread;
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+ cl_qlist_t queue;
- boolean_t exit;
+ boolean_t exit;
} cl_timer_prov_t;
/* Global timer provider. */
-static cl_timer_prov_t *gp_timer_prov = NULL;
+static cl_timer_prov_t *gp_timer_prov = NULL;
-static void*
-__cl_timer_prov_cb(
- IN void* const context );
+static void *__cl_timer_prov_cb(IN void *const context);
/*
* Creates the process global timer provider. Must be called by the shared
* object framework to solve all serialization issues.
*/
-cl_status_t
-__cl_timer_prov_create( void )
+cl_status_t __cl_timer_prov_create(void)
{
- CL_ASSERT( gp_timer_prov == NULL );
+ CL_ASSERT(gp_timer_prov == NULL);
- gp_timer_prov = malloc( sizeof(cl_timer_prov_t) );
- if( !gp_timer_prov )
- return( CL_INSUFFICIENT_MEMORY );
- else
- memset( gp_timer_prov, 0, sizeof(cl_timer_prov_t) );
+ gp_timer_prov = malloc(sizeof(cl_timer_prov_t));
+ if (!gp_timer_prov)
+ return (CL_INSUFFICIENT_MEMORY);
+ else
+ memset(gp_timer_prov, 0, sizeof(cl_timer_prov_t));
- cl_qlist_init( &gp_timer_prov->queue );
+ cl_qlist_init(&gp_timer_prov->queue);
- pthread_mutex_init( &gp_timer_prov->mutex, NULL );
- pthread_cond_init( &gp_timer_prov->cond, NULL );
+ pthread_mutex_init(&gp_timer_prov->mutex, NULL);
+ pthread_cond_init(&gp_timer_prov->cond, NULL);
- if( pthread_create( &gp_timer_prov->thread, NULL,
- __cl_timer_prov_cb, NULL ) )
- {
- __cl_timer_prov_destroy();
- return( CL_ERROR );
- }
+ if (pthread_create(&gp_timer_prov->thread, NULL,
+ __cl_timer_prov_cb, NULL)) {
+ __cl_timer_prov_destroy();
+ return (CL_ERROR);
+ }
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
-void
-__cl_timer_prov_destroy( void )
+void __cl_timer_prov_destroy(void)
{
- pthread_t tid;
+ pthread_t tid;
- if( !gp_timer_prov )
- return;
+ if (!gp_timer_prov)
+ return;
- tid = gp_timer_prov->thread;
- pthread_mutex_lock( &gp_timer_prov->mutex );
- gp_timer_prov->exit = TRUE;
- pthread_cond_broadcast( &gp_timer_prov->cond );
- pthread_mutex_unlock( &gp_timer_prov->mutex );
- pthread_join( tid , NULL );
+ tid = gp_timer_prov->thread;
+ pthread_mutex_lock(&gp_timer_prov->mutex);
+ gp_timer_prov->exit = TRUE;
+ pthread_cond_broadcast(&gp_timer_prov->cond);
+ pthread_mutex_unlock(&gp_timer_prov->mutex);
+ pthread_join(tid, NULL);
- /* Destroy the mutex and condition variable. */
- pthread_mutex_destroy( &gp_timer_prov->mutex );
- pthread_cond_destroy( &gp_timer_prov->cond );
+ /* Destroy the mutex and condition variable. */
+ pthread_mutex_destroy(&gp_timer_prov->mutex);
+ pthread_cond_destroy(&gp_timer_prov->cond);
- /* Free the memory and reset the global pointer. */
- free( gp_timer_prov );
- gp_timer_prov = NULL;
+ /* Free the memory and reset the global pointer. */
+ free(gp_timer_prov);
+ gp_timer_prov = NULL;
}
/*
* This is the internal work function executed by the timer's thread.
*/
-static void*
-__cl_timer_prov_cb(
- IN void* const context )
+static void *__cl_timer_prov_cb(IN void *const context)
{
- int ret;
- cl_timer_t *p_timer;
-
- pthread_mutex_lock( &gp_timer_prov->mutex );
- while( !gp_timer_prov->exit )
- {
- if( cl_is_qlist_empty( &gp_timer_prov->queue ) )
- {
- /* Wait until we exit or a timer is queued. */
- /* cond wait does:
- * pthread_cond_wait atomically unlocks the mutex (as per
- * pthread_unlock_mutex) and waits for the condition variable
- * cond to be signaled. The thread execution is suspended and
- * does not consume any CPU time until the condition variable is
- * signaled. The mutex must be locked by the calling thread on
- * entrance to pthread_cond_wait. Before RETURNING TO THE
- * CALLING THREAD, PTHREAD_COND_WAIT RE-ACQUIRES MUTEX (as per
- * pthread_lock_mutex).
- */
- ret = pthread_cond_wait( &gp_timer_prov->cond,
- &gp_timer_prov->mutex );
- }
- else
- {
- /*
- * The timer elements are on the queue in expiration order.
- * Get the first in the list to determine how long to wait.
- */
-
- p_timer = (cl_timer_t*)cl_qlist_head( &gp_timer_prov->queue );
- ret = pthread_cond_timedwait( &gp_timer_prov->cond,
- &gp_timer_prov->mutex, &p_timer->timeout );
-
- /*
- Sleep again on every event other than timeout and invalid
- Note: EINVAL means that we got behind. This can occur when
- we are very busy...
- */
- if( ret != ETIMEDOUT && ret != EINVAL )
- continue;
-
- /*
- * The timer expired. Check the state in case it was cancelled
- * after it expired but before we got a chance to invoke the
- * callback.
- */
- if( p_timer->timer_state != CL_TIMER_QUEUED )
- continue;
-
- /*
- * Mark the timer as running to synchronize with its
- * cancelation since we can't hold the mutex during the
- * callback.
- */
- p_timer->timer_state = CL_TIMER_RUNNING;
-
- /* Remove the item from the timer queue. */
- cl_qlist_remove_item( &gp_timer_prov->queue,
- &p_timer->list_item );
- pthread_mutex_unlock( &gp_timer_prov->mutex );
- /* Invoke the callback. */
- p_timer->pfn_callback( (void*)p_timer->context );
-
- /* Acquire the mutex again. */
- pthread_mutex_lock( &gp_timer_prov->mutex );
- /*
- * Only set the state to idle if the timer has not been accessed
- * from the callback
- */
- if( p_timer->timer_state == CL_TIMER_RUNNING )
- p_timer->timer_state = CL_TIMER_IDLE;
-
- /*
- * Signal any thread trying to manipulate the timer
- * that expired.
- */
- pthread_cond_signal( &p_timer->cond );
- }
- }
- gp_timer_prov->thread = 0;
- pthread_mutex_unlock( &gp_timer_prov->mutex );
- pthread_exit( NULL );
+ int ret;
+ cl_timer_t *p_timer;
+
+ pthread_mutex_lock(&gp_timer_prov->mutex);
+ while (!gp_timer_prov->exit) {
+ if (cl_is_qlist_empty(&gp_timer_prov->queue)) {
+ /* Wait until we exit or a timer is queued. */
+ /* cond wait does:
+ * pthread_cond_wait atomically unlocks the mutex (as per
+ * pthread_unlock_mutex) and waits for the condition variable
+ * cond to be signaled. The thread execution is suspended and
+ * does not consume any CPU time until the condition variable is
+ * signaled. The mutex must be locked by the calling thread on
+ * entrance to pthread_cond_wait. Before RETURNING TO THE
+ * CALLING THREAD, PTHREAD_COND_WAIT RE-ACQUIRES MUTEX (as per
+ * pthread_lock_mutex).
+ */
+ ret = pthread_cond_wait(&gp_timer_prov->cond,
+ &gp_timer_prov->mutex);
+ } else {
+ /*
+ * The timer elements are on the queue in expiration order.
+ * Get the first in the list to determine how long to wait.
+ */
+
+ p_timer =
+ (cl_timer_t *) cl_qlist_head(&gp_timer_prov->queue);
+ ret =
+ pthread_cond_timedwait(&gp_timer_prov->cond,
+ &gp_timer_prov->mutex,
+ &p_timer->timeout);
+
+ /*
+ Sleep again on every event other than timeout and invalid
+ Note: EINVAL means that we got behind. This can occur when
+ we are very busy...
+ */
+ if (ret != ETIMEDOUT && ret != EINVAL)
+ continue;
+
+ /*
+ * The timer expired. Check the state in case it was cancelled
+ * after it expired but before we got a chance to invoke the
+ * callback.
+ */
+ if (p_timer->timer_state != CL_TIMER_QUEUED)
+ continue;
+
+ /*
+ * Mark the timer as running to synchronize with its
+ * cancelation since we can't hold the mutex during the
+ * callback.
+ */
+ p_timer->timer_state = CL_TIMER_RUNNING;
+
+ /* Remove the item from the timer queue. */
+ cl_qlist_remove_item(&gp_timer_prov->queue,
+ &p_timer->list_item);
+ pthread_mutex_unlock(&gp_timer_prov->mutex);
+ /* Invoke the callback. */
+ p_timer->pfn_callback((void *)p_timer->context);
+
+ /* Acquire the mutex again. */
+ pthread_mutex_lock(&gp_timer_prov->mutex);
+ /*
+ * Only set the state to idle if the timer has not been accessed
+ * from the callback
+ */
+ if (p_timer->timer_state == CL_TIMER_RUNNING)
+ p_timer->timer_state = CL_TIMER_IDLE;
+
+ /*
+ * Signal any thread trying to manipulate the timer
+ * that expired.
+ */
+ pthread_cond_signal(&p_timer->cond);
+ }
+ }
+ gp_timer_prov->thread = 0;
+ pthread_mutex_unlock(&gp_timer_prov->mutex);
+ pthread_exit(NULL);
}
/* Timer implementation. */
-void
-cl_timer_construct(
- IN cl_timer_t* const p_timer )
+void cl_timer_construct(IN cl_timer_t * const p_timer)
{
- memset( p_timer, 0, sizeof(cl_timer_t) );
- p_timer->state = CL_UNINITIALIZED;
+ memset(p_timer, 0, sizeof(cl_timer_t));
+ p_timer->state = CL_UNINITIALIZED;
}
cl_status_t
-cl_timer_init(
- IN cl_timer_t* const p_timer,
- IN cl_pfn_timer_callback_t pfn_callback,
- IN const void* const context )
+cl_timer_init(IN cl_timer_t * const p_timer,
+ IN cl_pfn_timer_callback_t pfn_callback,
+ IN const void *const context)
{
- CL_ASSERT( p_timer );
- CL_ASSERT( pfn_callback );
+ CL_ASSERT(p_timer);
+ CL_ASSERT(pfn_callback);
- cl_timer_construct( p_timer );
+ cl_timer_construct(p_timer);
- if( !gp_timer_prov )
- return( CL_ERROR );
+ if (!gp_timer_prov)
+ return (CL_ERROR);
- /* Store timer parameters. */
- p_timer->pfn_callback = pfn_callback;
- p_timer->context = context;
+ /* Store timer parameters. */
+ p_timer->pfn_callback = pfn_callback;
+ p_timer->context = context;
- /* Mark the timer as idle. */
- p_timer->timer_state = CL_TIMER_IDLE;
+ /* Mark the timer as idle. */
+ p_timer->timer_state = CL_TIMER_IDLE;
- /* Create the condition variable that is used when cancelling a timer. */
- pthread_cond_init( &p_timer->cond, NULL );
+ /* Create the condition variable that is used when cancelling a timer. */
+ pthread_cond_init(&p_timer->cond, NULL);
- p_timer->state = CL_INITIALIZED;
+ p_timer->state = CL_INITIALIZED;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
-void
-cl_timer_destroy(
- IN cl_timer_t* const p_timer )
+void cl_timer_destroy(IN cl_timer_t * const p_timer)
{
- CL_ASSERT( p_timer );
- CL_ASSERT( cl_is_state_valid( p_timer->state ) );
+ CL_ASSERT(p_timer);
+ CL_ASSERT(cl_is_state_valid(p_timer->state));
- if( p_timer->state == CL_INITIALIZED )
- cl_timer_stop( p_timer );
+ if (p_timer->state == CL_INITIALIZED)
+ cl_timer_stop(p_timer);
- p_timer->state = CL_UNINITIALIZED;
+ p_timer->state = CL_UNINITIALIZED;
- /* is it possible we have some threads waiting on the cond now? */
- pthread_cond_broadcast( &p_timer->cond );
- pthread_cond_destroy( &p_timer->cond );
+ /* is it possible we have some threads waiting on the cond now? */
+ pthread_cond_broadcast(&p_timer->cond);
+ pthread_cond_destroy(&p_timer->cond);
}
@@ -278,13 +264,12 @@ cl_timer_destroy(
* Return TRUE if timeout value 1 is earlier than timeout value 2.
*/
static __inline boolean_t
-__cl_timer_is_earlier(
- IN struct timespec *p_timeout1,
- IN struct timespec *p_timeout2 )
+__cl_timer_is_earlier(IN struct timespec *p_timeout1,
+ IN struct timespec *p_timeout2)
{
- return( (p_timeout1->tv_sec < p_timeout2->tv_sec) ||
- ( (p_timeout1->tv_sec == p_timeout2->tv_sec) &&
- (p_timeout1->tv_nsec < p_timeout2->tv_nsec) ) );
+ return ((p_timeout1->tv_sec < p_timeout2->tv_sec) ||
+ ((p_timeout1->tv_sec == p_timeout2->tv_sec) &&
+ (p_timeout1->tv_nsec < p_timeout2->tv_nsec)));
}
/*
@@ -293,188 +278,173 @@ __cl_timer_is_earlier(
* a cl_timer_t structure with valid timeouts.
*/
static cl_status_t
-__cl_timer_find(
- IN const cl_list_item_t* const p_list_item,
- IN void* const context )
+__cl_timer_find(IN const cl_list_item_t * const p_list_item,
+ IN void *const context)
{
- cl_timer_t *p_in_list;
- cl_timer_t *p_new;
+ cl_timer_t *p_in_list;
+ cl_timer_t *p_new;
- CL_ASSERT( p_list_item );
- CL_ASSERT( context );
+ CL_ASSERT(p_list_item);
+ CL_ASSERT(context);
- p_in_list = (cl_timer_t*)p_list_item;
- p_new = (cl_timer_t*)context;
+ p_in_list = (cl_timer_t *) p_list_item;
+ p_new = (cl_timer_t *) context;
- CL_ASSERT( p_in_list->state == CL_INITIALIZED );
- CL_ASSERT( p_new->state == CL_INITIALIZED );
+ CL_ASSERT(p_in_list->state == CL_INITIALIZED);
+ CL_ASSERT(p_new->state == CL_INITIALIZED);
- CL_ASSERT( p_in_list->timer_state == CL_TIMER_QUEUED );
+ CL_ASSERT(p_in_list->timer_state == CL_TIMER_QUEUED);
- if( __cl_timer_is_earlier( &p_in_list->timeout, &p_new->timeout ) )
- return( CL_SUCCESS );
+ if (__cl_timer_is_earlier(&p_in_list->timeout, &p_new->timeout))
+ return (CL_SUCCESS);
- return( CL_NOT_FOUND );
+ return (CL_NOT_FOUND);
}
cl_status_t
-cl_timer_start(
- IN cl_timer_t* const p_timer,
- IN const uint32_t time_ms )
+cl_timer_start(IN cl_timer_t * const p_timer, IN const uint32_t time_ms)
{
- struct timeval curtime;
- cl_list_item_t *p_list_item;
- uint32_t delta_time = time_ms;
+ struct timeval curtime;
+ cl_list_item_t *p_list_item;
+ uint32_t delta_time = time_ms;
- CL_ASSERT( p_timer );
- CL_ASSERT( p_timer->state == CL_INITIALIZED );
+ CL_ASSERT(p_timer);
+ CL_ASSERT(p_timer->state == CL_INITIALIZED);
- pthread_mutex_lock( &gp_timer_prov->mutex );
- /* Signal the timer provider thread to wake up. */
- pthread_cond_signal( &gp_timer_prov->cond );
+ pthread_mutex_lock(&gp_timer_prov->mutex);
+ /* Signal the timer provider thread to wake up. */
+ pthread_cond_signal(&gp_timer_prov->cond);
- /* Remove the timer from the queue if currently queued. */
- if( p_timer->timer_state == CL_TIMER_QUEUED )
- cl_qlist_remove_item( &gp_timer_prov->queue, &p_timer->list_item);
+ /* Remove the timer from the queue if currently queued. */
+ if (p_timer->timer_state == CL_TIMER_QUEUED)
+ cl_qlist_remove_item(&gp_timer_prov->queue,
+ &p_timer->list_item);
- /* Get the current time */
+ /* Get the current time */
#ifndef timerclear
#define timerclear(tvp) (tvp)->tv_sec = (time_t)0, (tvp)->tv_usec = 0L
#endif
- timerclear( &curtime );
- gettimeofday( &curtime, NULL );
-
- /* do not do 0 wait ! */
- /* if (delta_time < 1000.0) {delta_time = 1000;} */
-
- /* Calculate the timeout. */
- p_timer->timeout.tv_sec =
- curtime.tv_sec + (delta_time / 1000);
- p_timer->timeout.tv_nsec =
- (curtime.tv_usec + ((delta_time % 1000) * 1000)) * 1000;
-
- /* Add the timer to the queue. */
- if( cl_is_qlist_empty( &gp_timer_prov->queue ) )
- {
- /* The timer list is empty. Add to the head. */
- cl_qlist_insert_head( &gp_timer_prov->queue, &p_timer->list_item );
- }
- else
- {
- /* Find the correct insertion place in the list for the timer. */
- p_list_item = cl_qlist_find_from_tail( &gp_timer_prov->queue,
- __cl_timer_find, p_timer );
-
- /* Insert the timer. */
- cl_qlist_insert_next( &gp_timer_prov->queue, p_list_item,
- &p_timer->list_item );
- }
- /* Set the state. */
- p_timer->timer_state = CL_TIMER_QUEUED;
- pthread_mutex_unlock( &gp_timer_prov->mutex );
-
- return( CL_SUCCESS );
+ timerclear(&curtime);
+ gettimeofday(&curtime, NULL);
+
+ /* do not do 0 wait ! */
+ /* if (delta_time < 1000.0) {delta_time = 1000;} */
+
+ /* Calculate the timeout. */
+ p_timer->timeout.tv_sec = curtime.tv_sec + (delta_time / 1000);
+ p_timer->timeout.tv_nsec =
+ (curtime.tv_usec + ((delta_time % 1000) * 1000)) * 1000;
+
+ /* Add the timer to the queue. */
+ if (cl_is_qlist_empty(&gp_timer_prov->queue)) {
+ /* The timer list is empty. Add to the head. */
+ cl_qlist_insert_head(&gp_timer_prov->queue,
+ &p_timer->list_item);
+ } else {
+ /* Find the correct insertion place in the list for the timer. */
+ p_list_item = cl_qlist_find_from_tail(&gp_timer_prov->queue,
+ __cl_timer_find, p_timer);
+
+ /* Insert the timer. */
+ cl_qlist_insert_next(&gp_timer_prov->queue, p_list_item,
+ &p_timer->list_item);
+ }
+ /* Set the state. */
+ p_timer->timer_state = CL_TIMER_QUEUED;
+ pthread_mutex_unlock(&gp_timer_prov->mutex);
+
+ return (CL_SUCCESS);
}
-void
-cl_timer_stop(
- IN cl_timer_t* const p_timer )
+void cl_timer_stop(IN cl_timer_t * const p_timer)
{
- CL_ASSERT( p_timer );
- CL_ASSERT( p_timer->state == CL_INITIALIZED );
-
- pthread_mutex_lock( &gp_timer_prov->mutex );
- switch( p_timer->timer_state )
- {
- case CL_TIMER_RUNNING:
- /* Wait for the callback to complete. */
- pthread_cond_wait( &p_timer->cond, &gp_timer_prov->mutex );
- /* Timer could have been queued while we were waiting. */
- if( p_timer->timer_state != CL_TIMER_QUEUED )
- break;
-
- case CL_TIMER_QUEUED:
- /* Change the state of the timer. */
- p_timer->timer_state = CL_TIMER_IDLE;
- /* Remove the timer from the queue. */
- cl_qlist_remove_item( &gp_timer_prov->queue, &p_timer->list_item );
- /*
- * Signal the timer provider thread to move onto the
- * next timer in the queue.
- */
- pthread_cond_signal( &gp_timer_prov->cond );
- break;
-
- case CL_TIMER_IDLE:
- break;
- }
- pthread_mutex_unlock( &gp_timer_prov->mutex );
+ CL_ASSERT(p_timer);
+ CL_ASSERT(p_timer->state == CL_INITIALIZED);
+
+ pthread_mutex_lock(&gp_timer_prov->mutex);
+ switch (p_timer->timer_state) {
+ case CL_TIMER_RUNNING:
+ /* Wait for the callback to complete. */
+ pthread_cond_wait(&p_timer->cond, &gp_timer_prov->mutex);
+ /* Timer could have been queued while we were waiting. */
+ if (p_timer->timer_state != CL_TIMER_QUEUED)
+ break;
+
+ case CL_TIMER_QUEUED:
+ /* Change the state of the timer. */
+ p_timer->timer_state = CL_TIMER_IDLE;
+ /* Remove the timer from the queue. */
+ cl_qlist_remove_item(&gp_timer_prov->queue,
+ &p_timer->list_item);
+ /*
+ * Signal the timer provider thread to move onto the
+ * next timer in the queue.
+ */
+ pthread_cond_signal(&gp_timer_prov->cond);
+ break;
+
+ case CL_TIMER_IDLE:
+ break;
+ }
+ pthread_mutex_unlock(&gp_timer_prov->mutex);
}
cl_status_t
-cl_timer_trim(
- IN cl_timer_t* const p_timer,
- IN const uint32_t time_ms )
+cl_timer_trim(IN cl_timer_t * const p_timer, IN const uint32_t time_ms)
{
- struct timeval curtime;
- struct timespec newtime;
- cl_status_t status;
+ struct timeval curtime;
+ struct timespec newtime;
+ cl_status_t status;
- CL_ASSERT( p_timer );
- CL_ASSERT( p_timer->state == CL_INITIALIZED );
+ CL_ASSERT(p_timer);
+ CL_ASSERT(p_timer->state == CL_INITIALIZED);
- pthread_mutex_lock( &gp_timer_prov->mutex );
+ pthread_mutex_lock(&gp_timer_prov->mutex);
- /* Get the current time */
- timerclear( &curtime );
- gettimeofday( &curtime, NULL );
+ /* Get the current time */
+ timerclear(&curtime);
+ gettimeofday(&curtime, NULL);
- /* Calculate the timeout. */
- newtime.tv_sec =
- curtime.tv_sec + (time_ms / 1000);
- newtime.tv_nsec =
- (curtime.tv_usec + ((time_ms % 1000) * 1000)) * 1000;
+ /* Calculate the timeout. */
+ newtime.tv_sec = curtime.tv_sec + (time_ms / 1000);
+ newtime.tv_nsec = (curtime.tv_usec + ((time_ms % 1000) * 1000)) * 1000;
- if( p_timer->timer_state == CL_TIMER_QUEUED )
- {
- /* If the old time is earlier, do not trim it. Just return. */
- if( __cl_timer_is_earlier( &p_timer->timeout, &newtime ) )
- {
- pthread_mutex_unlock( &gp_timer_prov->mutex );
- return( CL_SUCCESS );
- }
- }
+ if (p_timer->timer_state == CL_TIMER_QUEUED) {
+ /* If the old time is earlier, do not trim it. Just return. */
+ if (__cl_timer_is_earlier(&p_timer->timeout, &newtime)) {
+ pthread_mutex_unlock(&gp_timer_prov->mutex);
+ return (CL_SUCCESS);
+ }
+ }
- /* Reset the timer to the new timeout value. */
+ /* Reset the timer to the new timeout value. */
- pthread_mutex_unlock( &gp_timer_prov->mutex );
- status = cl_timer_start( p_timer, time_ms );
+ pthread_mutex_unlock(&gp_timer_prov->mutex);
+ status = cl_timer_start(p_timer, time_ms);
- return( status );
+ return (status);
}
-uint64_t
-cl_get_time_stamp( void )
+uint64_t cl_get_time_stamp(void)
{
- uint64_t tstamp;
- struct timeval tv;
+ uint64_t tstamp;
+ struct timeval tv;
- timerclear( &tv );
- gettimeofday( &tv, NULL );
+ timerclear(&tv);
+ gettimeofday(&tv, NULL);
- /* Convert the time of day into a microsecond timestamp. */
- tstamp = ((uint64_t)tv.tv_sec * 1000000) + (uint64_t)tv.tv_usec;
+ /* Convert the time of day into a microsecond timestamp. */
+ tstamp = ((uint64_t) tv.tv_sec * 1000000) + (uint64_t) tv.tv_usec;
- return( tstamp );
+ return (tstamp);
}
-uint32_t
-cl_get_time_stamp_sec( void )
+uint32_t cl_get_time_stamp_sec(void)
{
- struct timeval tv;
+ struct timeval tv;
- timerclear( &tv );
- gettimeofday( &tv, NULL );
+ timerclear(&tv);
+ gettimeofday(&tv, NULL);
- return( tv.tv_sec );
+ return (tv.tv_sec);
}
diff --git a/opensm/complib/cl_vector.c b/opensm/complib/cl_vector.c
index eb14c12..6e8e428 100644
--- a/opensm/complib/cl_vector.c
+++ b/opensm/complib/cl_vector.c
@@ -45,7 +45,7 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <string.h>
@@ -75,12 +75,10 @@
*
*/
static void
-cl_vector_copy_general(
- OUT void* const p_dest,
- IN const void* const p_src,
- IN const size_t size )
+cl_vector_copy_general(OUT void *const p_dest,
+ IN const void *const p_src, IN const size_t size)
{
- memcpy( p_dest, p_src, size );
+ memcpy(p_dest, p_src, size);
}
/*
@@ -100,15 +98,13 @@ cl_vector_copy_general(
*
*/
static void
-cl_vector_copy8(
- OUT void* const p_dest,
- IN const void* const p_src,
- IN const size_t size )
+cl_vector_copy8(OUT void *const p_dest,
+ IN const void *const p_src, IN const size_t size)
{
- CL_ASSERT( size == sizeof(uint8_t) );
- UNUSED_PARAM( size );
+ CL_ASSERT(size == sizeof(uint8_t));
+ UNUSED_PARAM(size);
- *(uint8_t*)p_dest = *(uint8_t*)p_src;
+ *(uint8_t *) p_dest = *(uint8_t *) p_src;
}
/*
@@ -128,15 +124,13 @@ cl_vector_copy8(
*
*/
void
-cl_vector_copy16(
- OUT void* const p_dest,
- IN const void* const p_src,
- IN const size_t size )
+cl_vector_copy16(OUT void *const p_dest,
+ IN const void *const p_src, IN const size_t size)
{
- CL_ASSERT( size == sizeof(uint16_t) );
- UNUSED_PARAM( size );
+ CL_ASSERT(size == sizeof(uint16_t));
+ UNUSED_PARAM(size);
- *(uint16_t*)p_dest = *(uint16_t*)p_src;
+ *(uint16_t *) p_dest = *(uint16_t *) p_src;
}
/*
@@ -156,15 +150,13 @@ cl_vector_copy16(
*
*/
void
-cl_vector_copy32(
- OUT void* const p_dest,
- IN const void* const p_src,
- IN const size_t size )
+cl_vector_copy32(OUT void *const p_dest,
+ IN const void *const p_src, IN const size_t size)
{
- CL_ASSERT( size == sizeof(uint32_t) );
- UNUSED_PARAM( size );
+ CL_ASSERT(size == sizeof(uint32_t));
+ UNUSED_PARAM(size);
- *(uint32_t*)p_dest = *(uint32_t*)p_src;
+ *(uint32_t *) p_dest = *(uint32_t *) p_src;
}
/*
@@ -184,44 +176,39 @@ cl_vector_copy32(
*
*/
void
-cl_vector_copy64(
- OUT void* const p_dest,
- IN const void* const p_src,
- IN const size_t size )
+cl_vector_copy64(OUT void *const p_dest,
+ IN const void *const p_src, IN const size_t size)
{
- CL_ASSERT( size == sizeof(uint64_t) );
- UNUSED_PARAM( size );
+ CL_ASSERT(size == sizeof(uint64_t));
+ UNUSED_PARAM(size);
- *(uint64_t*)p_dest = *(uint64_t*)p_src;
+ *(uint64_t *) p_dest = *(uint64_t *) p_src;
}
-void
-cl_vector_construct(
- IN cl_vector_t* const p_vector )
+void cl_vector_construct(IN cl_vector_t * const p_vector)
{
- CL_ASSERT( p_vector );
+ CL_ASSERT(p_vector);
- memset( p_vector, 0, sizeof(cl_vector_t) );
+ memset(p_vector, 0, sizeof(cl_vector_t));
p_vector->state = CL_UNINITIALIZED;
}
cl_status_t
-cl_vector_init(
- IN cl_vector_t* const p_vector,
- IN const size_t min_size,
- IN const size_t grow_size,
- IN const size_t element_size,
- IN cl_pfn_vec_init_t pfn_init OPTIONAL,
- IN cl_pfn_vec_dtor_t pfn_dtor OPTIONAL,
- IN const void* const context )
+cl_vector_init(IN cl_vector_t * const p_vector,
+ IN const size_t min_size,
+ IN const size_t grow_size,
+ IN const size_t element_size,
+ IN cl_pfn_vec_init_t pfn_init OPTIONAL,
+ IN cl_pfn_vec_dtor_t pfn_dtor OPTIONAL,
+ IN const void *const context)
{
- cl_status_t status = CL_SUCCESS;
+ cl_status_t status = CL_SUCCESS;
- CL_ASSERT( p_vector );
- CL_ASSERT( element_size );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(element_size);
- cl_vector_construct( p_vector );
+ cl_vector_construct(p_vector);
p_vector->grow_size = grow_size;
p_vector->element_size = element_size;
@@ -233,8 +220,7 @@ cl_vector_init(
* Try to choose a smart copy operator
* someday, we could simply let the users pass one in
*/
- switch( element_size )
- {
+ switch (element_size) {
case sizeof(uint8_t):
p_vector->pfn_copy = cl_vector_copy8;
break;
@@ -263,51 +249,45 @@ cl_vector_init(
p_vector->state = CL_INITIALIZED;
/* Initialize the allocation list */
- cl_qlist_init( &p_vector->alloc_list );
+ cl_qlist_init(&p_vector->alloc_list);
/* get the storage needed by the user */
- if( min_size )
- {
- status = cl_vector_set_size( p_vector, min_size );
- if( status != CL_SUCCESS )
- cl_vector_destroy( p_vector );
+ if (min_size) {
+ status = cl_vector_set_size(p_vector, min_size);
+ if (status != CL_SUCCESS)
+ cl_vector_destroy(p_vector);
}
- return( status );
+ return (status);
}
-void
-cl_vector_destroy(
- IN cl_vector_t* const p_vector )
+void cl_vector_destroy(IN cl_vector_t * const p_vector)
{
- size_t i;
- void *p_element;
+ size_t i;
+ void *p_element;
- CL_ASSERT( p_vector );
- CL_ASSERT( cl_is_state_valid( p_vector->state ) );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(cl_is_state_valid(p_vector->state));
/* Call the user's destructor for each element in the array. */
- if( p_vector->state == CL_INITIALIZED )
- {
- if( p_vector->pfn_dtor )
- {
- for( i = 0; i < p_vector->size; i++ )
- {
+ if (p_vector->state == CL_INITIALIZED) {
+ if (p_vector->pfn_dtor) {
+ for (i = 0; i < p_vector->size; i++) {
p_element = p_vector->p_ptr_array[i];
/* Sanity check! */
- CL_ASSERT( p_element );
- p_vector->pfn_dtor( p_element, (void*)p_vector->context );
+ CL_ASSERT(p_element);
+ p_vector->pfn_dtor(p_element,
+ (void *)p_vector->context);
}
}
/* Deallocate the pages */
- while( !cl_is_qlist_empty( &p_vector->alloc_list ) )
- free( cl_qlist_remove_head( &p_vector->alloc_list ) );
+ while (!cl_is_qlist_empty(&p_vector->alloc_list))
+ free(cl_qlist_remove_head(&p_vector->alloc_list));
/* Destroy the page vector. */
- if( p_vector->p_ptr_array )
- {
- free( p_vector->p_ptr_array );
+ if (p_vector->p_ptr_array) {
+ free(p_vector->p_ptr_array);
p_vector->p_ptr_array = NULL;
}
}
@@ -316,93 +296,85 @@ cl_vector_destroy(
}
cl_status_t
-cl_vector_at(
- IN const cl_vector_t* const p_vector,
- IN const size_t index,
- OUT void* const p_element )
+cl_vector_at(IN const cl_vector_t * const p_vector,
+ IN const size_t index, OUT void *const p_element)
{
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
/* Range check */
- if( index >= p_vector->size )
- return( CL_INVALID_PARAMETER );
+ if (index >= p_vector->size)
+ return (CL_INVALID_PARAMETER);
- cl_vector_get( p_vector, index, p_element );
- return( CL_SUCCESS );
+ cl_vector_get(p_vector, index, p_element);
+ return (CL_SUCCESS);
}
cl_status_t
-cl_vector_set(
- IN cl_vector_t* const p_vector,
- IN const size_t index,
- IN void* const p_element )
+cl_vector_set(IN cl_vector_t * const p_vector,
+ IN const size_t index, IN void *const p_element)
{
- cl_status_t status;
- void *p_dest;
+ cl_status_t status;
+ void *p_dest;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
- CL_ASSERT( p_element );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
+ CL_ASSERT(p_element);
/* Determine if the vector has room for this element. */
- if( index >= p_vector->size )
- {
+ if (index >= p_vector->size) {
/* Resize to accomodate the given index. */
- status = cl_vector_set_size( p_vector, index + 1 );
+ status = cl_vector_set_size(p_vector, index + 1);
/* Check for failure on or before the given index. */
- if( (status != CL_SUCCESS) && (p_vector->size < index) )
- return( status );
+ if ((status != CL_SUCCESS) && (p_vector->size < index))
+ return (status);
}
/* At this point, the array is guaranteed to be big enough */
- p_dest = cl_vector_get_ptr( p_vector, index );
+ p_dest = cl_vector_get_ptr(p_vector, index);
/* Sanity check! */
- CL_ASSERT( p_dest );
+ CL_ASSERT(p_dest);
/* Copy the data into the array */
- p_vector->pfn_copy( p_dest, p_element, p_vector->element_size );
+ p_vector->pfn_copy(p_dest, p_element, p_vector->element_size);
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
cl_status_t
-cl_vector_set_capacity(
- IN cl_vector_t* const p_vector,
- IN const size_t new_capacity )
+cl_vector_set_capacity(IN cl_vector_t * const p_vector,
+ IN const size_t new_capacity)
{
- size_t new_elements;
- size_t alloc_size;
- size_t i;
- cl_list_item_t *p_buf;
- void *p_new_ptr_array;
+ size_t new_elements;
+ size_t alloc_size;
+ size_t i;
+ cl_list_item_t *p_buf;
+ void *p_new_ptr_array;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
/* Do we have to do anything here? */
- if( new_capacity <= p_vector->capacity )
- {
+ if (new_capacity <= p_vector->capacity) {
/* Nope */
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
/* Allocate our pointer array. */
- p_new_ptr_array = malloc( new_capacity * sizeof(void*) );
- if( !p_new_ptr_array )
- return( CL_INSUFFICIENT_MEMORY );
+ p_new_ptr_array = malloc(new_capacity * sizeof(void *));
+ if (!p_new_ptr_array)
+ return (CL_INSUFFICIENT_MEMORY);
else
- memset( p_new_ptr_array, 0, new_capacity * sizeof(void*) );
+ memset(p_new_ptr_array, 0, new_capacity * sizeof(void *));
- if( p_vector->p_ptr_array )
- {
+ if (p_vector->p_ptr_array) {
/* Copy the old pointer array into the new. */
- memcpy( p_new_ptr_array, p_vector->p_ptr_array,
- p_vector->capacity * sizeof(void*) );
+ memcpy(p_new_ptr_array, p_vector->p_ptr_array,
+ p_vector->capacity * sizeof(void *));
/* Free the old pointer array. */
- free( p_vector->p_ptr_array );
+ free(p_vector->p_ptr_array);
}
/* Set the new array. */
@@ -416,192 +388,178 @@ cl_vector_set_capacity(
/* Determine the allocation size for the new array elements. */
alloc_size = new_elements * p_vector->element_size;
- p_buf = (cl_list_item_t*)malloc( alloc_size + sizeof(cl_list_item_t) );
- if( !p_buf )
- return( CL_INSUFFICIENT_MEMORY );
+ p_buf = (cl_list_item_t *) malloc(alloc_size + sizeof(cl_list_item_t));
+ if (!p_buf)
+ return (CL_INSUFFICIENT_MEMORY);
else
- memset( p_buf, 0, alloc_size + sizeof(cl_list_item_t) );
+ memset(p_buf, 0, alloc_size + sizeof(cl_list_item_t));
- cl_qlist_insert_tail( &p_vector->alloc_list, p_buf );
+ cl_qlist_insert_tail(&p_vector->alloc_list, p_buf);
/* Advance the buffer pointer past the list item. */
p_buf++;
- for( i = p_vector->capacity; i < new_capacity; i++ )
- {
+ for (i = p_vector->capacity; i < new_capacity; i++) {
p_vector->p_ptr_array[i] = p_buf;
/* Move the buffer pointer to the next element. */
- p_buf = (void*)(((uint8_t*)p_buf) + p_vector->element_size);
+ p_buf = (void *)(((uint8_t *) p_buf) + p_vector->element_size);
}
/* Update the vector with the new capactity. */
p_vector->capacity = new_capacity;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
cl_status_t
-cl_vector_set_size(
- IN cl_vector_t* const p_vector,
- IN const size_t size )
+cl_vector_set_size(IN cl_vector_t * const p_vector, IN const size_t size)
{
- cl_status_t status;
- size_t new_capacity;
- size_t index;
- void *p_element;
+ cl_status_t status;
+ size_t new_capacity;
+ size_t index;
+ void *p_element;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
/* Check to see if the requested size is the same as the existing size. */
- if( size == p_vector->size )
- return( CL_SUCCESS );
+ if (size == p_vector->size)
+ return (CL_SUCCESS);
/* Determine if the vector has room for this element. */
- if( size >= p_vector->capacity )
- {
- if( !p_vector->grow_size )
- return( CL_INSUFFICIENT_MEMORY );
+ if (size >= p_vector->capacity) {
+ if (!p_vector->grow_size)
+ return (CL_INSUFFICIENT_MEMORY);
/* Calculate the new capacity, taking into account the grow size. */
new_capacity = size;
- if( size % p_vector->grow_size )
- {
+ if (size % p_vector->grow_size) {
/* Round up to nearest grow_size boundary. */
new_capacity += p_vector->grow_size -
- (size % p_vector->grow_size);
+ (size % p_vector->grow_size);
}
- status = cl_vector_set_capacity( p_vector, new_capacity );
- if( status != CL_SUCCESS )
- return( status );
+ status = cl_vector_set_capacity(p_vector, new_capacity);
+ if (status != CL_SUCCESS)
+ return (status);
}
/* Are we growing the array and need to invoke an initializer callback? */
- if( size > p_vector->size && p_vector->pfn_init )
- {
- for( index = p_vector->size; index < size; index++ )
- {
+ if (size > p_vector->size && p_vector->pfn_init) {
+ for (index = p_vector->size; index < size; index++) {
/* Get a pointer to this element */
- p_element = cl_vector_get_ptr( p_vector, index );
+ p_element = cl_vector_get_ptr(p_vector, index);
/* Call the user's initializer and trap failures. */
- status = p_vector->pfn_init( p_element, (void*)p_vector->context );
- if( status != CL_SUCCESS )
- {
+ status =
+ p_vector->pfn_init(p_element,
+ (void *)p_vector->context);
+ if (status != CL_SUCCESS) {
/* Call the destructor for this object */
- if( p_vector->pfn_dtor )
- p_vector->pfn_dtor( p_element, (void*)p_vector->context );
+ if (p_vector->pfn_dtor)
+ p_vector->pfn_dtor(p_element,
+ (void *)p_vector->
+ context);
/* Return the failure status to the caller. */
- return( status );
+ return (status);
}
/* The array just grew by one element */
p_vector->size++;
}
- }
- else if( p_vector->pfn_dtor )
- {
+ } else if (p_vector->pfn_dtor) {
/* The array is shrinking and there is a destructor to invoke. */
- for( index = size; index < p_vector->size; index++ )
- {
+ for (index = size; index < p_vector->size; index++) {
/* compute the address of the new elements */
- p_element = cl_vector_get_ptr( p_vector, index );
+ p_element = cl_vector_get_ptr(p_vector, index);
/* call the user's destructor */
- p_vector->pfn_dtor( p_element, (void*)p_vector->context );
+ p_vector->pfn_dtor(p_element,
+ (void *)p_vector->context);
}
}
p_vector->size = size;
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
cl_status_t
-cl_vector_set_min_size(
- IN cl_vector_t* const p_vector,
- IN const size_t min_size )
+cl_vector_set_min_size(IN cl_vector_t * const p_vector,
+ IN const size_t min_size)
{
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
- if( min_size > p_vector->size )
- {
+ if (min_size > p_vector->size) {
/* We have to resize the array */
- return( cl_vector_set_size( p_vector, min_size ) );
+ return (cl_vector_set_size(p_vector, min_size));
}
/* We didn't have to do anything */
- return( CL_SUCCESS );
+ return (CL_SUCCESS);
}
void
-cl_vector_apply_func(
- IN const cl_vector_t* const p_vector,
- IN cl_pfn_vec_apply_t pfn_callback,
- IN const void* const context )
+cl_vector_apply_func(IN const cl_vector_t * const p_vector,
+ IN cl_pfn_vec_apply_t pfn_callback,
+ IN const void *const context)
{
- size_t i;
- void *p_element;
+ size_t i;
+ void *p_element;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
- CL_ASSERT( pfn_callback );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_callback);
- for( i = 0; i < p_vector->size; i++ )
- {
- p_element = cl_vector_get_ptr( p_vector, i );
- pfn_callback( i, p_element, (void*)context );
+ for (i = 0; i < p_vector->size; i++) {
+ p_element = cl_vector_get_ptr(p_vector, i);
+ pfn_callback(i, p_element, (void *)context);
}
}
size_t
-cl_vector_find_from_start(
- IN const cl_vector_t* const p_vector,
- IN cl_pfn_vec_find_t pfn_callback,
- IN const void* const context )
+cl_vector_find_from_start(IN const cl_vector_t * const p_vector,
+ IN cl_pfn_vec_find_t pfn_callback,
+ IN const void *const context)
{
- size_t i;
- void *p_element;
+ size_t i;
+ void *p_element;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
- CL_ASSERT( pfn_callback );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_callback);
- for( i = 0; i < p_vector->size; i++ )
- {
- p_element = cl_vector_get_ptr( p_vector, i );
+ for (i = 0; i < p_vector->size; i++) {
+ p_element = cl_vector_get_ptr(p_vector, i);
/* Invoke the callback */
- if( pfn_callback( i, p_element, (void*)context ) == CL_SUCCESS )
+ if (pfn_callback(i, p_element, (void *)context) == CL_SUCCESS)
break;
}
- return( i );
+ return (i);
}
size_t
-cl_vector_find_from_end(
- IN const cl_vector_t* const p_vector,
- IN cl_pfn_vec_find_t pfn_callback,
- IN const void* const context )
+cl_vector_find_from_end(IN const cl_vector_t * const p_vector,
+ IN cl_pfn_vec_find_t pfn_callback,
+ IN const void *const context)
{
- size_t i;
- void *p_element;
+ size_t i;
+ void *p_element;
- CL_ASSERT( p_vector );
- CL_ASSERT( p_vector->state == CL_INITIALIZED );
- CL_ASSERT( pfn_callback );
+ CL_ASSERT(p_vector);
+ CL_ASSERT(p_vector->state == CL_INITIALIZED);
+ CL_ASSERT(pfn_callback);
i = p_vector->size;
- while( i )
- {
+ while (i) {
/* Get a pointer to the element in the array. */
- p_element = cl_vector_get_ptr( p_vector, --i );
- CL_ASSERT( p_element );
+ p_element = cl_vector_get_ptr(p_vector, --i);
+ CL_ASSERT(p_element);
/* Invoke the callback for the current element. */
- if( pfn_callback( i, p_element, (void*)context ) == CL_SUCCESS )
- return( i );
+ if (pfn_callback(i, p_element, (void *)context) == CL_SUCCESS)
+ return (i);
}
- return( p_vector->size );
+ return (p_vector->size);
}
diff --git a/opensm/complib/ib_statustext.c b/opensm/complib/ib_statustext.c
index 07aee7a..0bedff1 100644
--- a/opensm/complib/ib_statustext.c
+++ b/opensm/complib/ib_statustext.c
@@ -45,13 +45,12 @@
#if HAVE_CONFIG_H
# include <config.h>
-#endif /* HAVE_CONFIG_H */
+#endif /* HAVE_CONFIG_H */
#include <complib/cl_types.h>
/* ib_api_status_t values above converted to text for easier printing. */
-const char* ib_error_str[] =
-{
+const char *ib_error_str[] = {
"IB_SUCCESS",
"IB_INSUFFICIENT_RESOURCES",
"IB_INSUFFICIENT_MEMORY",
@@ -95,7 +94,7 @@ const char* ib_error_str[] =
"IB_INVALID_AL_HANDLE",
"IB_INVALID_HANDLE",
"IB_ERROR",
- "IB_REMOTE_ERROR", /* Infiniband Access Layer */
+ "IB_REMOTE_ERROR", /* Infiniband Access Layer */
"IB_VERBS_PROCESSING_DONE",
"IB_INVALID_WR_TYPE",
"IB_QP_IN_TIMEWAIT",
@@ -103,12 +102,10 @@ const char* ib_error_str[] =
"IB_INVALID_PORT",
"IB_NOT_DONE",
"IB_UNKNOWN_ERROR"
-
};
/* ib_async_event_t values above converted to text for easier printing. */
-const char* ib_async_event_str[] =
-{
+const char *ib_async_event_str[] = {
"IB_AE_SQ_ERROR",
"IB_AE_SQ_DRAINED",
"IB_AE_RQ_ERROR",
@@ -133,14 +130,12 @@ const char* ib_async_event_str[] =
"IB_AE_EEC_APM_ERROR",
"IB_AE_WQ_REQ_ERROR",
"IB_AE_WQ_ACCESS_ERROR",
- "IB_AE_PORT_ACTIVE", /* ACTIVE STATE */
- "IB_AE_PORT_DOWN", /* INIT", ARMED", DOWN */
+ "IB_AE_PORT_ACTIVE", /* ACTIVE STATE */
+ "IB_AE_PORT_DOWN", /* INIT", ARMED", DOWN */
"IB_AE_UNKNOWN"
-
};
-const char* ib_wc_status_str[] =
-{
+const char *ib_wc_status_str[] = {
"IB_WCS_SUCCESS",
"IB_WCS_LOCAL_LEN_ERR",
"IB_WCS_LOCAL_OP_ERR",
@@ -157,7 +152,6 @@ const char* ib_wc_status_str[] =
"IB_WCS_INVALID_EECN",
"IB_WCS_INVALID_EEC_STATE",
"IB_WCS_UNMATCHED_RESPONSE", /* InfiniBand Access Layer */
- "IB_WCS_CANCELED", /* InfiniBand Access Layer */
+ "IB_WCS_CANCELED", /* InfiniBand Access Layer */
"IB_WCS_UNKNOWN"
-
};
--
1.5.3.rc2.38.g11308
More information about the general
mailing list