Skip to content

Commit

Permalink
Merge pull request #1630 from albinahlback/pthread
Browse files Browse the repository at this point in the history
Don't include pthread.h if not using it
  • Loading branch information
albinahlback committed Nov 17, 2023
2 parents fddfc40 + 2a1ffee commit c75ca82
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 35 deletions.
4 changes: 0 additions & 4 deletions src/fmpz.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

#include "fmpz_types.h"

#if FLINT_USES_PTHREAD
#include <pthread.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
1 change: 1 addition & 0 deletions src/fmpz/link/fmpz_single.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "fmpz.h"

#if FLINT_USES_PTHREAD
# include <pthread.h>
# include <stdatomic.h>
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/generic_files/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <stdarg.h>
#include "flint.h"

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
#include <pthread.h>

static pthread_once_t abort_func_init = PTHREAD_ONCE_INIT;
Expand All @@ -30,14 +30,14 @@ FLINT_NORETURN void (*abort_func)(void) = abort;

void flint_set_abort(FLINT_NORETURN void (*func)(void))
{
#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_once(&abort_func_init, __flint_set_abort_init);
pthread_mutex_lock(&abort_func_lock);
#endif

abort_func = func;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_mutex_unlock(&abort_func_lock);
#endif
}
Expand Down
21 changes: 10 additions & 11 deletions src/generic_files/memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/

#include <stdlib.h>
#include "flint.h"
#include "mpfr.h"
#include "thread_pool.h"

Expand All @@ -31,7 +30,7 @@ static void *(*__flint_callocate_func) (size_t, size_t) = _flint_calloc;
static void *(*__flint_reallocate_func) (void *, size_t) = _flint_realloc;
static void (*__flint_free_func) (void *) = _flint_free;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
#include <pthread.h>

static pthread_once_t register_initialised = PTHREAD_ONCE_INIT;
Expand All @@ -56,7 +55,7 @@ void __flint_get_memory_functions(void *(**alloc_func) (size_t),
void *(**realloc_func) (void *, size_t),
void (**free_func) (void *))
{
#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_once(&alloc_func_init, __flint_set_memory_functions_init);
pthread_mutex_lock(&alloc_func_lock);
#endif
Expand All @@ -66,7 +65,7 @@ void __flint_get_memory_functions(void *(**alloc_func) (size_t),
*realloc_func = __flint_reallocate_func;
*free_func = __flint_free_func;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_mutex_unlock(&alloc_func_lock);
#endif
}
Expand All @@ -76,7 +75,7 @@ void __flint_set_memory_functions(void *(*alloc_func) (size_t),
void *(*realloc_func) (void *, size_t),
void (*free_func) (void *))
{
#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_once(&alloc_func_init, __flint_set_memory_functions_init);
pthread_mutex_lock(&alloc_func_lock);
#endif
Expand All @@ -86,7 +85,7 @@ void __flint_set_memory_functions(void *(*alloc_func) (size_t),
__flint_reallocate_func = realloc_func;
__flint_free_func = free_func;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_mutex_unlock(&alloc_func_lock);
#endif
}
Expand Down Expand Up @@ -185,7 +184,7 @@ FLINT_TLS_PREFIX size_t flint_num_cleanup_functions = 0;

FLINT_TLS_PREFIX flint_cleanup_function_t * flint_cleanup_functions = NULL;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
void register_init(void)
{
pthread_mutex_init(&register_lock, NULL);
Expand All @@ -194,7 +193,7 @@ void register_init(void)

void flint_register_cleanup_function(flint_cleanup_function_t cleanup_function)
{
#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_once(&register_initialised, register_init);
pthread_mutex_lock(&register_lock);
#endif
Expand All @@ -206,7 +205,7 @@ void flint_register_cleanup_function(flint_cleanup_function_t cleanup_function)

flint_num_cleanup_functions++;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_mutex_unlock(&register_lock);
#endif
}
Expand All @@ -217,7 +216,7 @@ void _flint_cleanup(void)
{
size_t i;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_mutex_lock(&register_lock);
#endif

Expand All @@ -231,7 +230,7 @@ void _flint_cleanup(void)
mpfr_free_cache();
_fmpz_cleanup();

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_mutex_unlock(&register_lock);
#endif

Expand Down
13 changes: 6 additions & 7 deletions src/mpn_extras/factor_trial_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "flint.h"
#include "fmpz.h"
#include "fmpz_poly.h"
#include "mpn_extras.h"
#include "ulong_extras.h"
#include "fmpz.h"
#include "fmpz_poly.h"

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
#include <pthread.h>

static pthread_once_t _factor_trial_initialised = PTHREAD_ONCE_INIT;
Expand All @@ -25,7 +24,7 @@ pthread_mutex_t _factor_trial_lock;
FLINT_TLS_PREFIX mp_ptr _factor_trial_tree[16 - (FLINT_BITS/32)];
FLINT_TLS_PREFIX int _factor_trial_tree_initialised = 0;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
void _tree_mutex_init(void)
{
pthread_mutex_init(&_factor_trial_lock, NULL);
Expand All @@ -48,7 +47,7 @@ _factor_trial_tree_init(void)
slong i, j, k, m, n;
const mp_limb_t * primes;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_once(&_factor_trial_initialised, _tree_mutex_init);
pthread_mutex_lock(&_factor_trial_lock);
#endif
Expand Down Expand Up @@ -108,7 +107,7 @@ _factor_trial_tree_init(void)
_factor_trial_tree_initialised = 1;
}

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_mutex_unlock(&_factor_trial_lock);
#endif
}
Expand Down
3 changes: 0 additions & 3 deletions src/nmod_poly/compose_mod_brent_kung_vec_preinv_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#if FLINT_USES_PTHREAD
#include <pthread.h>
#endif
#include "thread_support.h"
#include "ulong_extras.h"
#include "nmod_vec.h"
Expand Down
11 changes: 4 additions & 7 deletions src/ulong_extras/compute_primes.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include <string.h>

#include "flint.h"
#include "ulong_extras.h"

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
#include <pthread.h>

static pthread_once_t primes_initialised = PTHREAD_ONCE_INIT;
Expand All @@ -43,7 +40,7 @@ FLINT_TLS_PREFIX mp_limb_t * _flint_primes[FLINT_BITS];
FLINT_TLS_PREFIX double * _flint_prime_inverses[FLINT_BITS];
FLINT_TLS_PREFIX int _flint_primes_used = 0;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
void n_compute_primes_init()
{
pthread_mutex_init(&primes_lock, NULL);
Expand All @@ -56,7 +53,7 @@ n_compute_primes(ulong num_primes)
int i, m;
ulong num_computed;

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_once(&primes_initialised, n_compute_primes_init);
pthread_mutex_lock(&primes_lock);
#endif
Expand Down Expand Up @@ -91,7 +88,7 @@ n_compute_primes(ulong num_primes)
_flint_primes_used = m + 1;
}

#if FLINT_REENTRANT && !FLINT_USES_TLS
#if FLINT_REENTRANT && !FLINT_USES_TLS && FLINT_USES_PTHREAD
pthread_mutex_unlock(&primes_lock);
#endif
}
Expand Down

0 comments on commit c75ca82

Please sign in to comment.