summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-06-24 06:38:52 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-06-24 06:38:52 +0000
commit2212a2adf9f760bd01ebaed18664569a302adc9b (patch)
tree22e0bc1c0f38ded2fc2093369d7b90dc9fafa6ff /cpukit/posix/src
parent2009-06-24 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-2212a2adf9f760bd01ebaed18664569a302adc9b.tar.bz2
2009-06-24 Joel Sherrill <joel.sherrill@oarcorp.com>
* posix/Makefile.am, posix/include/rtems/posix/priority.h, posix/include/rtems/posix/pthread.h, posix/inline/rtems/posix/priority.inl, posix/src/killinfo.c, posix/src/pthread.c, posix/src/pthreadcreate.c, posix/src/pthreadsetschedparam.c: Various modifications to improve binary code coverage analysis. Some of these are to mark code as debug only. Some are to break conditional expressions into multiple lines. Some are to move inline methods that are not time critical into subroutines to make them easier to test. Inlining them multiple times means that their logic paths are spread across multiple methods. This explodes the test cases required. * posix/src/psxpriorityisvalid.c, posix/src/psxtransschedparam.c: New files.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r--cpukit/posix/src/killinfo.c22
-rw-r--r--cpukit/posix/src/psxpriorityisvalid.c27
-rw-r--r--cpukit/posix/src/psxtransschedparam.c65
-rw-r--r--cpukit/posix/src/pthread.c9
-rw-r--r--cpukit/posix/src/pthreadcreate.c100
-rw-r--r--cpukit/posix/src/pthreadsetschedparam.c46
6 files changed, 153 insertions, 116 deletions
diff --git a/cpukit/posix/src/killinfo.c b/cpukit/posix/src/killinfo.c
index 2eb0441fc6..e44016d125 100644
--- a/cpukit/posix/src/killinfo.c
+++ b/cpukit/posix/src/killinfo.c
@@ -186,13 +186,15 @@ int killinfo(
the_info = _Objects_Information_table[ the_api ][ 1 ];
- /*
- * This cannot happen in the current (as of June 2009) implementation
- * of initialization but at some point, the object information
- * structure for a particular manager may not be installed.
- */
- if ( !the_info )
- continue;
+ #if defined(RTEMS_DEBUG)
+ /*
+ * This cannot happen in the current (as of June 2009) implementation
+ * of initialization but at some point, the object information
+ * structure for a particular manager may not be installed.
+ */
+ if ( !the_info )
+ continue;
+ #endif
maximum = the_info->maximum;
object_table = the_info->local_table;
@@ -217,8 +219,10 @@ int killinfo(
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
- if ( !api )
- continue;
+ #if defined(RTEMS_DEBUG)
+ if ( !api )
+ continue;
+ #endif
if ( !_POSIX_signals_Is_interested( api, mask ) )
continue;
diff --git a/cpukit/posix/src/psxpriorityisvalid.c b/cpukit/posix/src/psxpriorityisvalid.c
new file mode 100644
index 0000000000..4b35a81e62
--- /dev/null
+++ b/cpukit/posix/src/psxpriorityisvalid.c
@@ -0,0 +1,27 @@
+/*
+ * COPYRIGHT (c) 1989-2008.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/posix/priority.h>
+
+bool _POSIX_Priority_Is_valid(
+ int priority
+)
+{
+ return ((priority >= POSIX_SCHEDULER_MINIMUM_PRIORITY) &&
+ (priority <= POSIX_SCHEDULER_MAXIMUM_PRIORITY));
+
+}
+
diff --git a/cpukit/posix/src/psxtransschedparam.c b/cpukit/posix/src/psxtransschedparam.c
new file mode 100644
index 0000000000..8e91af75d4
--- /dev/null
+++ b/cpukit/posix/src/psxtransschedparam.c
@@ -0,0 +1,65 @@
+/* COPYRIGHT (c) 1989-2009.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/posix/pthread.h>
+#include <rtems/posix/priority.h>
+#include <rtems/posix/time.h>
+
+int _POSIX_Thread_Translate_sched_param(
+ int policy,
+ struct sched_param *param,
+ Thread_CPU_budget_algorithms *budget_algorithm,
+ Thread_CPU_budget_algorithm_callout *budget_callout
+)
+{
+ if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
+ return EINVAL;
+
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
+ *budget_callout = NULL;
+
+ switch ( policy ) {
+ case SCHED_OTHER:
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
+ break;
+
+ case SCHED_FIFO:
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
+ break;
+
+ case SCHED_RR:
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
+ break;
+
+ case SCHED_SPORADIC:
+ *budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
+ *budget_callout = _POSIX_Threads_Sporadic_budget_callout;
+
+ if ( _Timespec_To_ticks( &param->ss_replenish_period ) <
+ _Timespec_To_ticks( &param->ss_initial_budget ) )
+ return EINVAL;
+
+ if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
+ return EINVAL;
+ break;
+
+ default:
+ return EINVAL;
+ }
+ return 0;
+}
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index 72354ae49a..ae42dbe3fa 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -172,12 +172,17 @@ bool _POSIX_Threads_Create_extension(
/*
* If the thread is not a posix thread, then all posix signals are blocked
* by default.
+ *
+ * The check for class == 1 is debug. Should never really happen.
*/
/* XXX use signal constants */
api->signals_pending = 0;
- if ( _Objects_Get_API( created->Object.id ) == OBJECTS_POSIX_API &&
- _Objects_Get_class( created->Object.id ) == 1 ) {
+ if ( _Objects_Get_API( created->Object.id ) == OBJECTS_POSIX_API
+ #if defined(RTEMS_DEBUG)
+ && _Objects_Get_class( created->Object.id ) == 1
+ #endif
+ ) {
executing_api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
api->signals_blocked = executing_api->signals_blocked;
} else {
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 4ce8c2b2d1..b17da6b9ba 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -54,6 +54,7 @@ int pthread_create(
int schedpolicy = SCHED_RR;
struct sched_param schedparam;
Objects_Name name;
+ int rc;
if ( !start_routine )
return EFAULT;
@@ -73,10 +74,10 @@ int pthread_create(
if ( the_attr->stackaddr && !_Stack_Is_enough(the_attr->stacksize) )
return EINVAL;
-#if 0
- int cputime_clock_allowed; /* see time.h */
- rtems_set_errno_and_return_minus_one( ENOSYS );
-#endif
+ #if 0
+ int cputime_clock_allowed; /* see time.h */
+ rtems_set_errno_and_return_minus_one( ENOSYS );
+ #endif
/*
* P1003.1c/Draft 10, p. 121.
@@ -86,7 +87,6 @@ int pthread_create(
* PTHREAD_EXPLICIT_SCHED, then scheduling parameters come from the
* attributes structure.
*/
-
switch ( the_attr->inheritsched ) {
case PTHREAD_INHERIT_SCHED:
api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
@@ -107,14 +107,12 @@ int pthread_create(
* Check the contentionscope since rtems only supports PROCESS wide
* contention (i.e. no system wide contention).
*/
-
if ( the_attr->contentionscope != PTHREAD_SCOPE_PROCESS )
return ENOTSUP;
/*
* Interpret the scheduling parameters.
*/
-
if ( !_POSIX_Priority_Is_valid( schedparam.sched_priority ) )
return EINVAL;
@@ -123,51 +121,24 @@ int pthread_create(
/*
* Set the core scheduling policy information.
*/
-
- budget_callout = NULL;
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
-
- switch ( schedpolicy ) {
- case SCHED_OTHER:
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
- break;
-
- case SCHED_FIFO:
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
- break;
-
- case SCHED_RR:
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
- break;
-
- case SCHED_SPORADIC:
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
- budget_callout = _POSIX_Threads_Sporadic_budget_callout;
-
- if ( _Timespec_To_ticks( &schedparam.ss_replenish_period ) <
- _Timespec_To_ticks( &schedparam.ss_initial_budget ) )
- return EINVAL;
-
- if ( !_POSIX_Priority_Is_valid( schedparam.ss_low_priority ) )
- return EINVAL;
-
- break;
-
- default:
- return EINVAL;
- }
+ rc = _POSIX_Thread_Translate_sched_param(
+ schedpolicy,
+ &schedparam,
+ &budget_algorithm,
+ &budget_callout
+ );
+ if ( rc )
+ return rc;
/*
* Currently all POSIX threads are floating point if the hardware
* supports it.
*/
-
-
-#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
- is_fp = true;
-#else
- is_fp = false;
-#endif
+ #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
+ is_fp = true;
+ #else
+ is_fp = false;
+ #endif
/*
* Lock the allocator mutex for protection
@@ -179,9 +150,7 @@ int pthread_create(
*
* NOTE: Global threads are not currently supported.
*/
-
the_thread = _POSIX_Threads_Allocate();
-
if ( !the_thread ) {
_RTEMS_Unlock_allocator();
return EAGAIN;
@@ -190,7 +159,6 @@ int pthread_create(
/*
* Initialize the core thread for this task.
*/
-
name.name_p = NULL; /* posix threads don't have a name by default */
status = _Thread_Initialize(
&_POSIX_Threads_Information,
@@ -215,8 +183,6 @@ int pthread_create(
/*
* finish initializing the per API structure
*/
-
-
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
api->Attributes = *the_attr;
@@ -230,13 +196,11 @@ int pthread_create(
*
* NOTE: Since the thread starts with all unblocked, this is necessary.
*/
-
the_thread->do_post_task_switch_extension = true;
/*
* POSIX threads are allocated and started in one operation.
*/
-
status = _Thread_Start(
the_thread,
THREAD_START_POINTER,
@@ -245,6 +209,20 @@ int pthread_create(
0 /* unused */
);
+ #if defined(RTEMS_DEBUG)
+ /*
+ * _Thread_Start only fails if the thread was in the incorrect state
+ *
+ * NOTE: This can only happen if someone slips in and touches the
+ * thread while we are creating it.
+ */
+ if ( !status ) {
+ _POSIX_Threads_Free( the_thread );
+ _RTEMS_Unlock_allocator();
+ return EINVAL;
+ }
+ #endif
+
if ( schedpolicy == SCHED_SPORADIC ) {
_Watchdog_Insert_ticks(
&api->Sporadic_timer,
@@ -253,22 +231,8 @@ int pthread_create(
}
/*
- * _Thread_Start only fails if the thread was in the incorrect state
- *
- * NOTE: This can only happen if someone slips in and touches the
- * thread while we are creating it.
- */
-
- if ( !status ) {
- _POSIX_Threads_Free( the_thread );
- _RTEMS_Unlock_allocator();
- return EINVAL;
- }
-
- /*
* Return the id and indicate we successfully created the thread
*/
-
*thread = the_thread->Object.id;
_RTEMS_Unlock_allocator();
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index 8d5ffb1888..e95659f2db 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -36,54 +36,26 @@ int pthread_setschedparam(
Thread_CPU_budget_algorithms budget_algorithm;
Thread_CPU_budget_algorithm_callout budget_callout;
Objects_Locations location;
+ int rc;
/*
* Check all the parameters
*/
-
if ( !param )
return EINVAL;
- if ( !_POSIX_Priority_Is_valid( param->sched_priority ) )
- return EINVAL;
-
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
- budget_callout = NULL;
-
- switch ( policy ) {
- case SCHED_OTHER:
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
- break;
-
- case SCHED_FIFO:
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
- break;
-
- case SCHED_RR:
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
- break;
-
- case SCHED_SPORADIC:
- budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
- budget_callout = _POSIX_Threads_Sporadic_budget_callout;
-
- if ( _Timespec_To_ticks( &param->ss_replenish_period ) <
- _Timespec_To_ticks( &param->ss_initial_budget ) )
- return EINVAL;
-
- if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
- return EINVAL;
-
- break;
-
- default:
- return EINVAL;
- }
+ rc = _POSIX_Thread_Translate_sched_param(
+ policy,
+ param,
+ &budget_algorithm,
+ &budget_callout
+ );
+ if ( rc )
+ return rc;
/*
* Actually change the scheduling policy and parameters
*/
-
the_thread = _POSIX_Threads_Get( thread, &location );
switch ( location ) {