~ubuntu-branches/ubuntu/oneiric/openvpn/oneiric

« back to all changes in this revision

Viewing changes to list.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-06-16 18:33:37 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 46.
  • Revision ID: james.westby@ubuntu.com-20110616183337-etb3qgbwjkn8zniq
Tags: upstream-2.2.0
ImportĀ upstreamĀ versionĀ 2.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    {
53
53
      struct hash_bucket *b = &h->buckets[i];
54
54
      b->list = NULL;
55
 
      mutex_init (&b->mutex);
56
55
    }
57
56
  return h;
58
57
}
66
65
      struct hash_bucket *b = &hash->buckets[i];
67
66
      struct hash_element *he = b->list;
68
67
 
69
 
      mutex_destroy (&b->mutex);
70
68
      while (he)
71
69
        {
72
70
          struct hash_element *next = he->next;
148
146
 
149
147
  hv = hash_value (hash, key);
150
148
  bucket = &hash->buckets[hv & hash->mask];
151
 
  mutex_lock (&bucket->mutex);
152
149
 
153
150
  if ((he = hash_lookup_fast (hash, bucket, key, hv))) /* already exists? */
154
151
    {
164
161
      ret = true;
165
162
    }
166
163
 
167
 
  mutex_unlock (&bucket->mutex);
168
 
 
169
164
  return ret;
170
165
}
171
166
 
172
167
void
173
 
hash_remove_by_value (struct hash *hash, void *value, bool autolock)
 
168
hash_remove_by_value (struct hash *hash, void *value)
174
169
{
175
170
  struct hash_iterator hi;
176
171
  struct hash_element *he;
177
172
 
178
 
  hash_iterator_init (hash, &hi, autolock);
 
173
  hash_iterator_init (hash, &hi);
179
174
  while ((he = hash_iterator_next (&hi)))
180
175
    {
181
176
      if (he->value == value)
226
221
void
227
222
hash_iterator_init_range (struct hash *hash,
228
223
                       struct hash_iterator *hi,
229
 
                       bool autolock,
230
224
                       int start_bucket,
231
225
                       int end_bucket)
232
226
{
238
232
  hi->hash = hash;
239
233
  hi->elem = NULL;
240
234
  hi->bucket = NULL;
241
 
  hi->autolock = autolock;
242
235
  hi->last = NULL;
243
236
  hi->bucket_marked = false;
244
237
  hi->bucket_index_start = start_bucket;
248
241
 
249
242
void
250
243
hash_iterator_init (struct hash *hash,
251
 
                    struct hash_iterator *hi,
252
 
                    bool autolock)
 
244
                    struct hash_iterator *hi)
253
245
{
254
 
  hash_iterator_init_range (hash, hi, autolock, 0, hash->n_buckets);
 
246
  hash_iterator_init_range (hash, hi, 0, hash->n_buckets);
255
247
}
256
248
 
257
249
static inline void
258
250
hash_iterator_lock (struct hash_iterator *hi, struct hash_bucket *b)
259
251
{
260
 
  if (hi->autolock)
261
 
    {
262
 
      mutex_lock (&b->mutex);
263
 
    }
264
252
  hi->bucket = b;
265
253
  hi->last = NULL;
266
254
  hi->bucket_marked = false;
276
264
          hash_remove_marked (hi->hash, hi->bucket);
277
265
          hi->bucket_marked = false;
278
266
        }
279
 
      if (hi->autolock)
280
 
        {
281
 
          mutex_unlock (&hi->bucket->mutex);
282
 
        }
283
267
      hi->bucket = NULL;
284
268
      hi->last = NULL;
285
269
    }