deprecated eval-when situations
[bpt/guile.git] / libguile / null-threads.c
CommitLineData
dbb605f5 1/* Copyright (C) 2002, 2006, 2008 Free Software Foundation, Inc.
3d527b27 2 *
73be1d9e 3 * This library is free software; you can redistribute it and/or
53befeb7
NJ
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
3d527b27 7 *
53befeb7
NJ
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
3d527b27 12 *
73be1d9e
MV
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
53befeb7
NJ
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
73be1d9e 17 */
3d527b27 18
dbb605f5
LC
19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#endif
22
9de87eea
MV
23#include <stdlib.h>
24#include "libguile/_scm.h"
3d527b27 25
9de87eea 26#if SCM_USE_NULL_THREADS
3d527b27 27
9de87eea 28#include "libguile/null-threads.h"
3d527b27 29
9de87eea 30static scm_i_pthread_key_t *all_keys = NULL;
3d527b27 31
9de87eea
MV
32static void
33destroy_keys (void)
3d527b27 34{
9de87eea
MV
35 scm_i_pthread_key_t *key;
36 int again;
4b9154e7 37
9de87eea
MV
38 do {
39 again = 0;
40 for (key = all_keys; key; key = key->next)
41 if (key->value && key->destr_func)
4b9154e7 42 {
9de87eea
MV
43 void *v = key->value;
44 key->value = NULL;
45 key->destr_func (v);
46 again = 1;
4b9154e7 47 }
9de87eea 48 } while (again);
3d527b27
MV
49}
50
9de87eea
MV
51int
52scm_i_pthread_key_create (scm_i_pthread_key_t *key,
53 void (*destr_func) (void *))
3d527b27 54{
9de87eea
MV
55 if (all_keys == NULL)
56 atexit (destroy_keys);
3d527b27 57
9de87eea
MV
58 key->next = all_keys;
59 all_keys = key;
60 key->value = NULL;
61 key->destr_func = destr_func;
4b9154e7 62
9de87eea 63 return 0;
3d527b27
MV
64}
65
9de87eea
MV
66#endif /* SCM_USE_NULL_THREADS */
67
3d527b27
MV
68
69/*
70 Local Variables:
71 c-file-style: "gnu"
72 End:
73*/