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.

156 lines
5.0 KiB

26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
  1. /* Copyright (C) 2000 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  13. /* For use with thr_lock:s */
  14. #ifndef _thr_lock_h
  15. #define _thr_lock_h
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include <my_pthread.h>
  20. #include <my_list.h>
  21. struct st_thr_lock;
  22. extern ulong locks_immediate,locks_waited ;
  23. enum thr_lock_type { TL_IGNORE=-1,
  24. TL_UNLOCK, /* UNLOCK ANY LOCK */
  25. TL_READ, /* Read lock */
  26. TL_READ_WITH_SHARED_LOCKS,
  27. /* High prior. than TL_WRITE. Allow concurrent insert */
  28. TL_READ_HIGH_PRIORITY,
  29. /* READ, Don't allow concurrent insert */
  30. TL_READ_NO_INSERT,
  31. /*
  32. Write lock, but allow other threads to read / write.
  33. Used by BDB tables in MySQL to mark that someone is
  34. reading/writing to the table.
  35. */
  36. TL_WRITE_ALLOW_WRITE,
  37. /*
  38. Write lock, but allow other threads to read.
  39. Used by ALTER TABLE in MySQL to allow readers
  40. to use the table until ALTER TABLE is finished.
  41. */
  42. TL_WRITE_ALLOW_READ,
  43. /*
  44. WRITE lock used by concurrent insert. Will allow
  45. READ, if one could use concurrent insert on table.
  46. */
  47. TL_WRITE_CONCURRENT_INSERT,
  48. /* Write used by INSERT DELAYED. Allows READ locks */
  49. TL_WRITE_DELAYED,
  50. /* WRITE lock that has lower priority than TL_READ */
  51. TL_WRITE_LOW_PRIORITY,
  52. /* Normal WRITE lock */
  53. TL_WRITE,
  54. /* Abort new lock request with an error */
  55. TL_WRITE_ONLY};
  56. enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
  57. THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };
  58. extern ulong max_write_lock_count;
  59. extern ulong table_lock_wait_timeout;
  60. extern my_bool thr_lock_inited;
  61. extern enum thr_lock_type thr_upgraded_concurrent_insert_lock;
  62. /*
  63. A description of the thread which owns the lock. The address
  64. of an instance of this structure is used to uniquely identify the thread.
  65. */
  66. typedef struct st_thr_lock_info
  67. {
  68. pthread_t thread;
  69. ulong thread_id;
  70. ulong n_cursors;
  71. } THR_LOCK_INFO;
  72. /*
  73. Lock owner identifier. Globally identifies the lock owner within the
  74. thread and among all the threads. The address of an instance of this
  75. structure is used as id.
  76. */
  77. typedef struct st_thr_lock_owner
  78. {
  79. THR_LOCK_INFO *info;
  80. } THR_LOCK_OWNER;
  81. typedef struct st_thr_lock_data {
  82. THR_LOCK_OWNER *owner;
  83. struct st_thr_lock_data *next,**prev;
  84. struct st_thr_lock *lock;
  85. pthread_cond_t *cond;
  86. enum thr_lock_type type;
  87. void *status_param; /* Param to status functions */
  88. void *debug_print_param;
  89. } THR_LOCK_DATA;
  90. struct st_lock_list {
  91. THR_LOCK_DATA *data,**last;
  92. };
  93. typedef struct st_thr_lock {
  94. LIST list;
  95. pthread_mutex_t mutex;
  96. struct st_lock_list read_wait;
  97. struct st_lock_list read;
  98. struct st_lock_list write_wait;
  99. struct st_lock_list write;
  100. /* write_lock_count is incremented for write locks and reset on read locks */
  101. ulong write_lock_count;
  102. uint read_no_write_count;
  103. void (*get_status)(void*, int); /* When one gets a lock */
  104. void (*copy_status)(void*,void*);
  105. void (*update_status)(void*); /* Before release of write */
  106. my_bool (*check_status)(void *);
  107. } THR_LOCK;
  108. extern LIST *thr_lock_thread_list;
  109. extern pthread_mutex_t THR_LOCK_lock;
  110. my_bool init_thr_lock(void); /* Must be called once/thread */
  111. #define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
  112. void thr_lock_info_init(THR_LOCK_INFO *info);
  113. void thr_lock_init(THR_LOCK *lock);
  114. void thr_lock_delete(THR_LOCK *lock);
  115. void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
  116. void *status_param);
  117. enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data,
  118. THR_LOCK_OWNER *owner,
  119. enum thr_lock_type lock_type);
  120. void thr_unlock(THR_LOCK_DATA *data);
  121. enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
  122. uint count, THR_LOCK_OWNER *owner);
  123. void thr_multi_unlock(THR_LOCK_DATA **data,uint count);
  124. void thr_abort_locks(THR_LOCK *lock, bool upgrade_lock);
  125. my_bool thr_abort_locks_for_thread(THR_LOCK *lock, pthread_t thread);
  126. void thr_print_locks(void); /* For debugging */
  127. my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data);
  128. void thr_downgrade_write_lock(THR_LOCK_DATA *data,
  129. enum thr_lock_type new_lock_type);
  130. my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
  131. #ifdef __cplusplus
  132. }
  133. #endif
  134. #endif /* _thr_lock_h */