Don't redefine ETIMEDOUT on Solaris.
[gnulib.git] / lib / glthread / cond.c
1 /* Condition variables for multithreading.
2    Copyright (C) 2008 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Yoann Vandoorselaere <yoann@prelude-ids.org>, 2008.  */
19
20 #include <config.h>
21
22 #include "glthread/cond.h"
23
24 /* ========================================================================= */
25
26 #if USE_PTH_THREADS
27
28 /* -------------------------- gl_cond_t datatype -------------------------- */
29
30 int
31 glthread_cond_timedwait_multithreaded (gl_cond_t *cond,
32                                        gl_lock_t *lock,
33                                        struct timespec *abstime)
34 {
35   int ret, status;
36   pth_event_t ev;
37
38   ev = pth_event (PTH_EVENT_TIME, pth_time (abstime->tv_sec, abstime->tv_nsec / 1000));
39   ret = pth_cond_await (cond, lock, ev);
40
41   status = pth_event_status (ev);
42   pth_event_free (ev, PTH_FREE_THIS);
43
44   if (status == PTH_STATUS_OCCURRED)
45     return ETIMEDOUT;
46
47   return ret;
48 }
49
50 #endif
51
52 /* ========================================================================= */
53
54 #if USE_SOLARIS_THREADS
55
56 /* -------------------------- gl_cond_t datatype -------------------------- */
57
58 int
59 glthread_cond_timedwait_multithreaded (gl_cond_t *cond,
60                                        gl_lock_t *lock,
61                                        struct timespec *abstime)
62 {
63   int ret;
64
65   ret = cond_timedwait (cond, lock, abstime);
66   if (ret == ETIME)
67     return ETIMEDOUT;
68   return ret;
69 }
70
71 #endif
72
73 /* ========================================================================= */