summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-11 10:58:59 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-12 13:24:41 +0200
commite135271b933c896068a343b161773ce3b685be43 (patch)
tree83faf308498a9695ba551f8e5b3f7473daa37d68 /cpukit/posix/src
parentscore: Use thread state lock for current state (diff)
downloadrtems-e135271b933c896068a343b161773ce3b685be43.tar.bz2
score: Avoid Giant lock _Scheduler_Set_affinity()
Update #2555.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r--cpukit/posix/src/pthreadcreate.c8
-rw-r--r--cpukit/posix/src/pthreadsetaffinitynp.c59
2 files changed, 36 insertions, 31 deletions
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 2533345ff6..eedb80e203 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -74,7 +74,7 @@ int pthread_create(
struct sched_param schedparam;
Objects_Name name;
int rc;
- ISR_Level level;
+ ISR_lock_Context lock_context;
if ( !start_routine )
return EFAULT;
@@ -202,11 +202,13 @@ int pthread_create(
}
#if defined(RTEMS_SMP) && __RTEMS_HAVE_SYS_CPUSET_H__
+ _ISR_lock_ISR_disable( &lock_context );
status = _Scheduler_Set_affinity(
the_thread,
the_attr->affinitysetsize,
the_attr->affinityset
);
+ _ISR_lock_ISR_enable( &lock_context );
if ( !status ) {
_POSIX_Threads_Free( the_thread );
_RTEMS_Unlock_allocator();
@@ -247,13 +249,13 @@ int pthread_create(
#endif
if ( schedpolicy == SCHED_SPORADIC ) {
- _ISR_Disable_without_giant( level );
+ _ISR_lock_ISR_disable( &lock_context );
_Watchdog_Per_CPU_insert_relative(
&api->Sporadic_timer,
_Per_CPU_Get(),
_Timespec_To_ticks( &api->schedparam.sched_ss_repl_period )
);
- _ISR_Enable_without_giant( level );
+ _ISR_lock_ISR_enable( &lock_context );
}
_Thread_Enable_dispatch();
diff --git a/cpukit/posix/src/pthreadsetaffinitynp.c b/cpukit/posix/src/pthreadsetaffinitynp.c
index 711d6dcaeb..6dd8bce224 100644
--- a/cpukit/posix/src/pthreadsetaffinitynp.c
+++ b/cpukit/posix/src/pthreadsetaffinitynp.c
@@ -31,41 +31,44 @@
#include <rtems/score/schedulerimpl.h>
int pthread_setaffinity_np(
- pthread_t id,
- size_t cpusetsize,
- const cpu_set_t *cpuset)
+ pthread_t thread,
+ size_t cpusetsize,
+ const cpu_set_t *cpuset
+)
{
- Objects_Locations location;
- POSIX_API_Control *api;
- Thread_Control *the_thread;
- bool ok;
+ Thread_Control *the_thread;
+ ISR_lock_Context lock_context;
+ Per_CPU_Control *cpu_self;
+ bool ok;
- if ( !cpuset )
+ if ( cpuset == NULL ) {
return EFAULT;
+ }
- the_thread = _Thread_Get( id, &location );
- switch ( location ) {
+ the_thread = _Thread_Get_interrupt_disable( thread, &lock_context );
- case OBJECTS_LOCAL:
- ok = _Scheduler_Set_affinity(
- the_thread,
- cpusetsize,
- cpuset
- );
- if ( ok ) {
- api = the_thread->API_Extensions[ THREAD_API_POSIX ];
- CPU_COPY( api->Attributes.affinityset, cpuset );
- }
- _Objects_Put( &the_thread->Object );
- return ok ? 0 : EINVAL;
+ if ( the_thread == NULL ) {
+ return ESRCH;
+ }
-#if defined(RTEMS_MULTIPROCESSING)
- case OBJECTS_REMOTE:
-#endif
- case OBJECTS_ERROR:
- break;
+ cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
+ _Thread_State_acquire_critical( the_thread, &lock_context );
+
+ ok = _Scheduler_Set_affinity(
+ the_thread,
+ cpusetsize,
+ cpuset
+ );
+
+ if ( ok ) {
+ POSIX_API_Control *api;
+
+ api = the_thread->API_Extensions[ THREAD_API_POSIX ];
+ CPU_COPY( api->Attributes.affinityset, cpuset );
}
- return ESRCH;
+ _Thread_State_release( the_thread, &lock_context );
+ _Thread_Dispatch_enable( cpu_self );
+ return ok ? 0 : EINVAL;
}
#endif