From c9a86dd1813b03aff74808035f7cae18133e2cbb Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 3 Aug 2023 10:43:46 +0200 Subject: added THREAD_ID helper in a util.h, done away with warnings on numerical thread systems --- pgfuse.c | 3 +-- pool.c | 7 ++++--- util.h | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 util.h diff --git a/pgfuse.c b/pgfuse.c index 572fd31..00ca9a1 100644 --- a/pgfuse.c +++ b/pgfuse.c @@ -43,6 +43,7 @@ #endif #include "config.h" /* compiled in defaults */ +#include "util.h" /* common project utilities */ #include "pgsql.h" /* implements Postgresql accessers */ #include "pool.h" /* implements the connection pool */ @@ -107,8 +108,6 @@ static int psql_release( PgFuseData *data, PGconn *conn ) #define RELEASE( C ) \ if( psql_release( data, C ) < 0 ) return -EIO; -#define THREAD_ID pthread_self( ) - /* --- other helpers --- */ static int check_mountpoint( char **old_mountpoint ) diff --git a/pool.c b/pool.c index 82b0644..f83af07 100644 --- a/pool.c +++ b/pool.c @@ -16,6 +16,7 @@ */ #include "pool.h" +#include "util.h" /* common project utilities */ #include /* for strlen, memcpy, strcmp */ #include /* for ENOENT and friends */ @@ -96,7 +97,7 @@ int psql_pool_destroy( PgConnPool *pool ) break; case USED: syslog( LOG_ERR, "Destroying pool connection to thread %p which is still in use", - pool->thread[i] ); + (void *)pool->thread[i] ); PQfinish( pool->conns[i] ); break; case ERROR: @@ -124,7 +125,7 @@ PGconn *psql_pool_acquire( PgConnPool *pool ) res = pthread_mutex_lock( &pool->lock ); if( res < 0 ) { syslog( LOG_ERR, "Locking mutex failed for thread %p: %d", - pthread_self( ), res ); + THREAD_ID, res ); return NULL; } @@ -146,7 +147,7 @@ PGconn *psql_pool_acquire( PgConnPool *pool ) res = pthread_cond_wait( &pool->cond, &pool->lock ); if( res < 0 ) { syslog( LOG_ERR, "Error waiting for free condition in thread %p: %d", - pthread_self( ), res ); + THREAD_ID, res ); (void)pthread_mutex_unlock( &pool->lock ); return NULL; } diff --git a/util.h b/util.h new file mode 100644 index 0000000..b2f1ac7 --- /dev/null +++ b/util.h @@ -0,0 +1,23 @@ +/* + Copyright (C) 2012 - 2015 Andreas Baumann + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef UTIL_H +#define UTIL_H + +#define THREAD_ID ( (void *)pthread_self( ) ) + +#endif -- cgit v1.2.3-54-g00ecf