Skip to content

Commit

Permalink
dont use cpu_set_t in API, see #988
Browse files Browse the repository at this point in the history
  • Loading branch information
tornaria committed Jan 29, 2022
1 parent a7c49ad commit 73633a7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
10 changes: 1 addition & 9 deletions thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
#ifndef THREAD_POOL_H
#define THREAD_POOL_H

/* for some reason this define needs to be outside of the next if */
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#if FLINT_USES_CPUSET
#include <sched.h>
#endif

#include "flint.h"

#if FLINT_USES_PTHREAD
Expand Down Expand Up @@ -52,7 +44,7 @@ typedef thread_pool_entry_struct thread_pool_entry_t[1];
typedef struct
{
#if FLINT_USES_CPUSET && FLINT_USES_PTHREAD
cpu_set_t original_affinity;
void * original_affinity;
#endif
#if FLINT_USES_PTHREAD
pthread_mutex_t mutex;
Expand Down
6 changes: 6 additions & 0 deletions thread_pool/clear.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void thread_pool_clear(thread_pool_t T)
{
flint_free(D);
}
#if FLINT_USES_CPUSET && FLINT_USES_PTHREAD
if (T->original_affinity != NULL) {
flint_free(T->original_affinity);
T->original_affinity = NULL;
}
#endif
#if FLINT_USES_PTHREAD
pthread_mutex_unlock(&T->mutex);
pthread_mutex_destroy(&T->mutex);
Expand Down
8 changes: 6 additions & 2 deletions thread_pool/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#define _GNU_SOURCE
#include <sched.h>

#include "thread_pool.h"

thread_pool_t global_thread_pool;
Expand Down Expand Up @@ -73,10 +76,11 @@ void thread_pool_init(thread_pool_t T, slong size)
T->length = size;

#if FLINT_USES_CPUSET && FLINT_USES_PTHREAD
T->original_affinity = flint_malloc(sizeof(cpu_set_t));
if (0 != pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t),
&T->original_affinity))
(cpu_set_t *)T->original_affinity))
{
CPU_ZERO(&T->original_affinity);
CPU_ZERO((cpu_set_t *)T->original_affinity);
}
#endif

Expand Down
7 changes: 5 additions & 2 deletions thread_pool/restore_affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#define _GNU_SOURCE
#include <sched.h>

#include "thread_pool.h"

int thread_pool_restore_affinity(thread_pool_t T)
Expand All @@ -23,14 +26,14 @@ int thread_pool_restore_affinity(thread_pool_t T)
for (i = 0; i < T->length; i++)
{
errorno = pthread_setaffinity_np(D[i].pth, sizeof(cpu_set_t),
&T->original_affinity);
(cpu_set_t *)T->original_affinity);
if (errorno != 0)
return errorno;
}

/* restore affinity for main thread */
errorno = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t),
&T->original_affinity);
(cpu_set_t *)T->original_affinity);
if (errorno != 0)
return errorno;
#endif
Expand Down
3 changes: 3 additions & 0 deletions thread_pool/set_affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#define _GNU_SOURCE
#include <sched.h>

#include "thread_pool.h"

/*
Expand Down

0 comments on commit 73633a7

Please sign in to comment.