Changeset 6e4c01e in rtems


Ignore:
Timestamp:
Aug 23, 2013, 4:56:36 AM (6 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11, master
Children:
38ec8af
Parents:
c9b66f5
Message:

posix: Update to the pthread_once changes.

Implement the reeview changes.
Add a POSIX Fatal error domain.
Fix confdefs.h to correctly handle the internal POSIX mutexes.

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/posix/include/rtems/posix/posixapi.h

    rc9b66f5 r6e4c01e  
    11/**
    22 * @file
    3  * 
     3 *
    44 * @brief POSIX API Implementation
    55 *
     
    3030 */
    3131/**@{**/
     32
     33/**
     34 * @brief POSIX API Fatal domains.
     35 */
     36typedef enum {
     37  POSIX_FD_PTHREAD,      /**< A pthread thread error. */
     38  POSIX_FD_PTHREAD_ONCE  /**< A pthread once error. */
     39} POSIX_Fatal_domain;
     40
     41/**
     42 * @brief POSIX API Fatal error.
     43 *
     44 * A common method of rasing a POSIX API fatal error.
     45 *
     46 * @param[in] domain The POSIX error domain.
     47 * @param[in] eno The error number as defined in errno.h.
     48 */
     49void _POSIX_Fatal_error( POSIX_Fatal_domain domain, int eno );
    3250
    3351/**
  • cpukit/posix/src/once.c

    rc9b66f5 r6e4c01e  
    2323
    2424#include <rtems.h>
     25#include <rtems/posix/posixapi.h>
    2526#include <rtems/posix/onceimpl.h>
    26 
    27 pthread_mutex_t _POSIX_Once_Lock;
    2827
    2928void _POSIX_Once_Manager_initialization(void)
    3029{
    3130  pthread_mutexattr_t mattr;
    32   int r;
     31  int eno;
    3332
    3433  _POSIX_Once_Lock = PTHREAD_MUTEX_INITIALIZER;
    3534
    36   r = pthread_mutexattr_init( &mattr );
    37   if ( r != 0 )
    38     rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, 0x80aa0000 | r );
     35  eno = pthread_mutexattr_init( &mattr );
     36  _Assert( eno == 0 );
     37  eno = pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_RECURSIVE );
     38  _Assert( eno == 0 );
    3939
    40   r = pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_RECURSIVE );
    41    if ( r != 0 )
    42     rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, 0x80aa1000 | r );
     40  eno = pthread_mutex_init( &_POSIX_Once_Lock, &mattr );
     41  if ( eno != 0 )
     42    _POSIX_Fatal_error( POSIX_FD_PTHREAD_ONCE, eno );
    4343
    44   r = pthread_mutex_init( &_POSIX_Once_Lock, &mattr );
    45   if ( r != 0 )
    46     rtems_fatal( RTEMS_FATAL_SOURCE_ASSERT, 0x80aa2000 | r );
    47 
    48   pthread_mutexattr_destroy( &mattr );
     44  eno = pthread_mutexattr_destroy( &mattr );
     45  _Assert( eno == 0 );
    4946}
  • cpukit/posix/src/pthreadinitthreads.c

    rc9b66f5 r6e4c01e  
    3030#include <rtems/score/wkspace.h>
    3131#include <rtems/posix/cancel.h>
     32#include <rtems/posix/posixapi.h>
    3233#include <rtems/posix/pthreadimpl.h>
    3334#include <rtems/posix/priorityimpl.h>
     
    3738void _POSIX_Threads_Initialize_user_threads_body(void)
    3839{
    39   int                                 status;
     40  int                                 eno;
    4041  uint32_t                            index;
    4142  uint32_t                            maximum;
     
    6162     * There is no way for these calls to fail in this situation.
    6263     */
    63     (void) pthread_attr_init( &attr );
    64     (void) pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
    65     (void) pthread_attr_setstacksize(&attr, user_threads[ index ].stack_size);
     64    eno = pthread_attr_init( &attr );
     65    _Assert( eno == 0 );
     66    eno = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
     67    _Assert( eno == 0 );
     68    eno = pthread_attr_setstacksize(&attr, user_threads[ index ].stack_size);
     69    _Assert( eno == 0 );
    6670
    67     status = pthread_create(
     71    eno = pthread_create(
    6872      &thread_id,
    6973      &attr,
     
    7175      NULL
    7276    );
    73     if ( status )
    74       _Internal_error_Occurred( INTERNAL_ERROR_POSIX_API, true, status );
     77    if ( eno )
     78      _POSIX_Fatal_error( POSIX_FD_PTHREAD, eno );
    7579  }
    7680}
    77 
  • cpukit/posix/src/pthreadonce.c

    rc9b66f5 r6e4c01e  
    3030#define PTHREAD_ONCE_INIT_NOT_RUN  0
    3131#define PTHREAD_ONCE_INIT_RUNNING  1
    32 #define PTHREAD_ONCE_INIT_RUN      2
     32#define PTHREAD_ONCE_INIT_COMPLETE 2
    3333
    3434int pthread_once(
     
    4545    return EINVAL;
    4646
    47   if ( once_control->init_executed != PTHREAD_ONCE_INIT_RUN ) {
     47  if ( once_control->init_executed != PTHREAD_ONCE_INIT_COMPLETE ) {
    4848    r = pthread_mutex_lock( &_POSIX_Once_Lock );
    4949    if ( r == 0 ) {
     
    6262          once_control->init_executed = PTHREAD_ONCE_INIT_RUNNING;
    6363          (*init_routine)();
    64           once_control->init_executed = PTHREAD_ONCE_INIT_RUN;
     64          once_control->init_executed = PTHREAD_ONCE_INIT_COMPLETE;
    6565          break;
    6666        case PTHREAD_ONCE_INIT_RUNNING:
  • cpukit/sapi/include/confdefs.h

    rc9b66f5 r6e4c01e  
    955955
    956956/**
     957 * Zero of one returns 0 if the parameter is 0 else 1 is returned.
     958 */
     959#define _Configure_Zero_or_One(_number) ((_number) ? 1 : 0)
     960
     961/**
    957962 * This is a helper macro used in calculations in this file.  It is used
    958963 * to noted when an element is allocated from the RTEMS Workspace and adds
     
    961966 */
    962967#define _Configure_From_workspace(_size) \
    963   (ssize_t)((_size) + HEAP_BLOCK_HEADER_SIZE + CPU_HEAP_ALIGNMENT - 1)
     968   (ssize_t) (_Configure_Zero_or_One(_size) * \
     969     ((_size) + HEAP_BLOCK_HEADER_SIZE + CPU_HEAP_ALIGNMENT - 1))
    964970
    965971/**
     
    981987 */
    982988#define _Configure_Max_Objects(_max) \
    983   rtems_resource_maximum_per_allocation(_max)
     989  (_Configure_Zero_or_One(_max) * rtems_resource_maximum_per_allocation(_max))
    984990
    985991/**
     
    993999  ( _Configure_From_workspace(_Configure_Max_Objects(_number) * (_size)) + \
    9941000    _Configure_From_workspace( \
    995       ((_Configure_Max_Objects(_number) + 1) * sizeof(Objects_Control *)) + \
    996       (sizeof(void *) + sizeof(uint32_t) + sizeof(Objects_Name *)) \
     1001      (_Configure_Zero_or_One(_number) * \
     1002       (_Configure_Max_Objects(_number) + 1) * sizeof(Objects_Control *)) + \
     1003      (_Configure_Zero_or_One(_number) * \
     1004       (sizeof(void *) + sizeof(uint32_t) + sizeof(Objects_Name *))) \
    9971005    ) \
    9981006  )
     
    17311739
    17321740  #ifndef CONFIGURE_MAXIMUM_POSIX_THREADS
    1733     #define CONFIGURE_MAXIMUM_POSIX_THREADS      0
     1741    #define CONFIGURE_MAXIMUM_POSIX_THREADS 0
    17341742  #endif
    17351743
     
    17381746
    17391747  #ifndef CONFIGURE_MAXIMUM_POSIX_MUTEXES
    1740     #define CONFIGURE_MAXIMUM_POSIX_MUTEXES              0
    1741     #define CONFIGURE_MEMORY_FOR_POSIX_MUTEXES(_mutexes) 0
    1742   #else
    1743     #define CONFIGURE_MEMORY_FOR_POSIX_MUTEXES(_mutexes) \
    1744       _Configure_Object_RAM(_mutexes, sizeof(POSIX_Mutex_Control) )
    1745   #endif
     1748    #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 0
     1749  #endif
     1750  #define CONFIGURE_MEMORY_FOR_POSIX_MUTEXES(_mutexes) \
     1751    _Configure_Object_RAM(_mutexes, sizeof(POSIX_Mutex_Control) )
    17461752
    17471753  #ifndef CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES
    1748     #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES               0
    1749     #define CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(_condvars) 0
    1750   #else
    1751     #define CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(_condvars) \
    1752         _Configure_Object_RAM(_condvars, \
    1753                             sizeof(POSIX_Condition_variables_Control) )
    1754   #endif
     1754    #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 0
     1755  #endif
     1756  #define CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(_condvars) \
     1757      _Configure_Object_RAM(_condvars, \
     1758                          sizeof(POSIX_Condition_variables_Control) )
    17551759
    17561760  #ifndef CONFIGURE_MAXIMUM_POSIX_KEYS
    1757     #define CONFIGURE_MAXIMUM_POSIX_KEYS           0
    1758     #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS      0
    1759     #define CONFIGURE_MEMORY_FOR_POSIX_KEYS(_keys, _key_value_pairs) 0
     1761    #define CONFIGURE_MAXIMUM_POSIX_KEYS            0
     1762    #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 0
    17601763  #else
    17611764    #ifndef CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS
     
    17641767        * (CONFIGURE_MAXIMUM_POSIX_THREADS + CONFIGURE_MAXIMUM_TASKS)
    17651768    #endif
    1766   #define CONFIGURE_MEMORY_FOR_POSIX_KEYS(_keys, _key_value_pairs)       \
    1767       (_Configure_Object_RAM(_keys, sizeof(POSIX_Keys_Control) ) \
    1768   + _Configure_From_workspace(_key_value_pairs * sizeof(POSIX_Keys_Key_value_pair)))
    1769   #endif
     1769  #endif
     1770  #define CONFIGURE_MEMORY_FOR_POSIX_KEYS(_keys, _key_value_pairs) \
     1771     (_Configure_Object_RAM(_keys, sizeof(POSIX_Keys_Control) ) \
     1772      + _Configure_From_workspace(_key_value_pairs * sizeof(POSIX_Keys_Key_value_pair)))
    17701773
    17711774  #ifndef CONFIGURE_MAXIMUM_POSIX_TIMERS
    1772     #define CONFIGURE_MAXIMUM_POSIX_TIMERS             0
    1773     #define CONFIGURE_MEMORY_FOR_POSIX_TIMERS(_timers) 0
    1774   #else
    1775     #define CONFIGURE_MEMORY_FOR_POSIX_TIMERS(_timers) \
    1776       _Configure_Object_RAM(_timers, sizeof(POSIX_Timer_Control) )
    1777   #endif
     1775    #define CONFIGURE_MAXIMUM_POSIX_TIMERS 0
     1776  #endif
     1777  #define CONFIGURE_MEMORY_FOR_POSIX_TIMERS(_timers) \
     1778    _Configure_Object_RAM(_timers, sizeof(POSIX_Timer_Control) )
    17781779
    17791780  #ifndef CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS
    1780     #define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS                     0
    1781     #define CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS(_queued_signals) 0
    1782   #else
    1783     #define CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS(_queued_signals) \
    1784       _Configure_From_workspace( \
    1785         (_queued_signals) * (sizeof(POSIX_signals_Siginfo_node)) )
    1786   #endif
     1781    #define CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS 0
     1782  #endif
     1783  #define CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS(_queued_signals) \
     1784    _Configure_From_workspace( \
     1785      (_queued_signals) * (sizeof(POSIX_signals_Siginfo_node)) )
    17871786
    17881787  #ifndef CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES
    17891788    #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES                     0
    1790     #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES(_message_queues) 0
    17911789    #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS          0
    1792     #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUE_DESCRIPTORS(_fds) 0
    1793   #else
    1794     #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES(_message_queues) \
    1795       _Configure_POSIX_Named_Object_RAM( \
    1796          _message_queues, sizeof(POSIX_Message_queue_Control) )
    1797 
     1790  #else
    17981791    /* default to same number */
    17991792    #ifndef CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS
     
    18011794               CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES
    18021795    #endif
    1803 
    1804     #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUE_DESCRIPTORS(_mqueue_fds) \
    1805       _Configure_Object_RAM( \
    1806          _mqueue_fds, sizeof(POSIX_Message_queue_Control_fd) )
    1807   #endif
     1796  #endif
     1797
     1798  #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES(_message_queues) \
     1799    _Configure_POSIX_Named_Object_RAM( \
     1800       _message_queues, sizeof(POSIX_Message_queue_Control) )
     1801
     1802  #define CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUE_DESCRIPTORS(_mqueue_fds) \
     1803    _Configure_Object_RAM( \
     1804       _mqueue_fds, sizeof(POSIX_Message_queue_Control_fd) )
    18081805
    18091806  #ifndef CONFIGURE_MAXIMUM_POSIX_SEMAPHORES
    1810     #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES                 0
    1811     #define CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES(_semaphores) 0
    1812   #else
    1813     #define CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES(_semaphores) \
    1814       _Configure_POSIX_Named_Object_RAM( \
    1815          _semaphores, sizeof(POSIX_Semaphore_Control) )
    1816   #endif
     1807    #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 0
     1808  #endif
     1809  #define CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES(_semaphores) \
     1810    _Configure_POSIX_Named_Object_RAM( \
     1811       _semaphores, sizeof(POSIX_Semaphore_Control) )
    18171812
    18181813  #ifndef CONFIGURE_MAXIMUM_POSIX_BARRIERS
    1819     #define CONFIGURE_MAXIMUM_POSIX_BARRIERS               0
    1820     #define CONFIGURE_MEMORY_FOR_POSIX_BARRIERS(_barriers) 0
    1821   #else
    1822     #define CONFIGURE_MEMORY_FOR_POSIX_BARRIERS(_barriers) \
    1823       _Configure_Object_RAM(_barriers, sizeof(POSIX_Barrier_Control) )
    1824   #endif
     1814    #define CONFIGURE_MAXIMUM_POSIX_BARRIERS 0
     1815  #endif
     1816  #define CONFIGURE_MEMORY_FOR_POSIX_BARRIERS(_barriers) \
     1817    _Configure_Object_RAM(_barriers, sizeof(POSIX_Barrier_Control) )
    18251818
    18261819  #ifndef CONFIGURE_MAXIMUM_POSIX_SPINLOCKS
    1827     #define CONFIGURE_MAXIMUM_POSIX_SPINLOCKS                0
    1828     #define CONFIGURE_MEMORY_FOR_POSIX_SPINLOCKS(_spinlocks) 0
    1829   #else
    1830     #define CONFIGURE_MEMORY_FOR_POSIX_SPINLOCKS(_spinlocks) \
    1831       _Configure_Object_RAM(_spinlocks, sizeof(POSIX_Spinlock_Control) )
    1832   #endif
     1820    #define CONFIGURE_MAXIMUM_POSIX_SPINLOCKS 0
     1821  #endif
     1822  #define CONFIGURE_MEMORY_FOR_POSIX_SPINLOCKS(_spinlocks) \
     1823    _Configure_Object_RAM(_spinlocks, sizeof(POSIX_Spinlock_Control) )
    18331824
    18341825  #ifndef CONFIGURE_MAXIMUM_POSIX_RWLOCKS
    1835     #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS              0
    1836     #define CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS(_rwlocks) 0
    1837   #else
    1838     #define CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS(_rwlocks) \
    1839       _Configure_Object_RAM(_rwlocks, sizeof(POSIX_RWLock_Control) )
    1840   #endif
     1826    #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 0
     1827  #endif
     1828  #define CONFIGURE_MEMORY_FOR_POSIX_RWLOCKS(_rwlocks) \
     1829    _Configure_Object_RAM(_rwlocks, sizeof(POSIX_RWLock_Control) )
    18411830
    18421831  #ifdef CONFIGURE_POSIX_INIT_THREAD_TABLE
     
    25792568    /* POSIX API Pieces */
    25802569    CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( CONFIGURE_MAXIMUM_POSIX_MUTEXES +
     2570      CONFIGURE_MAXIMUM_POSIX_INTERNAL_MUTEXES +
    25812571      CONFIGURE_MAXIMUM_GO_CHANNELS + CONFIGURE_GO_INIT_MUTEXES),
    25822572    CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(
  • cpukit/sapi/src/posixapi.c

    rc9b66f5 r6e4c01e  
    4545#include <rtems/posix/time.h>
    4646
     47void _POSIX_Fatal_error( POSIX_Fatal_domain domain, int eno )
     48{
     49  uint32_t code = ( domain << 8 ) | ( ( uint32_t ) eno & 0xffU );
     50
     51  _Internal_error_Occurred( INTERNAL_ERROR_POSIX_API, false, code );
     52}
     53
    4754Objects_Information *_POSIX_Objects[ OBJECTS_POSIX_CLASSES_LAST + 1 ];
    4855
  • testsuites/psxtests/psx01/init.c

    rc9b66f5 r6e4c01e  
    2020
    2121#include <rtems/score/todimpl.h>
     22
     23pthread_once_t nesting_once = PTHREAD_ONCE_INIT;
     24
     25void Test_init_routine_nesting( void );
     26
     27void Test_init_routine_nesting( void )
     28{
     29  int status;
     30  puts( "Test_init_routine_nesting: invoked" );
     31  status = pthread_once( &nesting_once, Test_init_routine_nesting );
     32  rtems_test_assert( status == EINVAL );
     33}
    2234
    2335void *POSIX_Init(
     
    96108  rtems_test_assert( !status );
    97109
     110  /* once nesting */
     111  puts( "Init: pthread_once - SUCCESSFUL (init_routine_nesting executes)" );
     112  status = pthread_once( &nesting_once, Test_init_routine_nesting );
     113  rtems_test_assert( !status );
     114
    98115  /* create a thread */
    99116
  • testsuites/psxtests/psxconfig01/init.c

    rc9b66f5 r6e4c01e  
    163163  (MQ_BUFFER_MEMORY + POSIX_MQ_BUFFER_MEMORY)
    164164
     165#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
     166#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
     167
     168#define CONFIGURE_MAXIMUM_DRIVERS 2
     169
     170#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
     171
     172#define CONFIGURE_INIT
     173
     174static rtems_task Init(rtems_task_argument argument);
     175
     176#include <rtems/confdefs.h>
     177
    165178typedef struct {
    166179  uint64_t data [16];
     
    470483  rtems_resource_snapshot_take(&snapshot);
    471484  rtems_test_assert(
    472     snapshot.posix_api.active_mutexes == CONFIGURE_MAXIMUM_POSIX_MUTEXES
     485    snapshot.posix_api.active_mutexes ==
     486    (CONFIGURE_MAXIMUM_POSIX_MUTEXES + CONFIGURE_MAXIMUM_POSIX_INTERNAL_MUTEXES)
    473487  );
    474488#endif
     
    544558  rtems_test_exit(0);
    545559}
    546 
    547 #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
    548 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
    549 
    550 #define CONFIGURE_MAXIMUM_DRIVERS 2
    551 
    552 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    553 
    554 #define CONFIGURE_INIT
    555 
    556 #include <rtems/confdefs.h>
Note: See TracChangeset for help on using the changeset viewer.