probe_timer_entry * delete_probe_timer_entry( const uint64_t *datapath_id, uint16_t port_no ) { dlist_element *dlist; probe_timer_entry *entry; bool top = true; for ( dlist = probe_timer_table->next; dlist != NULL; dlist = dlist->next ) { entry = dlist->data; if ( entry->datapath_id == *datapath_id && entry->port_no == port_no ) { if ( dlist == probe_timer_last ) { probe_timer_last = dlist->prev; } delete_dlist_element( dlist ); #if 0 if ( probe_timer_table->next == NULL ) { unset_interval_timer(); } else if ( top ) { set_interval_timer(); } #endif return entry; } top = false; } return NULL; }
static void interval_timer_event( void *user_data ) { UNUSED( user_data ); struct timespec now; dlist_element *dlist, *next; probe_timer_entry *entry; for ( dlist = probe_timer_table->next; dlist != NULL; dlist = next ) { next = dlist->next; entry = dlist->data; get_current_time( &now ); if ( timespec_le( &( entry->expires ), &now ) ) { if ( dlist == probe_timer_last ) { probe_timer_last = dlist->prev; } delete_dlist_element( dlist ); probe_request( entry, PROBE_TIMER_EVENT_TIMEOUT, 0, 0 ); } else { #if 0 set_interval_timer(); #endif return; } } }
/** * Moves over the timer callback list and checks if that timer has expired. Incase it has, calls on_timer which * inturn calls callback associated with that timer. * @param None * @return None */ void execute_timer_events() { struct timespec now; timer_callback *callback; dlist_element *element, *element_next; debug( "Executing timer events ( timer_callbacks = %p ).", timer_callbacks ); assert( clock_gettime( CLOCK_MONOTONIC, &now ) == 0 ); assert( timer_callbacks != NULL ); // TODO: timer_callbacks should be a list which is sorted by expiry time for ( element = timer_callbacks->next; element; element = element_next ) { element_next = element->next; callback = element->data; if ( callback->function != NULL && ( ( callback->expires_at.tv_sec < now.tv_sec ) || ( ( callback->expires_at.tv_sec == now.tv_sec ) && ( callback->expires_at.tv_nsec <= now.tv_nsec ) ) ) ) { on_timer( callback ); } if ( callback->function == NULL ) { xfree( callback ); delete_dlist_element( element ); } } }
static void _execute_timer_events( int *next_timeout_usec ) { assert( next_timeout_usec != NULL ); timer_read_begin(); struct timer_info *timer = get_timer_info(); timer_read_end(); assert( timer != NULL ); debug( "Executing timer events ( timer_callbacks = %p ).", timer->timer_callbacks ); struct timespec now = { 0, 0 }; assert( clock_gettime( CLOCK_MONOTONIC, &now ) == 0 ); assert( timer->timer_callbacks != NULL ); timer_callback_info *callback = NULL; dlist_element *element_next = NULL; for ( dlist_element *element = timer->timer_callbacks->next; element; element = element_next ) { element_next = element->next; callback = element->data; if ( callback->function != NULL ) { if ( TIMESPEC_LESS_THEN( &now, &callback->expires_at ) ) { break; } on_timer( callback, &now ); } delete_dlist_element( element ); if ( callback->function == NULL ) { xfree( callback ); } else { insert_timer_callback( timer, callback ); } } struct timespec max_timeout = { ( INT_MAX / 1000000 ), 0 }; struct timespec min_timeout = { 0, 0 }; if ( timer->timer_callbacks->next == NULL ) { TIMESPEC_TO_MICROSECONDS( &max_timeout, next_timeout_usec ); } else { callback = timer->timer_callbacks->next->data; if ( TIMESPEC_LESS_THEN( &callback->expires_at, &now ) ) { TIMESPEC_TO_MICROSECONDS( &min_timeout, next_timeout_usec ); } else { struct timespec timeout = { 0, 0 }; SUB_TIMESPEC( &callback->expires_at, &now, &timeout ); if ( TIMESPEC_LESS_THEN( &timeout, &max_timeout ) ) { TIMESPEC_TO_MICROSECONDS( &timeout, next_timeout_usec ); } else { TIMESPEC_TO_MICROSECONDS( &max_timeout, next_timeout_usec ); } } } }
OFDPE remove_action_bucket( bucket_list *list, bucket *bucket ) { assert( list != NULL ); assert( bucket != NULL ); dlist_element *elemenet = find_element( list, bucket ); if ( elemenet == NULL ) { return ERROR_NOT_FOUND; } delete_action_bucket( bucket ); delete_dlist_element( elemenet ); return OFDPE_SUCCESS; }
OFDPE remove_action( action_list *list, action *action ) { assert( list != NULL ); assert( action != NULL ); dlist_element *element = find_element( get_first_element( list ), action ); if ( element == NULL ) { return ERROR_NOT_FOUND; } delete_action( action ); delete_dlist_element( element ); return OFDPE_SUCCESS; }
// Remove "charlie" of "alpha" <-> "bravo" <-> "charlie" static void test_remove_last_element() { char element_data2[] = "bravo"; char element_data3[] = "charlie"; dlist_element *alpha = create_dlist(); dlist_element *bravo = insert_after_dlist( alpha, element_data2 ); dlist_element *charlie = insert_after_dlist( bravo, element_data3 ); assert_true( delete_dlist_element( charlie ) ); assert_true( bravo->next == NULL ); assert_true( bravo->prev == alpha ); delete_dlist( alpha ); }
static void test_delete_dlist_element_aborts_with_NULL_dlist() { expect_string( mock_die, output, "element must not be NULL" ); expect_assert_failure( delete_dlist_element( NULL ) ); }