Files
rtems/testsuites/sptests/spthreadq01/init.c
Sebastian Huber 91e7b0c5ae score: PR2172: _Thread_queue_Extract()
Add _Thread_queue_Extract_with_return_code().  On SMP this sequence in
_Thread_queue_Process_timeout() was broken:

[...]
      /*
       * After we enable interrupts here, a lot may happen in the
       * meantime, e.g. nested interrupts may release the resource that
       * times out here.  So we enter _Thread_queue_Extract()
       * speculatively.  Inside this function we check the actual status
       * under ISR disable protection.  This ensures that exactly one
       * executing context performs the extract operation (other parties
       * may call _Thread_queue_Dequeue()).  If this context won, then
       * we have a timeout.
       *
       * We can use the_thread_queue pointer here even if
       * the_thread->Wait.queue is already set to NULL since the extract
       * operation will only use the thread queue discipline to select
       * the right extract operation.  The timeout status is set during
       * thread queue initialization.
       */
      we_did_it = _Thread_queue_Extract( the_thread_queue, the_thread );
      if ( we_did_it ) {
        the_thread->Wait.return_code = the_thread_queue->timeout_status;
      }
[...]

In case _Thread_queue_Extract() successfully extracted a thread, then
this thread may start execution on a remote processor immediately and
read the the_thread->Wait.return_code before we update it here with the
timeout status.  Thus it observes a successful operation even if it
timed out.
2014-04-01 14:10:22 +02:00

72 lines
1.7 KiB
C

/*
* 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.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tmacros.h>
#include <sys/types.h>
#include <rtems/score/threadqimpl.h>
const char rtems_test_name[] = "SPTHREADQ 1";
/* forward declarations to avoid warnings */
rtems_task Init(rtems_task_argument argument);
void threadq_first_empty(
const char *discipline_string,
Thread_queue_Disciplines discipline
);
void threadq_first_empty(
const char *discipline_string,
Thread_queue_Disciplines discipline
)
{
Thread_queue_Control tq;
printf( "Init - initialize thread queue for %s\n", discipline_string );
_Thread_queue_Initialize( &tq, discipline, 0x01, 3 );
puts( "Init - _Thread_queue_Extract - thread not blocked on a thread queue" );
_Thread_Disable_dispatch();
_Thread_queue_Extract( &tq, _Thread_Executing );
_Thread_Enable_dispatch();
/* is there more to check? */
}
rtems_task Init(
rtems_task_argument ignored
)
{
TEST_BEGIN();
threadq_first_empty( "FIFO", THREAD_QUEUE_DISCIPLINE_FIFO );
threadq_first_empty( "Priority", THREAD_QUEUE_DISCIPLINE_PRIORITY );
TEST_END();
rtems_test_exit(0);
}
/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 1
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
/* global variables */