From ea4adbb21496f8d93b72c640e70b3c3a418a383f Mon Sep 17 00:00:00 2001 From: "Michael I. Bushnell" Date: Thu, 7 Mar 1996 20:01:41 +0000 Subject: Include . (table_lock): New variable. (nextprime): Lock table_lock around operation of routine. --- libihash/primes.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libihash/primes.c b/libihash/primes.c index d0fc4d0c..5637e90d 100644 --- a/libihash/primes.c +++ b/libihash/primes.c @@ -1,5 +1,5 @@ /* Prime number generation - Copyright (C) 1994 Free Software Foundation + Copyright (C) 1994, 1996 Free Software Foundation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -19,10 +19,13 @@ #include #include #include +#include #define BITS_PER_UNSIGNED (8 * sizeof (unsigned)) #define SQRT_INT_MAX (1 << (BITS_PER_UNSIGNED / 2)) +static spin_lock_t table_lock = SPIN_LOCK_INITIALIZER; + /* Return the next prime greater than or equal to N. */ int nextprime (unsigned n) @@ -39,6 +42,8 @@ nextprime (unsigned n) static unsigned next_sieve; /* always even */ unsigned max_prime; + spin_lock (&table_lock); + if (! primes) { primes_size = 128; @@ -55,8 +60,11 @@ nextprime (unsigned n) } if (n <= primes[0]) - return primes[0]; - + { + spin_unlock (&table_lock); + return primes[0]; + } + while (n > (max_prime = primes[primes_len - 1])) { /* primes doesn't contain any prime large enough. Sieve from @@ -129,6 +137,7 @@ nextprime (unsigned n) top = mid; } + spin_unlock (&table_lock); return primes[top]; } } -- cgit v1.2.3