@@ -81,19 +81,26 @@ libat_lock_n (void *ptr, size_t n)
{
uintptr_t h = addr_hash (ptr);
size_t i = 0;
+ size_t l;
/* Don't lock more than all the locks we have. */
if (n > PAGE_SIZE)
n = PAGE_SIZE;
- do
+ l = n / CACHLINE_SIZE + h;
+
+ if (n % CACHLINE_SIZE)
+ l++;
+
+ if (l >= NLOCKS)
{
- pthread_mutex_lock (&locks[h].mutex);
- if (++h == NLOCKS)
- h = 0;
- i += WATCH_SIZE;
+ for (i=0; i < l - NLOCKS; i++)
+ pthread_mutex_lock (&locks[i].mutex);
+ l = NLOCKS;
}
- while (i < n);
+
+ for (i=h; i < l; i++)
+ pthread_mutex_lock (&locks[i].mutex);
}
void