Changeset f14a04c6 in rtems


Ignore:
Timestamp:
Nov 24, 2017, 5:38:07 AM (2 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
1b2da177
Parents:
8fa4549
git-author:
Sebastian Huber <sebastian.huber@…> (11/24/17 05:38:07)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/02/18 14:01:20)
Message:

Add RTEMS thread API

Update #2843.

Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/headers.am

    r8fa4549 rf14a04c6  
    211211include_rtems_HEADERS += include/rtems/termiostypes.h
    212212include_rtems_HEADERS += include/rtems/test.h
     213include_rtems_HEADERS += include/rtems/thread.h
    213214include_rtems_HEADERS += include/rtems/timecounter.h
    214215include_rtems_HEADERS += include/rtems/timespec.h
  • cpukit/score/src/semaphore.c

    r8fa4549 rf14a04c6  
    11/*
    2  * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2015, 2017 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    1919#include <rtems/score/semaphoreimpl.h>
    2020#include <rtems/score/statesimpl.h>
     21#include <rtems/score/threadimpl.h>
    2122
    22 #include <limits.h>
     23#include <errno.h>
    2324
    2425RTEMS_STATIC_ASSERT(
     
    7273}
    7374
     75int _Semaphore_Wait_timed_ticks( struct _Semaphore_Control *_sem, uint32_t ticks )
     76{
     77  Sem_Control          *sem;
     78  ISR_Level             level;
     79  Thread_queue_Context  queue_context;
     80  Thread_Control       *executing;
     81  unsigned int          count;
     82
     83  sem = _Sem_Get( _sem );
     84  _Thread_queue_Context_initialize( &queue_context );
     85  _Thread_queue_Context_ISR_disable( &queue_context, level );
     86  executing = _Sem_Queue_acquire_critical( sem, &queue_context );
     87
     88  count = sem->count;
     89  if ( __predict_true( count > 0 ) ) {
     90    sem->count = count - 1;
     91    _Sem_Queue_release( sem, level, &queue_context );
     92    return 0;
     93  } else {
     94    _Thread_queue_Context_set_thread_state(
     95      &queue_context,
     96      STATES_WAITING_FOR_SEMAPHORE
     97    );
     98    _Thread_queue_Context_set_enqueue_timeout_ticks( &queue_context, ticks );
     99    _Thread_queue_Context_set_ISR_level( &queue_context, level );
     100    _Thread_queue_Enqueue(
     101      &sem->Queue.Queue,
     102      SEMAPHORE_TQ_OPERATIONS,
     103      executing,
     104      &queue_context
     105    );
     106    return STATUS_GET_POSIX( _Thread_Wait_get_status( executing ) );
     107  }
     108}
     109
     110int _Semaphore_Try_wait( struct _Semaphore_Control *_sem )
     111{
     112  Sem_Control          *sem;
     113  ISR_Level             level;
     114  Thread_queue_Context  queue_context;
     115  unsigned int          count;
     116  int                   eno;
     117
     118  sem = _Sem_Get( _sem );
     119  _Thread_queue_Context_initialize( &queue_context );
     120  _Thread_queue_Context_ISR_disable( &queue_context, level );
     121  _Sem_Queue_acquire_critical( sem, &queue_context );
     122
     123  count = sem->count;
     124  if ( __predict_true( count > 0 ) ) {
     125    sem->count = count - 1;
     126    eno = 0;
     127  } else {
     128    eno = EAGAIN;
     129  }
     130
     131  _Sem_Queue_release( sem, level, &queue_context );
     132  return eno;
     133}
     134
    74135void _Semaphore_Post( struct _Semaphore_Control *_sem )
    75136{
     
    86147  heads = sem->Queue.Queue.heads;
    87148  if ( __predict_true( heads == NULL ) ) {
    88     _Assert( sem->count < UINT_MAX );
    89149    ++sem->count;
    90150    _Sem_Queue_release( sem, level, &queue_context );
     
    105165  }
    106166}
     167
     168void _Semaphore_Post_binary( struct _Semaphore_Control *_sem )
     169{
     170  Sem_Control          *sem;
     171  ISR_Level             level;
     172  Thread_queue_Context  queue_context;
     173  Thread_queue_Heads   *heads;
     174
     175  sem = _Sem_Get( _sem );
     176  _Thread_queue_Context_initialize( &queue_context );
     177  _Thread_queue_Context_ISR_disable( &queue_context, level );
     178  _Sem_Queue_acquire_critical( sem, &queue_context );
     179
     180  heads = sem->Queue.Queue.heads;
     181  if ( __predict_true( heads == NULL ) ) {
     182    sem->count = 1;
     183    _Sem_Queue_release( sem, level, &queue_context );
     184  } else {
     185    const Thread_queue_Operations *operations;
     186    Thread_Control *first;
     187
     188    _Thread_queue_Context_set_ISR_level( &queue_context, level );
     189    operations = SEMAPHORE_TQ_OPERATIONS;
     190    first = ( *operations->first )( heads );
     191
     192    _Thread_queue_Extract_critical(
     193      &sem->Queue.Queue,
     194      operations,
     195      first,
     196      &queue_context
     197    );
     198  }
     199}
  • testsuites/sptests/Makefile.am

    r8fa4549 rf14a04c6  
    3434    spsem_err02 sptask_err01 spevent_err03 sptask_err03 sptask_err02 \
    3535    sptask_err04 spclock_err01
     36_SUBDIRS += spthread01
    3637_SUBDIRS += spconsole01
    3738_SUBDIRS += spintrcritical24
  • testsuites/sptests/configure.ac

    r8fa4549 rf14a04c6  
    3939# Explicitly list all Makefiles here
    4040AC_CONFIG_FILES([Makefile
     41spthread01/Makefile
    4142sptls04/Makefile
    4243spconsole01/Makefile
Note: See TracChangeset for help on using the changeset viewer.