src/tremashark/queue.c in trema-0.2.5 vs src/tremashark/queue.c in trema-0.2.6

- old
+ new

@@ -37,11 +37,11 @@ bool delete_queue( queue *queue ) { assert( queue != NULL ); - while( queue->head != NULL ) { + while ( queue->head != NULL ) { queue_element *e = queue->head; if ( queue->head->data != NULL ) { free_buffer( queue->head->data ); } queue->head = queue->head->next; @@ -73,11 +73,11 @@ new_tail->data = data; new_tail->next = NULL; queue->tail->next = new_tail; queue->tail = new_tail; - queue->length++; + __sync_add_and_fetch( &queue->length, 1 ); // this must be an atomic operation for thread safety collect_garbage( queue ); return true; } @@ -90,11 +90,11 @@ if ( queue->divider != queue->tail ) { queue_element *next = queue->divider->next; buffer *data = next->data; next->data = NULL; // data must be freed by caller queue->divider = next; - queue->length--; + __sync_sub_and_fetch( &queue->length, 1 ); // this must be an atomic operation for thread safety return data; } return NULL; @@ -137,10 +137,11 @@ if ( compare( elements[ i - 1 ]->data, data ) ) { j = i; do { elements[ j ]->data = elements[ j - 1 ]->data; j--; - } while ( j > 0 && compare( elements[ j - 1 ]->data, data ) ); + } + while ( j > 0 && compare( elements[ j - 1 ]->data, data ) ); elements[ j ]->data = data; } } return true;