From e045fb6c60a495aafd2ced0fd756862a66e98ce3 Mon Sep 17 00:00:00 2001 From: Jennifer Averett Date: Wed, 19 Mar 2014 15:21:15 -0500 Subject: posix: Move affinity from thread to scheduler. --- cpukit/posix/src/pthreadattrsetaffinitynp.c | 3 +-- cpukit/posix/src/pthreadcreate.c | 18 ++++++++++++++---- cpukit/posix/src/pthreadgetaffinitynp.c | 14 ++++++-------- cpukit/posix/src/pthreadsetaffinitynp.c | 14 +++++++------- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/cpukit/posix/src/pthreadattrsetaffinitynp.c b/cpukit/posix/src/pthreadattrsetaffinitynp.c index 66811f101a..b880e5a514 100644 --- a/cpukit/posix/src/pthreadattrsetaffinitynp.c +++ b/cpukit/posix/src/pthreadattrsetaffinitynp.c @@ -42,8 +42,7 @@ int pthread_attr_setaffinity_np( if ( !attr ) return EFAULT; - error = _CPU_set_Is_valid( cpuset, cpusetsize ); - if ( error != 0 ) + if (! _CPU_set_Is_valid( cpuset, cpusetsize ) ) return EINVAL; CPU_COPY( attr->affinityset, cpuset ); diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c index 8d031335cc..8db6948830 100644 --- a/cpukit/posix/src/pthreadcreate.c +++ b/cpukit/posix/src/pthreadcreate.c @@ -32,6 +32,8 @@ #include #include #include +#include + static inline size_t _POSIX_Threads_Ensure_minimum_stack ( size_t size @@ -139,8 +141,8 @@ int pthread_create( #if defined(RTEMS_SMP) #if __RTEMS_HAVE_SYS_CPUSET_H__ - rc = _CPU_set_Is_valid( the_attr->affinityset, the_attr->affinitysetsize ); - if ( rc != 0 ) + status = _CPU_set_Is_valid( the_attr->affinityset, the_attr->affinitysetsize ); + if (!status ) return EINVAL; #endif #endif @@ -191,8 +193,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; + status = _Scheduler_Set_affinity( + the_thread, + attr->affinitysetsize, + attr->affinityset + ); + if ( !status ) { + _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 082e41adbd..497236f60f 100644 --- a/cpukit/posix/src/pthreadgetaffinitynp.c +++ b/cpukit/posix/src/pthreadgetaffinitynp.c @@ -28,6 +28,7 @@ #include #include #include +#include int pthread_getaffinity_np( const pthread_t id, @@ -37,7 +38,7 @@ int pthread_getaffinity_np( { Objects_Locations location; Thread_Control *the_thread; - int error; + bool ok; if ( !cpuset ) return EFAULT; @@ -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 ); - + ok = _Scheduler_Get_affinity( the_thread, cpusetsize, cpuset ); _Objects_Put( &the_thread->Object ); - return error; + if (!ok) + return EINVAL; + return 0; break; #if defined(RTEMS_MULTIPROCESSING) diff --git a/cpukit/posix/src/pthreadsetaffinitynp.c b/cpukit/posix/src/pthreadsetaffinitynp.c index fc2194db30..d150b409a1 100644 --- a/cpukit/posix/src/pthreadsetaffinitynp.c +++ b/cpukit/posix/src/pthreadsetaffinitynp.c @@ -28,6 +28,7 @@ #include #include #include +#include int pthread_setaffinity_np( pthread_t id, @@ -37,23 +38,22 @@ int pthread_setaffinity_np( Objects_Locations location; POSIX_API_Control *api; Thread_Control *the_thread; - int error; + bool ok; if ( !cpuset ) return EFAULT; - error = _CPU_set_Is_valid( cpuset, cpusetsize ); - if ( error != 0 ) - return EINVAL; - the_thread = _Thread_Get( id, &location ); switch ( location ) { case OBJECTS_LOCAL: api = the_thread->API_Extensions[ THREAD_API_POSIX ]; - CPU_COPY( the_thread->affinity.set, cpuset ); - CPU_COPY( api->Attributes.affinityset, cpuset ); + ok = _Scheduler_Set_affinity( the_thread, cpusetsize, cpuset ); + if (ok) + CPU_COPY( api->Attributes.affinityset, cpuset ); _Objects_Put( &the_thread->Object ); + if (!ok) + return EINVAL; return 0; break; -- cgit v1.2.3