View | Details | Raw Unified | Return to bug 13594
Collapse All | Expand All

(-)c/nscd/nscd_gethst_r.c (-2 / +25 lines)
Lines 101-109 libc_freeres_fn (hst_map_free) Link Here
101
uint32_t
101
uint32_t
102
__nscd_get_nl_timestamp (void)
102
__nscd_get_nl_timestamp (void)
103
{
103
{
104
  uint32_t retval;
104
  if (__nss_not_use_nscd_hosts != 0)
105
  if (__nss_not_use_nscd_hosts != 0)
105
    return 0;
106
    return 0;
106
107
108
  int cnt = 0;
109
  /* __nscd_get_mapping can change hst_map_handle.mapped to NO_MAPPING.
110
   However, __nscd_get_mapping assumes the prior value was not NO_MAPPING.
111
   Thus we have to acquire the lock to prevent this thread from changing
112
   hst_map_handle.mapped to NO_MAPPING while another thread is inside
113
    __nscd_get_mapping.  */
114
  while (__builtin_expect
115
	 (atomic_compare_and_exchange_val_acq (&__hst_map_handle.lock,
116
					       1, 0) != 0, 0))
117
    {
118
      // XXX Best number of rounds?
119
      if (__builtin_expect (++cnt > 5, 0))
120
	return 0;
121
122
      atomic_delay ();
123
    }
124
107
  struct mapped_database *map = __hst_map_handle.mapped;
125
  struct mapped_database *map = __hst_map_handle.mapped;
108
126
109
  if (map == NULL
127
  if (map == NULL
Lines 113-121 __nscd_get_nl_timestamp (void) Link Here
113
    map = __nscd_get_mapping (GETFDHST, "hosts", &__hst_map_handle.mapped);
131
    map = __nscd_get_mapping (GETFDHST, "hosts", &__hst_map_handle.mapped);
114
132
115
  if (map == NO_MAPPING)
133
  if (map == NO_MAPPING)
116
    return 0;
134
    retval =  0;
135
  else
136
    retval =  map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];
137
138
  /* Release the lock.  */
139
  __hst_map_handle.lock = 0;
117
140
118
  return map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP];
141
  return retval;
119
}
142
}
120
143
121
144

Return to bug 13594