1 /* ath-pth.c - Pth module for self-adapting thread-safeness library
2 * Copyright (C) 2002 g10 Code GmbH
3 * Copyright (C) 2002 Free Software Foundation, Inc.
5 * This file is part of Libgcrypt.
7 * Libgcrypt is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
12 * Libgcrypt is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
28 #pragma weak pth_mutex_init
29 #pragma weak pth_mutex_acquire
30 #pragma weak pth_mutex_release
32 #pragma weak pth_write
33 #pragma weak pth_select
34 #pragma weak pth_waitpid
36 /* The lock we take while checking for lazy lock initialization. */
37 static pth_mutex_t check_init_lock = PTH_MUTEX_INIT;
39 /* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if
40 it is not already initialized. */
42 mutex_pth_init (void **priv, int just_check)
47 pth_mutex_acquire (&check_init_lock, 0, NULL);
48 if (!*priv || !just_check)
50 pth_mutex_t *lock = malloc (sizeof (pth_mutex_t));
55 err = pth_mutex_init (lock);
68 pth_mutex_release (&check_init_lock);
74 mutex_pth_destroy (void *priv)
82 mutex_pth_lock (void *priv)
84 int ret = pth_mutex_acquire ((pth_mutex_t *) priv, 0, NULL);
85 return ret == FALSE ? errno : 0;
90 mutex_pth_unlock (void *priv)
92 int ret = pth_mutex_release ((pth_mutex_t *) priv);
93 return ret == FALSE ? errno : 0;
97 static struct ath_ops ath_pth_ops =
111 ath_pth_available (void)
113 if (pth_mutex_init && pth_mutex_acquire && pth_mutex_release
114 && pth_read && pth_write && pth_select && pth_waitpid)