summaryrefslogtreecommitdiff
path: root/libihash
diff options
context:
space:
mode:
authorMichael I. Bushnell <mib@gnu.org>1996-03-07 20:01:41 +0000
committerMichael I. Bushnell <mib@gnu.org>1996-03-07 20:01:41 +0000
commitea4adbb21496f8d93b72c640e70b3c3a418a383f (patch)
treef5bde8b7d29dac9a8e7e44f3e2634f3919e0af6a /libihash
parent49ec2d3e1fcb4caaf97a2cfe3b924dd6d51769c9 (diff)
Include <spin_lock.h>.
(table_lock): New variable. (nextprime): Lock table_lock around operation of routine.
Diffstat (limited to 'libihash')
-rw-r--r--libihash/primes.c15
1 files 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 <limits.h>
#include <string.h>
#include <assert.h>
+#include <spin-lock.h>
#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];
}
}