Changeset 1404


Ignore:
Timestamp:
Apr 29, 2004, 6:33:48 AM (21 years ago)
Author:
bird
Message:

#967: rewrote to use the LIBC TLS API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gcc/gcc/gthr-os2.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1403 r1404  
    3030#define __gthr_os2_h
    3131
    32 /* The __MT__ symbol should be defined for multiple threads (-Zmt) */
    33 #ifdef __MT__
     32#ifdef _LIBOBJC
     33#error "gthr-os2.h doesn't implement the _LIBOBJC mode!"
     34#endif
    3435
    3536#define __GTHREADS 1
     
    4142#include <malloc.h>
    4243#include <stdlib.h>
     44#include <errno.h>
     45#include <InnoTekLIBC/thread.h>
    4346
    44 typedef struct
    45 {
    46   void *thread_data;
    47   void (*thread_dtor) (void *);
    48 } __gthread_key_struct_t;
    49 
    50 typedef __gthread_key_struct_t *__gthread_key_t;
     47typedef int __gthread_key_t;
    5148typedef volatile signed char __gthread_once_t;
    5249typedef _fmutex __gthread_mutex_t;
     
    6461__gthread_once (__gthread_once_t *once, void (*func) (void))
    6562{
     63  if (once == NULL || func == NULL)
     64      return EINVAL;
    6665  if (__cxchg (once, 1) == 0)
    6766    func ();
     
    9392}
    9493
    95 #ifdef __cplusplus
    96 #  define EXTERN_C extern "C"
    97 #else
    98 #  define EXTERN_C extern
    99 #endif
    100 
    101 /** r=bird: We really should make a set of TLS functions for this stuff as
    102  *          the thread local memory is a very limited resource.
    103  */
    104 /* rather than including os2.h we'll define the prototype here... */
    105 EXTERN_C unsigned long _System DosAllocThreadLocalMemory (unsigned long dwords,
    106   unsigned long **ptr);
    107 EXTERN_C unsigned long _System DosFreeThreadLocalMemory (unsigned long *ptr);
    108 
    109 #undef EXTERN_C
    110 
    111 /* @@@BUG: dtor is NEVER called when the thread exits; todo: modify EMX
    112    libc so that we have separate storage in current thread structure and
    113    _endthread() calls all the destructors we assign here... */
    11494static inline int
    11595__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
    11696{
    117   if (DosAllocThreadLocalMemory ((sizeof (__gthread_key_struct_t) + 3)/4,
    118         (unsigned long **)key))
    119     return -1;
    120 
    121   (*key)->thread_data = NULL;
    122   (*key)->thread_dtor = dtor;
    123   return 0;
     97    int iTLS = __libc_TLSAlloc();
     98    if (iTLS < 0)
     99        return errno;
     100    __libc_TLSDestructor(iTLS, (void (*)(void *, int, unsigned))dtor, 0);
     101    *key = iTLS;
     102    return 0;
    124103}
    125104
     
    127106__gthread_key_dtor (__gthread_key_t key, void *ptr)
    128107{
    129   key->thread_dtor (ptr);
    130   key->thread_dtor = NULL;
    131   return 0;
     108    void (*pfnDestructor)(void *pvValue, int iTLSIndex, unsigned fFlags) = __libc_TLSGetDestructor(key, NULL);
     109    if (pfnDestructor)
     110    {
     111        pfnDestructor(ptr, key, 0);
     112        __libc_TLSSet(key, NULL);
     113    }
     114    return 0;
    132115}
    133116
     
    135118__gthread_key_delete (__gthread_key_t key)
    136119{
    137   return DosFreeThreadLocalMemory ((unsigned long *)key);
     120    if (__libc_TLSFree(key))
     121        return errno;
     122    return 0;
    138123}
    139124
     
    141126__gthread_getspecific (__gthread_key_t key)
    142127{
    143   return key->thread_data;
     128    return __libc_TLSGet(key);
    144129}
    145130
     
    147132__gthread_setspecific (__gthread_key_t key, const void *ptr)
    148133{
    149   key->thread_data = (void *)ptr;
    150   return 0;
     134    if (__libc_TLSSet(key, (void *)ptr))
     135        return errno;
     136    return 0;
    151137}
    152138
    153 #else /* __MT__ */
    154 
    155 #include "gthr-single.h"
    156 
    157 #endif /* __MT__ */
    158 
    159139#endif /* not __gthr_os2_h */
Note: See TracChangeset for help on using the changeset viewer.