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

« back to all changes in this revision

Viewing changes to list.h

  • 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:
40
40
/*#define LIST_TEST*/
41
41
 
42
42
#include "basic.h"
43
 
#include "thread.h"
44
43
#include "buffer.h"
45
44
 
46
45
#define hashsize(n) ((uint32_t)1<<(n))
56
55
 
57
56
struct hash_bucket
58
57
{
59
 
  MUTEX_DEFINE (mutex);
60
58
  struct hash_element *list;
61
59
};
62
60
 
90
88
                       const void *key,
91
89
                       uint32_t hv);
92
90
 
93
 
void hash_remove_by_value (struct hash *hash, void *value, bool autolock);
 
91
void hash_remove_by_value (struct hash *hash, void *value);
94
92
 
95
93
struct hash_iterator
96
94
{
100
98
  struct hash_element *elem;
101
99
  struct hash_element *last;
102
100
  bool bucket_marked;
103
 
  bool autolock;
104
101
  int bucket_index_start;
105
102
  int bucket_index_end;
106
103
};
107
104
 
108
105
void hash_iterator_init_range (struct hash *hash,
109
106
                               struct hash_iterator *hi,
110
 
                               bool autolock,
111
107
                               int start_bucket,
112
108
                               int end_bucket);
113
109
 
114
 
void hash_iterator_init (struct hash *hash, struct hash_iterator *iter, bool autolock);
 
110
void hash_iterator_init (struct hash *hash, struct hash_iterator *iter);
115
111
struct hash_element *hash_iterator_next (struct hash_iterator *hi);
116
112
void hash_iterator_delete_element (struct hash_iterator *hi);
117
113
void hash_iterator_free (struct hash_iterator *hi);
149
145
  return &hash->buckets[hv & hash->mask];
150
146
}
151
147
 
152
 
static inline void
153
 
hash_bucket_lock (struct hash_bucket *bucket)
154
 
{
155
 
  mutex_lock (&bucket->mutex);
156
 
}
157
 
 
158
 
static inline void
159
 
hash_bucket_unlock (struct hash_bucket *bucket)
160
 
{
161
 
  mutex_unlock (&bucket->mutex);
162
 
}
163
 
 
164
148
static inline void *
165
 
hash_lookup_lock (struct hash *hash, const void *key, uint32_t hv)
 
149
hash_lookup (struct hash *hash, const void *key)
166
150
{
167
151
  void *ret = NULL;
168
152
  struct hash_element *he;
 
153
  uint32_t hv = hash_value (hash, key);
169
154
  struct hash_bucket *bucket = &hash->buckets[hv & hash->mask];
170
155
 
171
 
  mutex_lock (&bucket->mutex);
172
156
  he = hash_lookup_fast (hash, bucket, key, hv);
173
157
  if (he)
174
158
    ret = he->value;
175
 
  mutex_unlock (&bucket->mutex);
176
159
 
177
160
  return ret;
178
161
}
179
162
 
180
 
static inline void *
181
 
hash_lookup (struct hash *hash, const void *key)
182
 
{
183
 
  return hash_lookup_lock (hash, key, hash_value (hash, key));
184
 
}
185
 
 
186
163
/* NOTE: assumes that key is not a duplicate */
187
164
static inline void
188
165
hash_add_fast (struct hash *hash,
211
188
 
212
189
  hv = hash_value (hash, key);
213
190
  bucket = &hash->buckets[hv & hash->mask];
214
 
  mutex_lock (&bucket->mutex);
215
191
  ret = hash_remove_fast (hash, bucket, key, hv);
216
 
  mutex_unlock (&bucket->mutex);
217
192
  return ret;
218
193
}
219
194