]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nscd: bump GC cycle during cache pruning (bug 26130)
authorAndreas Schwab <schwab@suse.de>
Wed, 17 Jun 2020 14:05:13 +0000 (16:05 +0200)
committerAndreas Schwab <schwab@suse.de>
Thu, 17 Sep 2020 15:59:11 +0000 (17:59 +0200)
While nscd prunes a cache it becomes inconsistent temporarily, which is
visible to clients if that cache is shared.  Bump the GC cycle counter so
that the clients notice the modification window.

Uniformly use atomic_fetch_add to modify the GC cycle counter.

nscd/cache.c
nscd/mem.c

index 0c4dfc0dcf01789eadc14dd1653da8d183ca50a5..38ddd6d7ec0bdd608661a8c4e033cb1a3846ca70 100644 (file)
@@ -452,6 +452,11 @@ prune_cache (struct database_dyn *table, time_t now, int fd)
          pthread_rwlock_wrlock (&table->lock);
        }
 
+      /* Now we start modifying the data.  Make sure all readers of the
+        data are aware of this and temporarily don't use the data.  */
+      atomic_fetch_add_relaxed (&table->head->gc_cycle, 1);
+      assert ((table->head->gc_cycle & 1) == 1);
+
       while (first <= last)
        {
          if (mark[first])
@@ -492,6 +497,10 @@ prune_cache (struct database_dyn *table, time_t now, int fd)
          ++first;
        }
 
+      /* Now we are done modifying the data.  */
+      atomic_fetch_add_relaxed (&table->head->gc_cycle, 1);
+      assert ((table->head->gc_cycle & 1) == 0);
+
       /* It's all done.  */
       pthread_rwlock_unlock (&table->lock);
 
index 3d10bb9b46121b918e2d6d61223c9d381f2d95c9..de5bd12db5f9a8c692b32c290c2f365e63f88329 100644 (file)
@@ -264,7 +264,7 @@ gc (struct database_dyn *db)
 
   /* Now we start modifying the data.  Make sure all readers of the
      data are aware of this and temporarily don't use the data.  */
-  ++db->head->gc_cycle;
+  atomic_fetch_add_relaxed (&db->head->gc_cycle, 1);
   assert ((db->head->gc_cycle & 1) == 1);
 
 
@@ -490,7 +490,7 @@ gc (struct database_dyn *db)
 
 
   /* Now we are done modifying the data.  */
-  ++db->head->gc_cycle;
+  atomic_fetch_add_relaxed (&db->head->gc_cycle, 1);
   assert ((db->head->gc_cycle & 1) == 0);
 
   /* We are done.  */