You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.2 KiB

  1. /*****************************************************************************
  2. Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  11. Place, Suite 330, Boston, MA 02111-1307 USA
  12. *****************************************************************************/
  13. /**************************************************//**
  14. @file include/os0thread.h
  15. The interface to the operating system
  16. process and thread control primitives
  17. Created 9/8/1995 Heikki Tuuri
  18. *******************************************************/
  19. #ifndef os0thread_h
  20. #define os0thread_h
  21. #include "univ.i"
  22. /* Maximum number of threads which can be created in the program;
  23. this is also the size of the wait slot array for MySQL threads which
  24. can wait inside InnoDB */
  25. #define OS_THREAD_MAX_N srv_max_n_threads
  26. /* Possible fixed priorities for threads */
  27. #define OS_THREAD_PRIORITY_NONE 100
  28. #define OS_THREAD_PRIORITY_BACKGROUND 1
  29. #define OS_THREAD_PRIORITY_NORMAL 2
  30. #define OS_THREAD_PRIORITY_ABOVE_NORMAL 3
  31. #ifdef __WIN__
  32. typedef void* os_thread_t;
  33. typedef unsigned long os_thread_id_t; /*!< In Windows the thread id
  34. is an unsigned long int */
  35. #else
  36. typedef pthread_t os_thread_t;
  37. typedef os_thread_t os_thread_id_t; /*!< In Unix we use the thread
  38. handle itself as the id of
  39. the thread */
  40. #endif
  41. /* Define a function pointer type to use in a typecast */
  42. typedef void* (*os_posix_f_t) (void*);
  43. /***************************************************************//**
  44. Compares two thread ids for equality.
  45. @return TRUE if equal */
  46. UNIV_INTERN
  47. ibool
  48. os_thread_eq(
  49. /*=========*/
  50. os_thread_id_t a, /*!< in: OS thread or thread id */
  51. os_thread_id_t b); /*!< in: OS thread or thread id */
  52. /****************************************************************//**
  53. Converts an OS thread id to a ulint. It is NOT guaranteed that the ulint is
  54. unique for the thread though!
  55. @return thread identifier as a number */
  56. UNIV_INTERN
  57. ulint
  58. os_thread_pf(
  59. /*=========*/
  60. os_thread_id_t a); /*!< in: OS thread identifier */
  61. /****************************************************************//**
  62. Creates a new thread of execution. The execution starts from
  63. the function given. The start function takes a void* parameter
  64. and returns a ulint.
  65. NOTE: We count the number of threads in os_thread_exit(). A created
  66. thread should always use that to exit and not use return() to exit.
  67. @return handle to the thread */
  68. UNIV_INTERN
  69. os_thread_t
  70. os_thread_create(
  71. /*=============*/
  72. #ifndef __WIN__
  73. os_posix_f_t start_f,
  74. #else
  75. ulint (*start_f)(void*), /*!< in: pointer to function
  76. from which to start */
  77. #endif
  78. void* arg, /*!< in: argument to start
  79. function */
  80. os_thread_id_t* thread_id); /*!< out: id of the created
  81. thread, or NULL */
  82. /*****************************************************************//**
  83. Exits the current thread. */
  84. UNIV_INTERN
  85. void
  86. os_thread_exit(
  87. /*===========*/
  88. void* exit_value); /*!< in: exit value; in Windows this void*
  89. is cast as a DWORD */
  90. /*****************************************************************//**
  91. Returns the thread identifier of current thread.
  92. @return current thread identifier */
  93. UNIV_INTERN
  94. os_thread_id_t
  95. os_thread_get_curr_id(void);
  96. /*========================*/
  97. /*****************************************************************//**
  98. Returns handle to the current thread.
  99. @return current thread handle */
  100. UNIV_INTERN
  101. os_thread_t
  102. os_thread_get_curr(void);
  103. /*====================*/
  104. /*****************************************************************//**
  105. Advises the os to give up remainder of the thread's time slice. */
  106. UNIV_INTERN
  107. void
  108. os_thread_yield(void);
  109. /*=================*/
  110. /*****************************************************************//**
  111. The thread sleeps at least the time given in microseconds. */
  112. UNIV_INTERN
  113. void
  114. os_thread_sleep(
  115. /*============*/
  116. ulint tm); /*!< in: time in microseconds */
  117. /******************************************************************//**
  118. Gets a thread priority.
  119. @return priority */
  120. UNIV_INTERN
  121. ulint
  122. os_thread_get_priority(
  123. /*===================*/
  124. os_thread_t handle);/*!< in: OS handle to the thread */
  125. /******************************************************************//**
  126. Sets a thread priority. */
  127. UNIV_INTERN
  128. void
  129. os_thread_set_priority(
  130. /*===================*/
  131. os_thread_t handle, /*!< in: OS handle to the thread */
  132. ulint pri); /*!< in: priority: one of OS_PRIORITY_... */
  133. /******************************************************************//**
  134. Gets the last operating system error code for the calling thread.
  135. @return last error on Windows, 0 otherwise */
  136. UNIV_INTERN
  137. ulint
  138. os_thread_get_last_error(void);
  139. /*==========================*/
  140. #ifndef UNIV_NONINL
  141. #include "os0thread.ic"
  142. #endif
  143. #endif