Skip to content

Commit

Permalink
score: Add thread queue for self-contained objects
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhub committed Jul 30, 2015
1 parent 0e3c59d commit 12f93fb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpukit/configure.ac
Expand Up @@ -71,6 +71,7 @@ AC_CHECK_DECLS([ftrylockfile],[AC_CHECK_FUNCS([ftrylockfile])],,[#include <stdio
AC_CHECK_HEADERS([envlock.h])
AC_CHECK_DECLS([__env_lock],,,[#include <envlock.h>])
AC_CHECK_DECLS([__env_unlock],,,[#include <envlock.h>])
AC_CHECK_TYPES([struct _Thread_queue_Queue],[],[],[#include <sys/lock.h>])

# Mandated by POSIX, older newlibs bogusly provided CLOCK_PROCESS_CPUTIME+CLOCK_THREAD_CPUTIME
AC_CHECK_DECL([CLOCK_PROCESS_CPUTIME_ID],[],[AC_MSG_ERROR([missing define CLOCK_PROCESS_CPUTIME_ID])],[#include <time.h>])
Expand Down
18 changes: 18 additions & 0 deletions cpukit/score/include/rtems/score/threadqimpl.h
Expand Up @@ -33,6 +33,24 @@ extern "C" {
*/
/**@{*/

/**
* @brief Thread queue with a layout compatible to struct _Thread_queue_Queue
* defined in Newlib <sys/lock.h>.
*/
typedef struct {
Thread_queue_Queue Queue;

#if !defined(RTEMS_SMP)
/*
* The struct _Thread_queue_Queue definition is independent of the RTEMS
* build configuration. Thus, the storage space for the SMP lock is always
* present. In SMP configurations, the SMP lock is contained in the
* Thread_queue_Queue.
*/
unsigned int reserved[2];
#endif
} Thread_queue_Syslock_queue;

RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_initialize(
Thread_queue_Queue *queue
)
Expand Down
36 changes: 36 additions & 0 deletions cpukit/score/src/threadq.c
Expand Up @@ -22,6 +22,42 @@
#include <rtems/score/rbtreeimpl.h>
#include <rtems/score/threadimpl.h>

#if HAVE_STRUCT__THREAD_QUEUE_QUEUE

RTEMS_STATIC_ASSERT(
offsetof( Thread_queue_Syslock_queue, Queue.heads )
== offsetof( struct _Thread_queue_Queue, _heads ),
THREAD_QUEUE_SYSLOCK_QUEUE_HEADS
);

RTEMS_STATIC_ASSERT(
#if defined(RTEMS_SMP)
offsetof( Thread_queue_Syslock_queue, Queue.Lock.next_ticket )
#else
offsetof( Thread_queue_Syslock_queue, reserved[ 0 ] )
#endif
== offsetof( struct _Thread_queue_Queue, _Lock._next_ticket ),
THREAD_QUEUE_SYSLOCK_QUEUE_NEXT_TICKET
);

RTEMS_STATIC_ASSERT(
#if defined(RTEMS_SMP)
offsetof( Thread_queue_Syslock_queue, Queue.Lock.now_serving )
#else
offsetof( Thread_queue_Syslock_queue, reserved[ 1 ] )
#endif
== offsetof( struct _Thread_queue_Queue, _Lock._now_serving ),
THREAD_QUEUE_SYSLOCK_QUEUE_NOW_SERVING
);

RTEMS_STATIC_ASSERT(
sizeof( Thread_queue_Syslock_queue )
== sizeof( struct _Thread_queue_Queue ),
THREAD_QUEUE_SYSLOCK_QUEUE_SIZE
);

#endif /* HAVE_STRUCT__THREAD_QUEUE_QUEUE */

RBTree_Compare_result _Thread_queue_Compare_priority(
const RBTree_Node *left,
const RBTree_Node *right
Expand Down

0 comments on commit 12f93fb

Please sign in to comment.