1 /* Block a thread with a timeout. Mach version.
2 Copyright (C) 2000-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
25 #include <mach/message.h>
27 #include <pt-internal.h>
30 # define MSG_OPTIONS 0
35 __pthread_timedblock (struct __pthread
*thread
,
36 const struct timespec
*abstime
, clockid_t clock_id
)
39 mach_msg_header_t msg
;
40 mach_msg_timeout_t timeout
;
43 /* We have an absolute time and now we have to convert it to a
44 relative time. Arg. */
46 err
= __clock_gettime (clock_id
, &now
);
49 if (now
.tv_sec
> abstime
->tv_sec
50 || (now
.tv_sec
== abstime
->tv_sec
&& now
.tv_nsec
> abstime
->tv_nsec
))
53 timeout
= (abstime
->tv_sec
- now
.tv_sec
) * 1000;
55 if (abstime
->tv_nsec
>= now
.tv_nsec
)
56 timeout
+= (abstime
->tv_nsec
- now
.tv_nsec
+ 999999) / 1000000;
58 /* Need to do a carry. */
59 timeout
-= (now
.tv_nsec
- abstime
->tv_nsec
+ 999999) / 1000000;
61 err
= __mach_msg (&msg
, MACH_RCV_MSG
| MACH_RCV_TIMEOUT
| MSG_OPTIONS
, 0,
62 sizeof msg
, thread
->wakeupmsg
.msgh_remote_port
,
63 timeout
, MACH_PORT_NULL
);
64 if (err
== EMACH_RCV_TIMED_OUT
)
66 if ((MSG_OPTIONS
& MACH_RCV_INTERRUPT
) && err
== MACH_RCV_INTERRUPTED
)