1228904Sed/*-
2228904Sed * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
3228904Sed * All rights reserved.
4228904Sed *
5228904Sed * Redistribution and use in source and binary forms, with or without
6228904Sed * modification, are permitted provided that the following conditions
7228904Sed * are met:
8228904Sed * 1. Redistributions of source code must retain the above copyright
9228904Sed *    notice, this list of conditions and the following disclaimer.
10228904Sed * 2. Redistributions in binary form must reproduce the above copyright
11228904Sed *    notice, this list of conditions and the following disclaimer in the
12228904Sed *    documentation and/or other materials provided with the distribution.
13228904Sed *
14228904Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15228904Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16228904Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17228904Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18228904Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19228904Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20228904Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21228904Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22228904Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23228904Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24228904Sed * SUCH DAMAGE.
25228904Sed *
26228904Sed * $FreeBSD$
27228904Sed */
28228904Sed
29228904Sed#include <sys/cdefs.h>
30228904Sed__FBSDID("$FreeBSD$");
31228904Sed
32228904Sed#include <pthread.h>
33228904Sed
34228904Sed#include "threads.h"
35228904Sed
36228904Sedint
37228904Sedtss_create(tss_t *key, tss_dtor_t dtor)
38228904Sed{
39228904Sed
40228904Sed	if (pthread_key_create(key, dtor) != 0)
41228904Sed		return (thrd_error);
42228904Sed	return (thrd_success);
43228904Sed}
44228904Sed
45228904Sedvoid
46228904Sedtss_delete(tss_t key)
47228904Sed{
48228904Sed
49228904Sed	(void)pthread_key_delete(key);
50228904Sed}
51228904Sed
52228904Sedvoid *
53228904Sedtss_get(tss_t key)
54228904Sed{
55228904Sed
56228904Sed	return (pthread_getspecific(key));
57228904Sed}
58228904Sed
59228904Sedint
60228904Sedtss_set(tss_t key, void *val)
61228904Sed{
62228904Sed
63228904Sed	if (pthread_setspecific(key, val) != 0)
64228904Sed		return (thrd_error);
65228904Sed	return (thrd_success);
66228904Sed}
67228904Sed
68228904Sed_Static_assert(TSS_DTOR_ITERATIONS == PTHREAD_DESTRUCTOR_ITERATIONS,
69228904Sed    "TSS_DTOR_ITERATIONS must be identical to PTHREAD_DESTRUCTOR_ITERATIONS");
70