]>
Commit | Line | Data |
---|---|---|
9881cbf8 | 1 | /* Test for notification mechanism in lio_listio. |
04277e02 | 2 | Copyright (C) 2000-2019 Free Software Foundation, Inc. |
9881cbf8 AJ |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
9881cbf8 AJ |
9 | |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
9881cbf8 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
9881cbf8 AJ |
18 | |
19 | #include <aio.h> | |
20 | #include <signal.h> | |
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
23 | #include <unistd.h> | |
ffa8d2a0 | 24 | #include <errno.h> |
c39bc8b8 | 25 | #include <pthread.h> |
9881cbf8 | 26 | |
22347a8b | 27 | static pthread_barrier_t b; |
9881cbf8 AJ |
28 | |
29 | ||
de149cdb | 30 | static void |
9881cbf8 AJ |
31 | thrfct (sigval_t arg) |
32 | { | |
22347a8b UD |
33 | int e = pthread_barrier_wait (&b); |
34 | if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) | |
35 | { | |
36 | puts ("child: barrier_wait failed"); | |
37 | exit (1); | |
38 | } | |
9881cbf8 AJ |
39 | } |
40 | ||
41 | ||
de149cdb | 42 | static int |
9881cbf8 AJ |
43 | do_test (int argc, char *argv[]) |
44 | { | |
45 | char name[] = "/tmp/aio3.XXXXXX"; | |
46 | int fd; | |
47 | struct aiocb *arr[1]; | |
48 | struct aiocb cb; | |
49 | static const char buf[] = "Hello World\n"; | |
50 | ||
51 | fd = mkstemp (name); | |
52 | if (fd == -1) | |
53 | { | |
54 | printf ("cannot open temp name: %m\n"); | |
55 | return 1; | |
56 | } | |
57 | ||
58 | unlink (name); | |
59 | ||
22347a8b UD |
60 | if (pthread_barrier_init (&b, NULL, 2) != 0) |
61 | { | |
62 | puts ("barrier_init failed"); | |
63 | return 1; | |
64 | } | |
65 | ||
9881cbf8 AJ |
66 | arr[0] = &cb; |
67 | ||
68 | cb.aio_fildes = fd; | |
69 | cb.aio_lio_opcode = LIO_WRITE; | |
70 | cb.aio_reqprio = 0; | |
71 | cb.aio_buf = (void *) buf; | |
72 | cb.aio_nbytes = sizeof (buf) - 1; | |
636ccfc8 | 73 | cb.aio_offset = 0; |
9881cbf8 AJ |
74 | cb.aio_sigevent.sigev_notify = SIGEV_THREAD; |
75 | cb.aio_sigevent.sigev_notify_function = thrfct; | |
76 | cb.aio_sigevent.sigev_notify_attributes = NULL; | |
77 | cb.aio_sigevent.sigev_value.sival_ptr = NULL; | |
78 | ||
79 | if (lio_listio (LIO_NOWAIT, arr, 1, NULL) < 0) | |
80 | { | |
ffa8d2a0 RM |
81 | if (errno == ENOSYS) |
82 | { | |
83 | puts ("no aio support in this configuration"); | |
84 | return 0; | |
85 | } | |
9881cbf8 AJ |
86 | printf ("lio_listio failed: %m\n"); |
87 | return 1; | |
88 | } | |
89 | ||
90 | if (aio_suspend ((const struct aiocb *const *) arr, 1, NULL) < 0) | |
91 | { | |
92 | printf ("aio_suspend failed: %m\n"); | |
93 | return 1; | |
94 | } | |
de149cdb | 95 | |
22347a8b UD |
96 | int e = pthread_barrier_wait (&b); |
97 | if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) | |
9881cbf8 | 98 | { |
22347a8b | 99 | puts ("parent: barrier_wait failed"); |
9881cbf8 AJ |
100 | return 1; |
101 | } | |
102 | ||
103 | puts ("all OK"); | |
104 | ||
105 | return 0; | |
106 | } | |
107 | ||
108 | #include "../test-skeleton.c" |