thr-irix.c
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:5k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. /* GNU Objective C Runtime Thread Interface - SGI IRIX Implementation
  2.    Copyright (C) 1996, 1997 Free Software Foundation, Inc.
  3.    Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
  4. This file is part of GNU CC.
  5. GNU CC is free software; you can redistribute it and/or modify it under the
  6. terms of the GNU General Public License as published by the Free Software
  7. Foundation; either version 2, or (at your option) any later version.
  8. GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  11. details.
  12. You should have received a copy of the GNU General Public License along with
  13. GNU CC; see the file COPYING.  If not, write to the Free Software
  14. Foundation, 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.  */
  16. /* As a special exception, if you link this library with files compiled with
  17.    GCC to produce an executable, this does not cause the resulting executable
  18.    to be covered by the GNU General Public License. This exception does not
  19.    however invalidate any other reasons why the executable file might be
  20.    covered by the GNU General Public License.  */
  21. #include <stdlib.h>
  22. #include <sys/types.h>
  23. #include <sys/sysmp.h>
  24. #include <sys/prctl.h>
  25. #include <ulocks.h>
  26. #include <objc/thr.h>
  27. #include "runtime.h"
  28. /* Key structure for maintaining thread specific storage */
  29. static void * __objc_shared_arena_handle = NULL;
  30. /* Backend initialization functions */
  31. /* Initialize the threads subsystem. */
  32. int
  33. __objc_init_thread_system(void)
  34. {
  35.   /* Name of IRIX arena. */
  36.   char arena_name[64];
  37.   DEBUG_PRINTF("__objc_init_thread_systemn");
  38.   /* Construct a temporary name for arena. */
  39.   sprintf(arena_name, "/usr/tmp/objc_%05u", (unsigned)getpid());
  40.   /* Up to 256 threads.  Arena only for threads. */
  41.   usconfig(CONF_INITUSERS, 256);
  42.   usconfig(CONF_ARENATYPE, US_SHAREDONLY);
  43.   /* Initialize the arena */
  44.   if (!(__objc_shared_arena_handle = usinit(arena_name)))
  45.     /* Failed */
  46.     return -1;
  47.   return 0;
  48. }
  49. /* Close the threads subsystem. */
  50. int
  51. __objc_close_thread_system(void)
  52. {
  53.   return 0;
  54. }
  55. /* Backend thread functions */
  56. /* Create a new thread of execution. */
  57. objc_thread_t
  58. __objc_thread_detach(void (*func)(void *arg), void *arg)
  59. {
  60.   objc_thread_t thread_id;
  61.   int sys_id;
  62.   if ((sys_id = sproc((void *)func, PR_SALL, arg)) >= 0)
  63.     thread_id = (objc_thread_t)sys_id;
  64.   else
  65.     thread_id = NULL;
  66.   
  67.   return thread_id;
  68. }
  69. /* Set the current thread's priority. */
  70. int
  71. __objc_thread_set_priority(int priority)
  72. {
  73.   /* Not implemented yet */
  74.   return -1;
  75. }
  76. /* Return the current thread's priority. */
  77. int
  78. __objc_thread_get_priority(void)
  79. {
  80.   /* Not implemented yet */
  81.   return OBJC_THREAD_INTERACTIVE_PRIORITY;
  82. }
  83. /* Yield our process time to another thread. */
  84. void
  85. __objc_thread_yield(void)
  86. {
  87.   sginap(0);
  88. }
  89. /* Terminate the current thread. */
  90. int
  91. __objc_thread_exit(void)
  92. {
  93.   /* IRIX only has exit. */
  94.   exit(__objc_thread_exit_status);
  95.   /* Failed if we reached here */
  96.   return -1;
  97. }
  98. /* Returns an integer value which uniquely describes a thread. */
  99. objc_thread_t
  100. __objc_thread_id(void)
  101. {
  102.   /* Threads are processes. */
  103.   return (objc_thread_t)get_pid();
  104. }
  105. /* Sets the thread's local storage pointer. */
  106. int
  107. __objc_thread_set_data(void *value)
  108. {
  109.   *((void **)&PRDA->usr_prda) = value;
  110.   return 0;
  111. }
  112. /* Returns the thread's local storage pointer. */
  113. void *
  114. __objc_thread_get_data(void)
  115. {
  116.   return *((void **)&PRDA->usr_prda);
  117. }
  118. /* Backend mutex functions */
  119. /* Allocate a mutex. */
  120. int
  121. __objc_mutex_allocate(objc_mutex_t mutex)
  122. {
  123.   if (!( (ulock_t)(mutex->backend) = usnewlock(__objc_shared_arena_handle) ))
  124.     return -1;
  125.   else
  126.     return 0;
  127. }
  128. /* Deallocate a mutex. */
  129. int
  130. __objc_mutex_deallocate(objc_mutex_t mutex)
  131. {
  132.   usfreelock((ulock_t)(mutex->backend), __objc_shared_arena_handle);
  133.   return 0;
  134. }
  135. /* Grab a lock on a mutex. */
  136. int
  137. __objc_mutex_lock(objc_mutex_t mutex)
  138. {
  139.   if (ussetlock((ulock_t)(mutex->backend)) == 0)
  140.     return -1;
  141.   else
  142.     return 0;
  143. }
  144. /* Try to grab a lock on a mutex. */
  145. int
  146. __objc_mutex_trylock(objc_mutex_t mutex)
  147. {
  148.   if (ustestlock((ulock_t)(mutex->backend)) == 0)
  149.     return -1;
  150.   else
  151.     return 0;
  152. }
  153. /* Unlock the mutex */
  154. int
  155. __objc_mutex_unlock(objc_mutex_t mutex)
  156. {
  157.   usunsetlock((ulock_t)(mutex->backend));
  158.   return 0;
  159. }
  160. /* Backend condition mutex functions */
  161. /* Allocate a condition. */
  162. int
  163. __objc_condition_allocate(objc_condition_t condition)
  164. {
  165.   /* Unimplemented. */
  166.   return -1;
  167. }
  168. /* Deallocate a condition. */
  169. int
  170. __objc_condition_deallocate(objc_condition_t condition)
  171. {
  172.   /* Unimplemented. */
  173.   return -1;
  174. }
  175. /* Wait on the condition */
  176. int
  177. __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
  178. {
  179.   /* Unimplemented. */
  180.   return -1;
  181. }
  182. /* Wake up all threads waiting on this condition. */
  183. int
  184. __objc_condition_broadcast(objc_condition_t condition)
  185. {
  186.   /* Unimplemented. */
  187.   return -1;
  188. }
  189. /* Wake up one thread waiting on this condition. */
  190. int
  191. __objc_condition_signal(objc_condition_t condition)
  192. {
  193.   /* Unimplemented. */
  194.   return -1;
  195. }
  196. /* End of File */