1 /* ath-pth.c - Pth module for self-adapting thread-safeness library
2 * Copyright (C) 2002 g10 Code GmbH
4 * This file is part of GPGME.
6 * GPGME is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GPGME is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
27 #pragma weak pth_mutex_init
28 #pragma weak pth_mutex_acquire
29 #pragma weak pth_mutex_release
31 #pragma weak pth_write
32 #pragma weak pth_select
33 #pragma weak pth_waitpid
34 #pragma weak pth_accept
35 #pragma weak pth_connect
37 /* The lock we take while checking for lazy lock initialization. */
38 static pth_mutex_t check_init_lock = PTH_MUTEX_INIT;
40 /* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if
41 it is not already initialized. */
43 mutex_pth_init (void **priv, int just_check)
48 pth_mutex_acquire (&check_init_lock, 0, NULL);
49 if (!*priv || !just_check)
51 pth_mutex_t *lock = malloc (sizeof (pth_mutex_t));
56 err = pth_mutex_init (lock);
69 pth_mutex_release (&check_init_lock);
75 mutex_pth_destroy (void *priv)
83 mutex_pth_lock (void *priv)
85 int ret = pth_mutex_acquire ((pth_mutex_t *) priv, 0, NULL);
86 return ret == FALSE ? errno : 0;
91 mutex_pth_unlock (void *priv)
93 int ret = pth_mutex_release ((pth_mutex_t *) priv);
94 return ret == FALSE ? errno : 0;
98 static struct ath_ops ath_pth_ops =
110 NULL, /* FIXME: When GNU PTh has sendmsg. */
111 NULL /* FIXME: When GNU PTh has recvmsg. */
116 ath_pth_available (void)
118 if (pth_mutex_init && pth_mutex_acquire && pth_mutex_release
119 && pth_read && pth_write && pth_select && pth_waitpid)