Ticket #2514: 0001-RTEMS-Self-contained-POSIX-objects.patch

File 0001-RTEMS-Self-contained-POSIX-objects.patch, 5.7 KB (added by Sebastian Huber, on Oct 5, 2017 at 5:20:56 AM)
  • newlib/libc/sys/rtems/include/machine/_threads.h

    From c2ab263fee31fe05fa447be1714e529d0f220b9d Mon Sep 17 00:00:00 2001
    From: Sebastian Huber <sebastian.huber@embedded-brains.de>
    Date: Tue, 19 Sep 2017 15:08:35 +0200
    Subject: [PATCH] RTEMS: Self-contained POSIX objects
    
    RTEMS: Optimize pthread_once_t
    
    Reduce size of pthread_once_t and make it zero-initialized.
    
    Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
    
    RTEMS: Make sem_t self-contained
    
    Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
    
    RTEMS: Make pthread_barrier_t self-contained
    
    Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
    
    RTEMS: Make pthread_rwlock_t self-contained
    
    Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
    
    RTEMS: Make pthread_cond_t self-contained
    
    Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
    
    RTEMS: Make pthread_mutex_t self-contained
    
    Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
    ---
     newlib/libc/sys/rtems/include/machine/_threads.h  |  5 +-
     newlib/libc/sys/rtems/include/semaphore.h         |  8 ++-
     newlib/libc/sys/rtems/include/sys/_pthreadtypes.h | 63 +++++++++++++++++++----
     3 files changed, 60 insertions(+), 16 deletions(-)
    
    diff --git a/newlib/libc/sys/rtems/include/machine/_threads.h b/newlib/libc/sys/rtems/include/machine/_threads.h
    index 24db21c0e..5faa78f46 100644
    a b typedef __uint32_t tss_t; 
    4141
    4242/* pthread_once_t */
    4343typedef struct {
    44         int     _is_initialized;
    45         int     _init_executed;
     44        unsigned char _flags;
    4645} once_flag;
    4746
    4847/* PTHREAD_ONCE_INIT */
    49 #define ONCE_FLAG_INIT { 1, 0 }
     48#define ONCE_FLAG_INIT { 0 }
    5049
    5150/* PTHREAD_DESTRUCTOR_ITERATIONS */
    5251#define TSS_DTOR_ITERATIONS 4
  • newlib/libc/sys/rtems/include/semaphore.h

    diff --git a/newlib/libc/sys/rtems/include/semaphore.h b/newlib/libc/sys/rtems/include/semaphore.h
    index e3c61da04..44ecc58f4 100644
    a b  
    2424 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    2525 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2626 *
    27  * $FreeBSD$
     27 * $FreeBSD: head/include/semaphore.h 314424 2017-02-28 21:47:00Z vangyzen $
    2828 */
    2929
    3030/* semaphore.h: POSIX 1003.1b semaphores */
     
    3333#define _SEMAPHORE_H_
    3434
    3535#include <sys/cdefs.h>
     36#include <sys/lock.h>
    3637#include <sys/_types.h>
    3738#include <sys/_timespec.h>
    3839
    39 typedef __uint32_t      sem_t;
     40typedef struct {
     41        unsigned long _flags;
     42        struct _Semaphore_Control _Semaphore;
     43} sem_t;
    4044
    4145#define SEM_FAILED      ((sem_t *)0)
    4246
  • newlib/libc/sys/rtems/include/sys/_pthreadtypes.h

    diff --git a/newlib/libc/sys/rtems/include/sys/_pthreadtypes.h b/newlib/libc/sys/rtems/include/sys/_pthreadtypes.h
    index bd66c689e..b091ebbaf 100644
    a b typedef struct { 
    131131
    132132#endif /* !defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES) */
    133133
    134 typedef __uint32_t pthread_mutex_t;      /* identify a mutex */
     134struct _Chain_Node {
     135  struct _Chain_Node *_next;
     136  struct _Chain_Node *_previous;
     137};
     138
     139struct _RBTree_Node {
     140  struct _RBTree_Node *_left;
     141  struct _RBTree_Node *_right;
     142  struct _RBTree_Node *_parent;
     143  int _color;
     144};
     145
     146struct _Priority_Node {
     147  union {
     148    struct _RBTree_Node _RBTree;
     149    struct _Chain_Node _Chain;
     150  } _Node;
     151  __uint64_t _priority;
     152};
    135153
    136 #define _PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) 0xFFFFFFFF)
     154typedef struct {
     155  unsigned long _flags;
     156  struct _Mutex_recursive_Control _Recursive;
     157  struct _Priority_Node _Priority_ceiling;
     158  const struct _Scheduler_Control *_scheduler;
     159} pthread_mutex_t;
     160
     161#define _PTHREAD_MUTEX_INITIALIZER \
     162  { 0, _MUTEX_RECURSIVE_INITIALIZER, { { 0, 0, 0, 0 }, 0 }, 0 }
    137163
    138164typedef struct {
    139165  int   is_initialized;
    typedef struct { 
    152178
    153179/* Condition Variables */
    154180
    155 typedef __uint32_t pthread_cond_t;       /* identify a condition variable */
     181typedef struct {
     182  unsigned long _flags;
     183  struct _Thread_queue_Queue _Queue;
     184  pthread_mutex_t *_mutex;
     185} pthread_cond_t;
    156186
    157 #define _PTHREAD_COND_INITIALIZER ((pthread_cond_t) 0xFFFFFFFF)
     187#define _PTHREAD_COND_INITIALIZER { 0, _THREAD_QUEUE_INITIALIZER, 0 }
    158188
    159189typedef struct {
    160190  int      is_initialized;
    typedef struct { 
    169199typedef __uint32_t pthread_key_t;        /* thread-specific data keys */
    170200
    171201typedef struct {
    172   int   is_initialized;  /* is this structure initialized? */
    173   int   init_executed;   /* has the initialization routine been run? */
    174 } pthread_once_t;       /* dynamic package initialization */
     202  unsigned char _flags;
     203} pthread_once_t;
     204
     205#define _PTHREAD_ONCE_INIT { 0 }
    175206
    176 #define _PTHREAD_ONCE_INIT  { 1, 0 }  /* is initialized and not run */
    177207#endif /* defined(_POSIX_THREADS) */
    178208
    179209/* POSIX Barrier Types */
    180210
    181211#if defined(_POSIX_BARRIERS)
    182 typedef __uint32_t pthread_barrier_t;        /* POSIX Barrier Object */
     212typedef struct {
     213  unsigned long _flags;
     214  struct _Thread_queue_Queue _Queue;
     215  unsigned int _count;
     216  unsigned int _waiting_threads;
     217} pthread_barrier_t;
     218
    183219typedef struct {
    184220  int   is_initialized;  /* is this structure initialized? */
    185221#if defined(_POSIX_THREAD_PROCESS_SHARED)
    typedef struct { 
    200236/* POSIX Reader/Writer Lock Types */
    201237
    202238#if defined(_POSIX_READER_WRITER_LOCKS)
    203 typedef __uint32_t pthread_rwlock_t;         /* POSIX RWLock Object */
     239typedef struct {
     240  unsigned long _flags;
     241  struct _Thread_queue_Queue _Queue;
     242  unsigned int _current_state;
     243  unsigned int _number_of_readers;
     244} pthread_rwlock_t;
    204245
    205 #define _PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) 0xFFFFFFFF)
     246#define _PTHREAD_RWLOCK_INITIALIZER { 0, _THREAD_QUEUE_INITIALIZER, 0, 0 }
    206247
    207248typedef struct {
    208249  int   is_initialized;       /* is this structure initialized? */