1 /* Separate thread test for pthread_getaffinity_np, pthread_setaffinity_np.
2 Copyright (C) 2015-2023 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 /* Defined for the benefit of tst-skeleton-thread-affinity.c, included
26 below. This variant runs the functions on a separate thread. */
28 struct affinity_access_task
38 affinity_access_thread (void *closure
)
40 struct affinity_access_task
*task
= closure
;
42 task
->result
= pthread_getaffinity_np
43 (task
->thread
, task
->size
, task
->set
);
45 task
->result
= pthread_setaffinity_np
46 (task
->thread
, task
->size
, task
->set
);
51 run_affinity_access_thread (cpu_set_t
*set
, size_t size
, bool get
)
53 struct affinity_access_task task
=
55 .thread
= pthread_self (),
61 int ret
= pthread_create (&thr
, NULL
, affinity_access_thread
, &task
);
65 printf ("error: could not create affinity access thread: %m\n");
68 ret
= pthread_join (thr
, NULL
);
72 printf ("error: could not join affinity access thread: %m\n");
84 setaffinity (size_t size
, const cpu_set_t
*set
)
86 return run_affinity_access_thread ((cpu_set_t
*) set
, size
, false);
90 getaffinity (size_t size
, cpu_set_t
*set
)
92 return run_affinity_access_thread (set
, size
, true);
95 #include "tst-skeleton-thread-affinity.c"