~ubuntu-branches/ubuntu/lucid/gpgme1.0/lucid

« back to all changes in this revision

Viewing changes to gpgme/ath-pthread.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman, Bhavani Shankar, Scott Kitterman
  • Date: 2008-12-31 02:39:33 UTC
  • mfrom: (1.1.6 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081231023933-zi5r2w9vf7fdz0x9
Tags: 1.1.8-1ubuntu1
[ Bhavani Shankar ]
* Merge from debian unstable, remaining changes: LP: #311666
  - debian/rules: enable tests

[ Scott Kitterman ]
* Re-enable testsuite on armel since it's no longer a first build 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ath-pthread.c - pthread module for self-adapting thread-safeness library
2
 
   Copyright (C) 2002, 2003, 2004 g10 Code GmbH
3
 
 
4
 
   This file is part of GPGME.
5
 
 
6
 
   GPGME is free software; you can redistribute it and/or modify it
7
 
   under the terms of the GNU Lesser General Public License as
8
 
   published by the Free Software Foundation; either version 2.1 of
9
 
   the License, or (at your option) any later version.
10
 
   
11
 
   GPGME is distributed in the hope that it will be useful, but
12
 
   WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
   Lesser General Public License for more details.
15
 
   
16
 
   You should have received a copy of the GNU Lesser General Public
17
 
   License along with this program; if not, write to the Free Software
18
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
 
   02111-1307, USA.  */
20
 
 
21
 
#ifdef HAVE_CONFIG_H
22
 
#include <config.h>
23
 
#endif
24
 
 
25
 
#include <stdlib.h>
26
 
#include <errno.h>
27
 
#include <unistd.h>
28
 
#ifdef HAVE_SYS_SELECT_H
29
 
# include <sys/select.h>
30
 
#else
31
 
# include <sys/time.h>
32
 
#endif
33
 
#include <sys/types.h>
34
 
#include <sys/wait.h>
35
 
 
36
 
#include <pthread.h>
37
 
 
38
 
#include "ath.h"
39
 
 
40
 
 
41
 
/* The lock we take while checking for lazy lock initialization.  */
42
 
static pthread_mutex_t check_init_lock = PTHREAD_MUTEX_INITIALIZER;
43
 
 
44
 
/* Initialize the mutex *PRIV.  If JUST_CHECK is true, only do this if
45
 
   it is not already initialized.  */
46
 
static int
47
 
mutex_pthread_init (ath_mutex_t *priv, int just_check)
48
 
{
49
 
  int err = 0;
50
 
 
51
 
  if (just_check)
52
 
    pthread_mutex_lock (&check_init_lock);
53
 
  if (!*priv || !just_check)
54
 
    {
55
 
      pthread_mutex_t *lock = malloc (sizeof (pthread_mutex_t));
56
 
      if (!lock)
57
 
        err = ENOMEM;
58
 
      if (!err)
59
 
        {
60
 
          err = pthread_mutex_init (lock, NULL);
61
 
          if (err)
62
 
            free (lock);
63
 
          else
64
 
            *priv = (ath_mutex_t) lock;
65
 
        }
66
 
    }
67
 
  if (just_check)
68
 
    pthread_mutex_unlock (&check_init_lock);
69
 
  return err;
70
 
}
71
 
 
72
 
 
73
 
void
74
 
ath_init (void)
75
 
{
76
 
  /* Nothing to do.  */
77
 
}
78
 
 
79
 
 
80
 
int
81
 
ath_mutex_init (ath_mutex_t *lock)
82
 
{
83
 
  return mutex_pthread_init (lock, 0);
84
 
}
85
 
 
86
 
 
87
 
int
88
 
ath_mutex_destroy (ath_mutex_t *lock)
89
 
{
90
 
  int err = mutex_pthread_init (lock, 1);
91
 
  if (!err)
92
 
    {
93
 
      err = pthread_mutex_destroy ((pthread_mutex_t *) *lock);
94
 
      free (*lock);
95
 
    }
96
 
  return err;
97
 
}
98
 
 
99
 
 
100
 
int
101
 
ath_mutex_lock (ath_mutex_t *lock)
102
 
{
103
 
  int ret = mutex_pthread_init (lock, 1);
104
 
  if (ret)
105
 
    return ret;
106
 
 
107
 
  return pthread_mutex_lock ((pthread_mutex_t *) *lock);
108
 
}
109
 
 
110
 
 
111
 
int
112
 
ath_mutex_unlock (ath_mutex_t *lock)
113
 
{
114
 
  int ret = mutex_pthread_init (lock, 1);
115
 
  if (ret)
116
 
    return ret;
117
 
 
118
 
  return pthread_mutex_unlock ((pthread_mutex_t *) *lock);
119
 
}
120
 
 
121
 
 
122
 
ssize_t
123
 
ath_read (int fd, void *buf, size_t nbytes)
124
 
{
125
 
  return read (fd, buf, nbytes);
126
 
}
127
 
 
128
 
 
129
 
ssize_t
130
 
ath_write (int fd, const void *buf, size_t nbytes)
131
 
{
132
 
  return write (fd, buf, nbytes);
133
 
}
134
 
 
135
 
 
136
 
ssize_t
137
 
ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset,
138
 
            struct timeval *timeout)
139
 
{
140
 
  return select (nfd, rset, wset, eset, timeout);
141
 
}
142
 
 
143
 
 
144
 
ssize_t
145
 
ath_waitpid (pid_t pid, int *status, int options)
146
 
{
147
 
  return waitpid (pid, status, options);
148
 
}
149
 
 
150
 
 
151
 
int
152
 
ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr)
153
 
{
154
 
  return accept (s, addr, length_ptr);
155
 
}
156
 
 
157
 
 
158
 
int
159
 
ath_connect (int s, const struct sockaddr *addr, socklen_t length)
160
 
{
161
 
  return connect (s, addr, length);
162
 
}
163
 
 
164
 
int
165
 
ath_sendmsg (int s, const struct msghdr *msg, int flags)
166
 
{
167
 
  return sendmsg (s, msg, flags);
168
 
}
169
 
 
170
 
 
171
 
int
172
 
ath_recvmsg (int s, struct msghdr *msg, int flags)
173
 
{
174
 
  return recvmsg (s, msg, flags);
175
 
}