Skip to content

Commit

Permalink
Fixed compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob-C-Smith committed Sep 19, 2023
1 parent 5ab168c commit 87b5570
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
2 changes: 1 addition & 1 deletion include/queue/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ DLLEXPORT bool queue_empty ( const queue *const p_queue );
*
* @return 1 on success, 0 on error
*/
DLLEXPORT int queue_destroy ( queue **const pp_queue );
DLLEXPORT int queue_destroy ( queue **const pp_queue );
6 changes: 5 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
int main ( int argc, const char *argv[] )
{

// Supress compiler warnings
(void) argc;
(void) argv;

// Initialized data
queue *p_queue = 0;
void *value = 0;
Expand All @@ -26,7 +30,7 @@ int main ( int argc, const char *argv[] )
void *v = 0;

// Dequeue an item
queue_dequeue(p_queue,&v);
queue_dequeue(p_queue, &v);

// Print the element
printf("%s\n", (char *) v);
Expand Down
54 changes: 19 additions & 35 deletions queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ struct queue_node_s
void *content;
struct queue_node_s *prev,
*next;
mutex _mutex;
};

struct queue_s
Expand All @@ -19,9 +18,7 @@ int queue_create ( queue **const pp_queue )
{

// Argument check
#ifndef NDEBUG
if ( pp_queue == (void *) 0 ) goto no_queue;
#endif
if ( pp_queue == (void *) 0 ) goto no_queue;

// Initialized data
queue *ret = QUEUE_REALLOC(0, sizeof(queue));
Expand Down Expand Up @@ -69,9 +66,7 @@ int queue_construct ( queue **const pp_queue )
{

// Argument check
#ifndef NDEBUG
if ( pp_queue == (void *) 0 ) goto no_queue;
#endif
if ( pp_queue == (void *) 0 ) goto no_queue;

// Initialized data
queue *p_queue = 0;
Expand Down Expand Up @@ -127,11 +122,9 @@ int queue_from_contents ( queue **const pp_queue, void* const* const pp_contents
{

// Argument check
#ifndef NDEBUG
if ( pp_queue == (void *) 0 ) goto no_queue;
if ( pp_contents == (void *) 0 ) goto no_queue_contents;
if ( size == 0 ) goto no_queue_contents;
#endif
if ( pp_queue == (void *) 0 ) goto no_queue;
if ( pp_contents == (void *) 0 ) goto no_queue_contents;
if ( size == 0 ) goto no_queue_contents;

// Construct a queue
if ( queue_construct(pp_queue) == 0 ) goto failed_to_construct_queue;
Expand Down Expand Up @@ -184,9 +177,7 @@ int queue_front ( const queue *const p_queue, const void ** const pp_value )
{

// Argument check
#ifndef NDEBUG
if ( p_queue == (void *) 0 ) goto no_queue;
#endif
if ( p_queue == (void *) 0 ) goto no_queue;

// Lock
mutex_lock(p_queue->_lock);
Expand Down Expand Up @@ -232,9 +223,7 @@ int queue_rear ( const queue *const p_queue, const void **const pp_value )
{

// Argument check
#ifndef NDEBUG
if ( p_queue == (void *) 0 ) goto no_queue;
#endif
if ( p_queue == (void *) 0 ) goto no_queue;

// Lock
mutex_lock(p_queue->_lock);
Expand Down Expand Up @@ -283,9 +272,7 @@ int queue_enqueue ( queue *const p_queue, void *const data )
{

// Argument check
#ifndef NDEBUG
if ( p_queue == (void *) 0 ) goto no_queue;
#endif
if ( p_queue == (void *) 0 ) goto no_queue;

// Lock
mutex_lock(p_queue->_lock);
Expand Down Expand Up @@ -355,9 +342,7 @@ int queue_dequeue ( queue *const p_queue, const void **const pp_value )
{

// Argument check
#ifndef NDEBUG
if ( p_queue == (void *) 0 ) goto no_queue;
#endif
if ( p_queue == (void *) 0 ) goto no_queue;

// Lock
mutex_lock(p_queue->_lock);
Expand All @@ -366,18 +351,18 @@ int queue_dequeue ( queue *const p_queue, const void **const pp_value )
if ( p_queue->front == 0 ) goto queue_empty;

// Initialized data
void **pp_ret = 0;
struct queue_node_s *ret_m = 0,
*ret_n = 0;
struct queue_node_s *ret_m = 0;

ret_m = ((struct queue_node_s *)(p_queue->front));

// Remove the front
if (p_queue->front != p_queue->rear)
p_queue->front = ((struct queue_node_s *)(p_queue->front))->next;
else
p_queue->front = 0,
{
p_queue->front = 0;
p_queue->rear = 0;
}

// If the caller specified a return...
if ( pp_value )
Expand Down Expand Up @@ -441,9 +426,7 @@ bool queue_empty ( const queue *const p_queue )
{

// Argument check
#ifndef MDEBIG
if ( p_queue == (void *)0 ) goto no_queue;
#endif
if ( p_queue == (void *)0 ) goto no_queue;

// Lock
mutex_lock(p_queue->_lock);
Expand Down Expand Up @@ -477,9 +460,7 @@ int queue_destroy ( queue **const pp_queue )
{

// Argument check
#ifndef NDEBUG
if ( pp_queue == (void *) 0 ) goto no_queue;
#endif
if ( pp_queue == (void *) 0 ) goto no_queue;

// Initialized data
queue *p_queue = *pp_queue;
Expand All @@ -494,7 +475,10 @@ int queue_destroy ( queue **const pp_queue )
mutex_unlock(p_queue->_lock);

// Empty the queue
while ( queue_empty(p_queue) == false ) { queue_dequeue(p_queue, 0); };
while ( queue_empty(p_queue) == false )
{
queue_dequeue(p_queue, 0);
}

// Free the memory
if ( QUEUE_REALLOC(p_queue, 0) ) goto failed_to_free;
Expand Down

0 comments on commit 87b5570

Please sign in to comment.