]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nscd/nscd-client.h
NSS: Implement group merging support.
[thirdparty/glibc.git] / nscd / nscd-client.h
index 325368e73b317f6fafcd0576c7002d44a2dc6992..c0190ce3f8fc8709cafc957b330d117c112f998e 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998-2012 Free Software Foundation, Inc.
+/* Copyright (c) 1998-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
 
@@ -24,6 +24,8 @@
 
 #include <stdbool.h>
 #include <stdint.h>
+#include <string.h>
+#include <time.h>
 #include <sys/types.h>
 #include <atomic.h>
 #include <nscd-types.h>
@@ -236,6 +238,48 @@ struct datahead
   } data[0];
 };
 
+static inline time_t
+datahead_init_common (struct datahead *head, nscd_ssize_t allocsize,
+                     nscd_ssize_t recsize, uint32_t ttl)
+{
+  /* Initialize so that we don't write out junk in uninitialized data to the
+     cache.  */
+  memset (head, 0, sizeof (*head));
+
+  head->allocsize = allocsize;
+  head->recsize = recsize;
+  head->usable = true;
+
+  head->ttl = ttl;
+
+  /* Compute and return the timeout time.  */
+  return head->timeout = time (NULL) + ttl;
+}
+
+static inline time_t
+datahead_init_pos (struct datahead *head, nscd_ssize_t allocsize,
+                  nscd_ssize_t recsize, uint8_t nreloads, uint32_t ttl)
+{
+  time_t ret = datahead_init_common (head, allocsize, recsize, ttl);
+
+  head->notfound = false;
+  head->nreloads = nreloads;
+
+  return ret;
+}
+
+static inline time_t
+datahead_init_neg (struct datahead *head, nscd_ssize_t allocsize,
+                  nscd_ssize_t recsize, uint32_t ttl)
+{
+  time_t ret = datahead_init_common (head, allocsize, recsize, ttl);
+
+  /* We don't need to touch nreloads here since it is set to our desired value
+     (0) when we clear the structure.  */
+  head->notfound = true;
+
+  return ret;
+}
 
 /* Structure for one hash table entry.  */
 struct hashentry
@@ -323,17 +367,18 @@ struct locked_map_ptr
 
 /* Try acquiring lock for mapptr, returns true if it succeeds, false
    if not.  */
-static inline bool __nscd_acquire_maplock (volatile struct locked_map_ptr *mapptr)
+static inline bool
+__nscd_acquire_maplock (volatile struct locked_map_ptr *mapptr)
 {
   int cnt = 0;
   while (__builtin_expect (atomic_compare_and_exchange_val_acq (&mapptr->lock,
                                                                1, 0) != 0, 0))
     {
       // XXX Best number of rounds?
-      if (__builtin_expect (++cnt > 5, 0))
+      if (__glibc_unlikely (++cnt > 5))
        return false;
 
-      atomic_delay ();
+      atomic_spin_nop ();
     }
 
   return true;
@@ -361,13 +406,14 @@ extern struct mapped_database *__nscd_get_map_ref (request_type type,
 extern void __nscd_unmap (struct mapped_database *mapped);
 
 /* Drop reference of mapping.  */
-static inline int __nscd_drop_map_ref (struct mapped_database *map,
-                                      int *gc_cycle)
+static int
+__attribute__ ((unused))
+__nscd_drop_map_ref (struct mapped_database *map, int *gc_cycle)
 {
   if (map != NO_MAPPING)
     {
       int now_cycle = map->head->gc_cycle;
-      if (__builtin_expect (now_cycle != *gc_cycle, 0))
+      if (__glibc_unlikely (now_cycle != *gc_cycle))
        {
          /* We might have read inconsistent data.  */
          *gc_cycle = now_cycle;