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

信息检索与抽取

开发平台:

Unix_Linux

  1. /* Thread and mutex controls for Objective C.
  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
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. GNU CC is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13. GNU CC is free software; you can redistribute it and/or modify it under the
  14. terms of the GNU General Public License as published by the Free Software
  15. Foundation; either version 2, or (at your option) any later version.
  16. GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY
  17. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  18. FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  19. details.
  20. You should have received a copy of the GNU General Public License along with
  21. GNU CC; see the file COPYING.  If not, write to the Free Software
  22. Foundation, 59 Temple Place - Suite 330,
  23. Boston, MA 02111-1307, USA.  */
  24. /* As a special exception, if you link this library with files
  25.    compiled with GCC to produce an executable, this does not cause
  26.    the resulting executable to be covered by the GNU General Public License.
  27.    This exception does not however invalidate any other reasons why
  28.    the executable file might be covered by the GNU General Public License.  */
  29. #ifndef __thread_INCLUDE_GNU
  30. #define __thread_INCLUDE_GNU
  31. #include <objc/objc.h>
  32. #include <objc/externvar.h>
  33. /*************************************************************************
  34.  *  Universal static variables:
  35.  */
  36. externobjcvar int __objc_thread_exit_status;      /* Global exit status.   */
  37. /********
  38.  *  Thread safe implementation types and functions.  
  39.  */
  40. /* Thread priorities */
  41. #define OBJC_THREAD_INTERACTIVE_PRIORITY        2
  42. #define OBJC_THREAD_BACKGROUND_PRIORITY         1
  43. #define OBJC_THREAD_LOW_PRIORITY                0
  44. /* A thread */
  45. typedef void * objc_thread_t;
  46. /* This structure represents a single mutual exclusion lock. */
  47. struct objc_mutex
  48. {
  49.   volatile objc_thread_t owner;     /* Id of thread that owns. */
  50.   volatile int depth;               /* # of acquires. */
  51.   void * backend;                   /* Specific to backend */
  52. };
  53. typedef struct objc_mutex *objc_mutex_t;
  54. /* This structure represents a single condition mutex */
  55. struct objc_condition
  56. {
  57.   void * backend;                   /* Specific to backend */
  58. };
  59. typedef struct objc_condition *objc_condition_t;
  60. /* Frontend mutex functions */
  61. objc_mutex_t objc_mutex_allocate(void);
  62. int objc_mutex_deallocate(objc_mutex_t mutex);
  63. int objc_mutex_lock(objc_mutex_t mutex);
  64. int objc_mutex_unlock(objc_mutex_t mutex);
  65. int objc_mutex_trylock(objc_mutex_t mutex);
  66. /* Frontend condition mutex functions */
  67. objc_condition_t objc_condition_allocate(void);
  68. int objc_condition_deallocate(objc_condition_t condition);
  69. int objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex);
  70. int objc_condition_signal(objc_condition_t condition);
  71. int objc_condition_broadcast(objc_condition_t condition);
  72. /* Frontend thread functions */
  73. objc_thread_t objc_thread_detach(SEL selector, id object, id argument);
  74. void objc_thread_yield(void);
  75. int objc_thread_exit(void);
  76. int objc_thread_set_priority(int priority);
  77. int objc_thread_get_priority(void);
  78. void * objc_thread_get_data(void);
  79. int objc_thread_set_data(void *value);
  80. objc_thread_t objc_thread_id(void);
  81. /*
  82.   Use this to set the hook function that will be called when the 
  83.   runtime initially becomes multi threaded.
  84.   The hook function is only called once, meaning only when the 
  85.   2nd thread is spawned, not for each and every thread.
  86.   It returns the previous hook function or NULL if there is none.
  87.   A program outside of the runtime could set this to some function so
  88.   it can be informed; for example, the GNUstep Base Library sets it 
  89.   so it can implement the NSBecomingMultiThreaded notification.
  90.   */
  91. typedef void (*objc_thread_callback)();
  92. objc_thread_callback objc_set_thread_callback(objc_thread_callback func);
  93. /* Backend initialization functions */
  94. int __objc_init_thread_system(void);
  95. int __objc_fini_thread_system(void);
  96. /* Backend mutex functions */
  97. int __objc_mutex_allocate(objc_mutex_t mutex);
  98. int __objc_mutex_deallocate(objc_mutex_t mutex);
  99. int __objc_mutex_lock(objc_mutex_t mutex);
  100. int __objc_mutex_trylock(objc_mutex_t mutex);
  101. int __objc_mutex_unlock(objc_mutex_t mutex);
  102. /* Backend condition mutex functions */
  103. int __objc_condition_allocate(objc_condition_t condition);
  104. int __objc_condition_deallocate(objc_condition_t condition);
  105. int __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex);
  106. int __objc_condition_broadcast(objc_condition_t condition);
  107. int __objc_condition_signal(objc_condition_t condition);
  108. /* Backend thread functions */
  109. objc_thread_t __objc_thread_detach(void (*func)(void *arg), void *arg);
  110. int __objc_thread_set_priority(int priority);
  111. int __objc_thread_get_priority(void);
  112. void __objc_thread_yield(void);
  113. int __objc_thread_exit(void);
  114. objc_thread_t __objc_thread_id(void);
  115. int __objc_thread_set_data(void *value);
  116. void * __objc_thread_get_data(void);
  117. #endif /* not __thread_INCLUDE_GNU */