ovs-thread: Use fair (but nonrecursive) rwlocks on glibc.
[sliver-openvswitch.git] / lib / ovs-thread.c
1 /*
2  * Copyright (c) 2013, 2014 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <config.h>
18 #include "ovs-thread.h"
19 #include <errno.h>
20 #include <poll.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include "compiler.h"
24 #include "hash.h"
25 #include "poll-loop.h"
26 #include "socket-util.h"
27 #include "util.h"
28
29 #ifdef __CHECKER__
30 /* Omit the definitions in this file because they are somewhat difficult to
31  * write without prompting "sparse" complaints, without ugliness or
32  * cut-and-paste.  Since "sparse" is just a checker, not a compiler, it
33  * doesn't matter that we don't define them. */
34 #else
35 #include "vlog.h"
36
37 VLOG_DEFINE_THIS_MODULE(ovs_thread);
38
39 /* If there is a reason that we cannot fork anymore (unless the fork will be
40  * immediately followed by an exec), then this points to a string that
41  * explains why. */
42 static const char *must_not_fork;
43
44 /* True if we created any threads beyond the main initial thread. */
45 static bool multithreaded;
46
47 #define LOCK_FUNCTION(TYPE, FUN) \
48     void \
49     ovs_##TYPE##_##FUN##_at(const struct ovs_##TYPE *l_, \
50                             const char *where) \
51         OVS_NO_THREAD_SAFETY_ANALYSIS \
52     { \
53         struct ovs_##TYPE *l = CONST_CAST(struct ovs_##TYPE *, l_); \
54         int error = pthread_##TYPE##_##FUN(&l->lock); \
55         if (OVS_UNLIKELY(error)) { \
56             ovs_abort(error, "pthread_%s_%s failed", #TYPE, #FUN); \
57         } \
58         l->where = where; \
59     }
60 LOCK_FUNCTION(mutex, lock);
61 LOCK_FUNCTION(rwlock, rdlock);
62 LOCK_FUNCTION(rwlock, wrlock);
63
64 #define TRY_LOCK_FUNCTION(TYPE, FUN) \
65     int \
66     ovs_##TYPE##_##FUN##_at(const struct ovs_##TYPE *l_, \
67                             const char *where) \
68         OVS_NO_THREAD_SAFETY_ANALYSIS \
69     { \
70         struct ovs_##TYPE *l = CONST_CAST(struct ovs_##TYPE *, l_); \
71         int error = pthread_##TYPE##_##FUN(&l->lock); \
72         if (OVS_UNLIKELY(error) && error != EBUSY) { \
73             ovs_abort(error, "pthread_%s_%s failed", #TYPE, #FUN); \
74         } \
75         if (!error) { \
76             l->where = where; \
77         } \
78         return error; \
79     }
80 TRY_LOCK_FUNCTION(mutex, trylock);
81 TRY_LOCK_FUNCTION(rwlock, tryrdlock);
82 TRY_LOCK_FUNCTION(rwlock, trywrlock);
83
84 #define UNLOCK_FUNCTION(TYPE, FUN) \
85     void \
86     ovs_##TYPE##_##FUN(const struct ovs_##TYPE *l_) \
87         OVS_NO_THREAD_SAFETY_ANALYSIS \
88     { \
89         struct ovs_##TYPE *l = CONST_CAST(struct ovs_##TYPE *, l_); \
90         int error; \
91         l->where = NULL; \
92         error = pthread_##TYPE##_##FUN(&l->lock); \
93         if (OVS_UNLIKELY(error)) { \
94             ovs_abort(error, "pthread_%s_%sfailed", #TYPE, #FUN); \
95         } \
96     }
97 UNLOCK_FUNCTION(mutex, unlock);
98 UNLOCK_FUNCTION(mutex, destroy);
99 UNLOCK_FUNCTION(rwlock, unlock);
100 UNLOCK_FUNCTION(rwlock, destroy);
101
102 #define XPTHREAD_FUNC1(FUNCTION, PARAM1)                \
103     void                                                \
104     x##FUNCTION(PARAM1 arg1)                            \
105     {                                                   \
106         int error = FUNCTION(arg1);                     \
107         if (OVS_UNLIKELY(error)) {                      \
108             ovs_abort(error, "%s failed", #FUNCTION);   \
109         }                                               \
110     }
111 #define XPTHREAD_FUNC2(FUNCTION, PARAM1, PARAM2)        \
112     void                                                \
113     x##FUNCTION(PARAM1 arg1, PARAM2 arg2)               \
114     {                                                   \
115         int error = FUNCTION(arg1, arg2);               \
116         if (OVS_UNLIKELY(error)) {                      \
117             ovs_abort(error, "%s failed", #FUNCTION);   \
118         }                                               \
119     }
120
121 XPTHREAD_FUNC1(pthread_mutex_lock, pthread_mutex_t *);
122 XPTHREAD_FUNC1(pthread_mutex_unlock, pthread_mutex_t *);
123 XPTHREAD_FUNC1(pthread_mutexattr_init, pthread_mutexattr_t *);
124 XPTHREAD_FUNC1(pthread_mutexattr_destroy, pthread_mutexattr_t *);
125 XPTHREAD_FUNC2(pthread_mutexattr_settype, pthread_mutexattr_t *, int);
126 XPTHREAD_FUNC2(pthread_mutexattr_gettype, pthread_mutexattr_t *, int *);
127
128 XPTHREAD_FUNC1(pthread_rwlockattr_init, pthread_rwlockattr_t *);
129 XPTHREAD_FUNC1(pthread_rwlockattr_destroy, pthread_rwlockattr_t *);
130 #ifdef PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP
131 XPTHREAD_FUNC2(pthread_rwlockattr_setkind_np, pthread_rwlockattr_t *, int);
132 #endif
133
134 XPTHREAD_FUNC2(pthread_cond_init, pthread_cond_t *, pthread_condattr_t *);
135 XPTHREAD_FUNC1(pthread_cond_destroy, pthread_cond_t *);
136 XPTHREAD_FUNC1(pthread_cond_signal, pthread_cond_t *);
137 XPTHREAD_FUNC1(pthread_cond_broadcast, pthread_cond_t *);
138
139 XPTHREAD_FUNC2(pthread_join, pthread_t, void **);
140
141 typedef void destructor_func(void *);
142 XPTHREAD_FUNC2(pthread_key_create, pthread_key_t *, destructor_func *);
143 XPTHREAD_FUNC1(pthread_key_delete, pthread_key_t);
144 XPTHREAD_FUNC2(pthread_setspecific, pthread_key_t, const void *);
145
146 static void
147 ovs_mutex_init__(const struct ovs_mutex *l_, int type)
148 {
149     struct ovs_mutex *l = CONST_CAST(struct ovs_mutex *, l_);
150     pthread_mutexattr_t attr;
151     int error;
152
153     l->where = NULL;
154     xpthread_mutexattr_init(&attr);
155     xpthread_mutexattr_settype(&attr, type);
156     error = pthread_mutex_init(&l->lock, &attr);
157     if (OVS_UNLIKELY(error)) {
158         ovs_abort(error, "pthread_mutex_init failed");
159     }
160     xpthread_mutexattr_destroy(&attr);
161 }
162
163 /* Initializes 'mutex' as a normal (non-recursive) mutex. */
164 void
165 ovs_mutex_init(const struct ovs_mutex *mutex)
166 {
167     ovs_mutex_init__(mutex, PTHREAD_MUTEX_ERRORCHECK);
168 }
169
170 /* Initializes 'mutex' as a recursive mutex. */
171 void
172 ovs_mutex_init_recursive(const struct ovs_mutex *mutex)
173 {
174     ovs_mutex_init__(mutex, PTHREAD_MUTEX_RECURSIVE);
175 }
176
177 /* Initializes 'mutex' as a recursive mutex. */
178 void
179 ovs_mutex_init_adaptive(const struct ovs_mutex *mutex)
180 {
181 #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
182     ovs_mutex_init__(mutex, PTHREAD_MUTEX_ADAPTIVE_NP);
183 #else
184     ovs_mutex_init(mutex);
185 #endif
186 }
187
188 void
189 ovs_rwlock_init(const struct ovs_rwlock *l_)
190 {
191     struct ovs_rwlock *l = CONST_CAST(struct ovs_rwlock *, l_);
192     pthread_rwlockattr_t attr;
193     int error;
194
195     l->where = NULL;
196
197     xpthread_rwlockattr_init(&attr);
198 #ifdef PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP
199     xpthread_rwlockattr_setkind_np(
200         &attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
201 #endif
202     error = pthread_rwlock_init(&l->lock, NULL);
203     if (OVS_UNLIKELY(error)) {
204         ovs_abort(error, "pthread_rwlock_init failed");
205     }
206     xpthread_rwlockattr_destroy(&attr);
207 }
208
209 void
210 ovs_mutex_cond_wait(pthread_cond_t *cond, const struct ovs_mutex *mutex_)
211 {
212     struct ovs_mutex *mutex = CONST_CAST(struct ovs_mutex *, mutex_);
213     int error = pthread_cond_wait(cond, &mutex->lock);
214     if (OVS_UNLIKELY(error)) {
215         ovs_abort(error, "pthread_cond_wait failed");
216     }
217 }
218 \f
219 DEFINE_EXTERN_PER_THREAD_DATA(ovsthread_id, 0);
220
221 struct ovsthread_aux {
222     void *(*start)(void *);
223     void *arg;
224 };
225
226 static void *
227 ovsthread_wrapper(void *aux_)
228 {
229     static atomic_uint next_id = ATOMIC_VAR_INIT(1);
230
231     struct ovsthread_aux *auxp = aux_;
232     struct ovsthread_aux aux;
233     unsigned int id;
234
235     atomic_add(&next_id, 1, &id);
236     *ovsthread_id_get() = id;
237
238     aux = *auxp;
239     free(auxp);
240
241     return aux.start(aux.arg);
242 }
243
244 void
245 xpthread_create(pthread_t *threadp, pthread_attr_t *attr,
246                 void *(*start)(void *), void *arg)
247 {
248     struct ovsthread_aux *aux;
249     pthread_t thread;
250     int error;
251
252     forbid_forking("multiple threads exist");
253     multithreaded = true;
254
255     aux = xmalloc(sizeof *aux);
256     aux->start = start;
257     aux->arg = arg;
258
259     error = pthread_create(threadp ? threadp : &thread, attr,
260                            ovsthread_wrapper, aux);
261     if (error) {
262         ovs_abort(error, "pthread_create failed");
263     }
264 }
265 \f
266 bool
267 ovsthread_once_start__(struct ovsthread_once *once)
268 {
269     ovs_mutex_lock(&once->mutex);
270     if (!ovsthread_once_is_done__(once)) {
271         return false;
272     }
273     ovs_mutex_unlock(&once->mutex);
274     return true;
275 }
276
277 void
278 ovsthread_once_done(struct ovsthread_once *once)
279 {
280     atomic_store(&once->done, true);
281     ovs_mutex_unlock(&once->mutex);
282 }
283 \f
284 /* Asserts that the process has not yet created any threads (beyond the initial
285  * thread).
286  *
287  * ('where' is used in logging.  Commonly one would use
288  * assert_single_threaded() to automatically provide the caller's source file
289  * and line number for 'where'.) */
290 void
291 assert_single_threaded_at(const char *where)
292 {
293     if (multithreaded) {
294         VLOG_FATAL("%s: attempted operation not allowed when multithreaded",
295                    where);
296     }
297 }
298
299 /* Forks the current process (checking that this is allowed).  Aborts with
300  * VLOG_FATAL if fork() returns an error, and otherwise returns the value
301  * returned by fork().
302  *
303  * ('where' is used in logging.  Commonly one would use xfork() to
304  * automatically provide the caller's source file and line number for
305  * 'where'.) */
306 pid_t
307 xfork_at(const char *where)
308 {
309     pid_t pid;
310
311     if (must_not_fork) {
312         VLOG_FATAL("%s: attempted to fork but forking not allowed (%s)",
313                    where, must_not_fork);
314     }
315
316     pid = fork();
317     if (pid < 0) {
318         VLOG_FATAL("%s: fork failed (%s)", where, ovs_strerror(errno));
319     }
320     return pid;
321 }
322
323 /* Notes that the process must not call fork() from now on, for the specified
324  * 'reason'.  (The process may still fork() if it execs itself immediately
325  * afterward.) */
326 void
327 forbid_forking(const char *reason)
328 {
329     ovs_assert(reason != NULL);
330     must_not_fork = reason;
331 }
332
333 /* Returns true if the process is allowed to fork, false otherwise. */
334 bool
335 may_fork(void)
336 {
337     return !must_not_fork;
338 }
339 \f
340 /* ovsthread_counter.
341  *
342  * We implement the counter as an array of N_COUNTERS individual counters, each
343  * with its own lock.  Each thread uses one of the counters chosen based on a
344  * hash of the thread's ID, the idea being that, statistically, different
345  * threads will tend to use different counters and therefore avoid
346  * interfering with each other.
347  *
348  * Undoubtedly, better implementations are possible. */
349
350 /* Basic counter structure. */
351 struct ovsthread_counter__ {
352     struct ovs_mutex mutex;
353     unsigned long long int value;
354 };
355
356 /* Pad the basic counter structure to 64 bytes to avoid cache line
357  * interference. */
358 struct ovsthread_counter {
359     struct ovsthread_counter__ c;
360     char pad[ROUND_UP(sizeof(struct ovsthread_counter__), 64)
361              - sizeof(struct ovsthread_counter__)];
362 };
363
364 #define N_COUNTERS 16
365
366 struct ovsthread_counter *
367 ovsthread_counter_create(void)
368 {
369     struct ovsthread_counter *c;
370     int i;
371
372     c = xmalloc(N_COUNTERS * sizeof *c);
373     for (i = 0; i < N_COUNTERS; i++) {
374         ovs_mutex_init(&c[i].c.mutex);
375         c[i].c.value = 0;
376     }
377     return c;
378 }
379
380 void
381 ovsthread_counter_destroy(struct ovsthread_counter *c)
382 {
383     if (c) {
384         int i;
385
386         for (i = 0; i < N_COUNTERS; i++) {
387             ovs_mutex_destroy(&c[i].c.mutex);
388         }
389         free(c);
390     }
391 }
392
393 void
394 ovsthread_counter_inc(struct ovsthread_counter *c, unsigned long long int n)
395 {
396     c = &c[hash_int(ovsthread_id_self(), 0) % N_COUNTERS];
397
398     ovs_mutex_lock(&c->c.mutex);
399     c->c.value += n;
400     ovs_mutex_unlock(&c->c.mutex);
401 }
402
403 unsigned long long int
404 ovsthread_counter_read(const struct ovsthread_counter *c)
405 {
406     unsigned long long int sum;
407     int i;
408
409     sum = 0;
410     for (i = 0; i < N_COUNTERS; i++) {
411         ovs_mutex_lock(&c[i].c.mutex);
412         sum += c[i].c.value;
413         ovs_mutex_unlock(&c[i].c.mutex);
414     }
415     return sum;
416 }
417 \f
418 /* Parses /proc/cpuinfo for the total number of physical cores on this system
419  * across all CPU packages, not counting hyper-threads.
420  *
421  * Sets *n_cores to the total number of cores on this system, or 0 if the
422  * number cannot be determined. */
423 static void
424 parse_cpuinfo(long int *n_cores)
425 {
426     static const char file_name[] = "/proc/cpuinfo";
427     char line[128];
428     uint64_t cpu = 0; /* Support up to 64 CPU packages on a single system. */
429     long int cores = 0;
430     FILE *stream;
431
432     stream = fopen(file_name, "r");
433     if (!stream) {
434         VLOG_DBG("%s: open failed (%s)", file_name, ovs_strerror(errno));
435         return;
436     }
437
438     while (fgets(line, sizeof line, stream)) {
439         unsigned int id;
440
441         /* Find the next CPU package. */
442         if (ovs_scan(line, "physical id%*[^:]: %u", &id)) {
443             if (id > 63) {
444                 VLOG_WARN("Counted over 64 CPU packages on this system. "
445                           "Parsing %s for core count may be inaccurate.",
446                           file_name);
447                 cores = 0;
448                 break;
449             }
450
451             if (cpu & (1 << id)) {
452                 /* We've already counted this package's cores. */
453                 continue;
454             }
455             cpu |= 1 << id;
456
457             /* Find the number of cores for this package. */
458             while (fgets(line, sizeof line, stream)) {
459                 int count;
460
461                 if (ovs_scan(line, "cpu cores%*[^:]: %u", &count)) {
462                     cores += count;
463                     break;
464                 }
465             }
466         }
467     }
468     fclose(stream);
469
470     *n_cores = cores;
471 }
472
473 /* Returns the total number of cores on this system, or 0 if the number cannot
474  * be determined.
475  *
476  * Tries not to count hyper-threads, but may be inaccurate - particularly on
477  * platforms that do not provide /proc/cpuinfo, but also if /proc/cpuinfo is
478  * formatted different to the layout that parse_cpuinfo() expects. */
479 int
480 count_cpu_cores(void)
481 {
482     static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
483     static long int n_cores;
484
485     if (ovsthread_once_start(&once)) {
486         parse_cpuinfo(&n_cores);
487         if (!n_cores) {
488             n_cores = sysconf(_SC_NPROCESSORS_ONLN);
489         }
490         ovsthread_once_done(&once);
491     }
492
493     return n_cores > 0 ? n_cores : 0;
494 }
495 \f
496 /* ovsthread_key. */
497
498 #define L1_SIZE 1024
499 #define L2_SIZE 1024
500 #define MAX_KEYS (L1_SIZE * L2_SIZE)
501
502 /* A piece of thread-specific data. */
503 struct ovsthread_key {
504     struct list list_node;      /* In 'inuse_keys' or 'free_keys'. */
505     void (*destructor)(void *); /* Called at thread exit. */
506
507     /* Indexes into the per-thread array in struct ovsthread_key_slots.
508      * This key's data is stored in p1[index / L2_SIZE][index % L2_SIZE]. */
509     unsigned int index;
510 };
511
512 /* Per-thread data structure. */
513 struct ovsthread_key_slots {
514     struct list list_node;      /* In 'slots_list'. */
515     void **p1[L1_SIZE];
516 };
517
518 /* Contains "struct ovsthread_key_slots *". */
519 static pthread_key_t tsd_key;
520
521 /* Guards data structures below. */
522 static struct ovs_mutex key_mutex = OVS_MUTEX_INITIALIZER;
523
524 /* 'inuse_keys' holds "struct ovsthread_key"s that have been created and not
525  * yet destroyed.
526  *
527  * 'free_keys' holds "struct ovsthread_key"s that have been deleted and are
528  * ready for reuse.  (We keep them around only to be able to easily locate
529  * free indexes.)
530  *
531  * Together, 'inuse_keys' and 'free_keys' hold an ovsthread_key for every index
532  * from 0 to n_keys - 1, inclusive. */
533 static struct list inuse_keys OVS_GUARDED_BY(key_mutex)
534     = LIST_INITIALIZER(&inuse_keys);
535 static struct list free_keys OVS_GUARDED_BY(key_mutex)
536     = LIST_INITIALIZER(&free_keys);
537 static unsigned int n_keys OVS_GUARDED_BY(key_mutex);
538
539 /* All existing struct ovsthread_key_slots. */
540 static struct list slots_list OVS_GUARDED_BY(key_mutex)
541     = LIST_INITIALIZER(&slots_list);
542
543 static void *
544 clear_slot(struct ovsthread_key_slots *slots, unsigned int index)
545 {
546     void **p2 = slots->p1[index / L2_SIZE];
547     if (p2) {
548         void **valuep = &p2[index % L2_SIZE];
549         void *value = *valuep;
550         *valuep = NULL;
551         return value;
552     } else {
553         return NULL;
554     }
555 }
556
557 static void
558 ovsthread_key_destruct__(void *slots_)
559 {
560     struct ovsthread_key_slots *slots = slots_;
561     struct ovsthread_key *key;
562     unsigned int n;
563     int i;
564
565     ovs_mutex_lock(&key_mutex);
566     list_remove(&slots->list_node);
567     LIST_FOR_EACH (key, list_node, &inuse_keys) {
568         void *value = clear_slot(slots, key->index);
569         if (value && key->destructor) {
570             key->destructor(value);
571         }
572     }
573     n = n_keys;
574     ovs_mutex_unlock(&key_mutex);
575
576     for (i = 0; i < n / L2_SIZE; i++) {
577         free(slots->p1[i]);
578     }
579     free(slots);
580 }
581
582 /* Initializes '*keyp' as a thread-specific data key.  The data items are
583  * initially null in all threads.
584  *
585  * If a thread exits with non-null data, then 'destructor', if nonnull, will be
586  * called passing the final data value as its argument.  'destructor' must not
587  * call any thread-specific data functions in this API.
588  *
589  * This function is similar to xpthread_key_create(). */
590 void
591 ovsthread_key_create(ovsthread_key_t *keyp, void (*destructor)(void *))
592 {
593     static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
594     struct ovsthread_key *key;
595
596     if (ovsthread_once_start(&once)) {
597         xpthread_key_create(&tsd_key, ovsthread_key_destruct__);
598         ovsthread_once_done(&once);
599     }
600
601     ovs_mutex_lock(&key_mutex);
602     if (list_is_empty(&free_keys)) {
603         key = xmalloc(sizeof *key);
604         key->index = n_keys++;
605         if (key->index >= MAX_KEYS) {
606             abort();
607         }
608     } else {
609         key = CONTAINER_OF(list_pop_back(&free_keys),
610                             struct ovsthread_key, list_node);
611     }
612     list_push_back(&inuse_keys, &key->list_node);
613     key->destructor = destructor;
614     ovs_mutex_unlock(&key_mutex);
615
616     *keyp = key;
617 }
618
619 /* Frees 'key'.  The destructor supplied to ovsthread_key_create(), if any, is
620  * not called.
621  *
622  * This function is similar to xpthread_key_delete(). */
623 void
624 ovsthread_key_delete(ovsthread_key_t key)
625 {
626     struct ovsthread_key_slots *slots;
627
628     ovs_mutex_lock(&key_mutex);
629
630     /* Move 'key' from 'inuse_keys' to 'free_keys'. */
631     list_remove(&key->list_node);
632     list_push_back(&free_keys, &key->list_node);
633
634     /* Clear this slot in all threads. */
635     LIST_FOR_EACH (slots, list_node, &slots_list) {
636         clear_slot(slots, key->index);
637     }
638
639     ovs_mutex_unlock(&key_mutex);
640 }
641
642 static void **
643 ovsthread_key_lookup__(const struct ovsthread_key *key)
644 {
645     struct ovsthread_key_slots *slots;
646     void **p2;
647
648     slots = pthread_getspecific(tsd_key);
649     if (!slots) {
650         slots = xzalloc(sizeof *slots);
651
652         ovs_mutex_lock(&key_mutex);
653         pthread_setspecific(tsd_key, slots);
654         list_push_back(&slots_list, &slots->list_node);
655         ovs_mutex_unlock(&key_mutex);
656     }
657
658     p2 = slots->p1[key->index / L2_SIZE];
659     if (!p2) {
660         p2 = xzalloc(L2_SIZE * sizeof *p2);
661         slots->p1[key->index / L2_SIZE] = p2;
662     }
663
664     return &p2[key->index % L2_SIZE];
665 }
666
667 /* Sets the value of thread-specific data item 'key', in the current thread, to
668  * 'value'.
669  *
670  * This function is similar to pthread_setspecific(). */
671 void
672 ovsthread_setspecific(ovsthread_key_t key, const void *value)
673 {
674     *ovsthread_key_lookup__(key) = CONST_CAST(void *, value);
675 }
676
677 /* Returns the value of thread-specific data item 'key' in the current thread.
678  *
679  * This function is similar to pthread_getspecific(). */
680 void *
681 ovsthread_getspecific(ovsthread_key_t key)
682 {
683     return *ovsthread_key_lookup__(key);
684 }
685 #endif