1 /* 2 Copyright (C) 2019 Daniel Schultz 3 4 This file is part of FLINT. 5 6 FLINT is free software: you can redistribute it and/or modify it under 7 the terms of the GNU Lesser General Public License (LGPL) as published 8 by the Free Software Foundation; either version 2.1 of the License, or 9 (at your option) any later version. See <https://www.gnu.org/licenses/>. 10 */ 11 12 #include "thread_pool.h" 13 thread_pool_restore_affinity(thread_pool_t T)14int thread_pool_restore_affinity(thread_pool_t T) 15 { 16 #if FLINT_USES_CPUSET && FLINT_USES_PTHREAD 17 slong i; 18 int errorno; 19 thread_pool_entry_struct * D; 20 21 /* restore affinities for workers */ 22 D = T->tdata; 23 for (i = 0; i < T->length; i++) 24 { 25 errorno = pthread_setaffinity_np(D[i].pth, sizeof(cpu_set_t), 26 &T->original_affinity); 27 if (errorno != 0) 28 return errorno; 29 } 30 31 /* restore affinity for main thread */ 32 errorno = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), 33 &T->original_affinity); 34 if (errorno != 0) 35 return errorno; 36 #endif 37 38 return 0; 39 } 40