Skip to content

Commit

Permalink
Don't do mutexes if no threads
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Jul 27, 2015
1 parent b1923a4 commit 4f50609
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/connection.c
Expand Up @@ -786,7 +786,9 @@ static void *fr_connection_get_internal(fr_connection_pool_t *pool, bool spawn)

if (!pool) return NULL;

#ifdef HAVE_PTHREAD_H
if (spawn) pthread_mutex_lock(&pool->mutex);
#endif

now = time(NULL);

Expand All @@ -805,10 +807,6 @@ static void *fr_connection_get_internal(fr_connection_pool_t *pool, bool spawn)
* heap and use it.
*/
if (this) {
/*
* The conection is either fine, or was
* successfully reconnected.
*/
fr_heap_extract(pool->heap, this);
goto do_return;
}
Expand Down Expand Up @@ -864,7 +862,9 @@ static void *fr_connection_get_internal(fr_connection_pool_t *pool, bool spawn)
this->pthread_id = pthread_self();
#endif

#ifdef HAVE_PTHREAD_H

This comment has been minimized.

Copy link
@jpereira

jpereira Jul 29, 2015

Member

@alandekok

I Believe that this is redundant, because we just have the below code.

 149 #ifndef HAVE_PTHREAD_H
 150 #  define pthread_mutex_lock(_x)
 151 #  define pthread_mutex_unlock(_x)
 152 #endif
if (spawn) pthread_mutex_unlock(&pool->mutex);
#endif

DEBUG("%s: Reserved connection (%" PRIu64 ")", pool->log_prefix, this->number);

Expand Down

1 comment on commit 4f50609

@alandekok
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not redundant. If there's no pthreads, the "if (spawn)" statement has nothing inside of the "if" block. It's better to remove the entire "if" statement when there's no pthreads.

Please sign in to comment.