[PATCH 07/10] posix: Move affinity from thread to scheduler.
Jennifer
jennifer.averett at oarcorp.com
Mon Mar 24 18:39:38 UTC 2014
From: Jennifer Averett <jennifer.averett at oarcorp.com>
---
cpukit/posix/src/pthreadcreate.c | 14 ++++++++++++--
cpukit/posix/src/pthreadgetaffinitynp.c | 12 +++++-------
cpukit/posix/src/pthreadsetaffinitynp.c | 8 ++++++--
3 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 5a6d929..075a092 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -32,6 +32,8 @@
#include <rtems/score/apimutex.h>
#include <rtems/score/stackimpl.h>
#include <rtems/score/watchdogimpl.h>
+#include <rtems/score/schedulerimpl.h>
+
static inline size_t _POSIX_Threads_Ensure_minimum_stack (
size_t size
@@ -196,8 +198,16 @@ int pthread_create(
#if defined(RTEMS_SMP)
#if __RTEMS_HAVE_SYS_CPUSET_H__
- the_thread->affinity.setsize = the_attr->affinitysetsize;
- *the_thread->affinity.set = *the_attr->affinityset;
+ rc = _Scheduler_Set_affinity(
+ the_thread,
+ attr->affinitysetsize,
+ attr->affinityset
+ );
+ if ( rc != 0 ) {
+ _POSIX_Threads_Free( the_thread );
+ _RTEMS_Unlock_allocator();
+ return EINVAL;
+ }
#endif
#endif
diff --git a/cpukit/posix/src/pthreadgetaffinitynp.c b/cpukit/posix/src/pthreadgetaffinitynp.c
index 082e41a..fd61af5 100644
--- a/cpukit/posix/src/pthreadgetaffinitynp.c
+++ b/cpukit/posix/src/pthreadgetaffinitynp.c
@@ -28,6 +28,7 @@
#include <rtems/posix/pthreadimpl.h>
#include <rtems/posix/priorityimpl.h>
#include <rtems/score/threadimpl.h>
+#include <rtems/score/schedulerimpl.h>
int pthread_getaffinity_np(
const pthread_t id,
@@ -46,14 +47,11 @@ int pthread_getaffinity_np(
switch ( location ) {
case OBJECTS_LOCAL:
- error = 0;
- if ( cpusetsize != the_thread->affinity.setsize )
- error = EINVAL;
- else
- CPU_COPY( cpuset, the_thread->affinity.set );
-
+ error = _Scheduler_Get_affinity( the_thread, cpusetsize, cpuset );
_Objects_Put( &the_thread->Object );
- return error;
+ if (error)
+ return EINVAL;
+ return 0;
break;
#if defined(RTEMS_MULTIPROCESSING)
diff --git a/cpukit/posix/src/pthreadsetaffinitynp.c b/cpukit/posix/src/pthreadsetaffinitynp.c
index fc2194d..51aaee9 100644
--- a/cpukit/posix/src/pthreadsetaffinitynp.c
+++ b/cpukit/posix/src/pthreadsetaffinitynp.c
@@ -28,6 +28,7 @@
#include <rtems/posix/priorityimpl.h>
#include <rtems/score/threadimpl.h>
#include <rtems/score/cpusetimpl.h>
+#include <rtems/score/schedulerimpl.h>
int pthread_setaffinity_np(
pthread_t id,
@@ -51,9 +52,12 @@ int pthread_setaffinity_np(
case OBJECTS_LOCAL:
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
- CPU_COPY( the_thread->affinity.set, cpuset );
- CPU_COPY( api->Attributes.affinityset, cpuset );
+ error = _Scheduler_Set_affinity( the_thread, cpusetsize, cpuset );
+ if (!error)
+ CPU_COPY( api->Attributes.affinityset, cpuset );
_Objects_Put( &the_thread->Object );
+ if (error)
+ return EINVAL;
return 0;
break;
--
1.8.1.4
More information about the devel
mailing list