Subversion Repositories Kolibri OS

Rev

Rev 4872 | Blame | Last modification | View Log | RSS feed

  1. /* Threads compatibility routines for libgcc2.  */
  2. /* Compile this one with gcc.  */
  3. /* Copyright (C) 1997, 1998, 2004, 2008, 2009 Free Software Foundation, Inc.
  4.  
  5. This file is part of GCC.
  6.  
  7. GCC is free software; you can redistribute it and/or modify it under
  8. the terms of the GNU General Public License as published by the Free
  9. Software Foundation; either version 3, or (at your option) any later
  10. version.
  11.  
  12. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  13. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. Under Section 7 of GPL version 3, you are granted additional
  18. permissions described in the GCC Runtime Library Exception, version
  19. 3.1, as published by the Free Software Foundation.
  20.  
  21. You should have received a copy of the GNU General Public License and
  22. a copy of the GCC Runtime Library Exception along with this program;
  23. see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
  24. <http://www.gnu.org/licenses/>.  */
  25.  
  26. #ifndef GCC_GTHR_H
  27. #define GCC_GTHR_H
  28.  
  29. typedef unsigned int __gthread_key_t;
  30.  
  31. typedef struct {
  32.   volatile int done;
  33.   int started;
  34. } __gthread_once_t;
  35.  
  36. typedef struct {
  37.   volatile int counter;
  38. } __gthread_mutex_t;
  39.  
  40.  
  41. void *tls_alloc(void);
  42.  
  43. static int __gthread_mutex_lock (__gthread_mutex_t *mutex)
  44. {
  45.     __mutex_lock(&mutex->counter);
  46.     return 0;
  47. };
  48.  
  49. static int __gthread_mutex_unlock (__gthread_mutex_t *mutex)
  50. {
  51.     mutex->counter = 0;
  52.     return 0;
  53. };
  54.  
  55. static inline int __gthread_key_create (__gthread_key_t *__key,
  56.               void (*__dtor) (void *) __attribute__((unused)))
  57. {
  58.     int __status = 0;
  59.     void *__tls_index = tls_alloc();
  60.     if (__tls_index != NULL)
  61.     {
  62.         *__key = (unsigned int)__tls_index;
  63.  
  64. #ifdef MINGW32_SUPPORTS_MT_EH               /* FIXME */
  65.       /* Mingw runtime will run the dtors in reverse order for each thread
  66.          when the thread exits.  */
  67. //      __status = __mingwthr_key_dtor (*__key, __dtor);
  68. #endif
  69.  
  70.     }
  71.     else
  72.         __status = (int) ENOMEM;
  73.     return __status;
  74. }
  75.  
  76.  
  77. static inline void *
  78. __gthread_getspecific (__gthread_key_t __key)
  79. {
  80.     void *val;
  81.     __asm__ __volatile__(
  82.     "movl %%fs:(%1), %0"
  83.     :"=r"(val)
  84.     :"r"(__key));
  85.  
  86.   return val;
  87. };
  88.  
  89. static inline int
  90. __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
  91. {
  92.     if(!(__key & 3))
  93.     {
  94.         __asm__ __volatile__(
  95.         "movl %0, %%fs:(%1)"
  96.         ::"r"(__ptr),"r"(__key));
  97.         return 0;
  98.     }
  99.     else return EINVAL;
  100. }
  101.  
  102.  
  103. #endif
  104.