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.

174 lines
5.9 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
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 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
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
26 years ago
26 years ago
  1. /* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
  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; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. /* For use with thr_lock:s */
  13. #ifndef _thr_lock_h
  14. #define _thr_lock_h
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <my_pthread.h>
  19. #include <my_list.h>
  20. struct st_thr_lock;
  21. extern ulong locks_immediate,locks_waited ;
  22. /*
  23. Important: if a new lock type is added, a matching lock description
  24. must be added to sql_test.cc's lock_descriptions array.
  25. */
  26. enum thr_lock_type { TL_IGNORE=-1,
  27. TL_UNLOCK, /* UNLOCK ANY LOCK */
  28. /*
  29. Parser only! At open_tables() becomes TL_READ or
  30. TL_READ_NO_INSERT depending on the binary log format
  31. (SBR/RBR) and on the table category (log table).
  32. Used for tables that are read by statements which
  33. modify tables.
  34. */
  35. TL_READ_DEFAULT,
  36. TL_READ, /* Read lock */
  37. TL_READ_WITH_SHARED_LOCKS,
  38. /* High prior. than TL_WRITE. Allow concurrent insert */
  39. TL_READ_HIGH_PRIORITY,
  40. /* READ, Don't allow concurrent insert */
  41. TL_READ_NO_INSERT,
  42. /*
  43. Write lock, but allow other threads to read / write.
  44. Used by BDB tables in MySQL to mark that someone is
  45. reading/writing to the table.
  46. */
  47. TL_WRITE_ALLOW_WRITE,
  48. /*
  49. Write lock, but allow other threads to read.
  50. Used by ALTER TABLE in MySQL to allow readers
  51. to use the table until ALTER TABLE is finished.
  52. */
  53. TL_WRITE_ALLOW_READ,
  54. /*
  55. WRITE lock used by concurrent insert. Will allow
  56. READ, if one could use concurrent insert on table.
  57. */
  58. TL_WRITE_CONCURRENT_INSERT,
  59. /* Write used by INSERT DELAYED. Allows READ locks */
  60. TL_WRITE_DELAYED,
  61. /*
  62. parser only! Late bound low_priority flag.
  63. At open_tables() becomes thd->update_lock_default.
  64. */
  65. TL_WRITE_DEFAULT,
  66. /* WRITE lock that has lower priority than TL_READ */
  67. TL_WRITE_LOW_PRIORITY,
  68. /* Normal WRITE lock */
  69. TL_WRITE,
  70. /* Abort new lock request with an error */
  71. TL_WRITE_ONLY};
  72. enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1,
  73. THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 };
  74. extern ulong max_write_lock_count;
  75. extern ulong table_lock_wait_timeout;
  76. extern my_bool thr_lock_inited;
  77. extern enum thr_lock_type thr_upgraded_concurrent_insert_lock;
  78. /*
  79. A description of the thread which owns the lock. The address
  80. of an instance of this structure is used to uniquely identify the thread.
  81. */
  82. typedef struct st_thr_lock_info
  83. {
  84. pthread_t thread;
  85. my_thread_id thread_id;
  86. ulong n_cursors;
  87. } THR_LOCK_INFO;
  88. /*
  89. Lock owner identifier. Globally identifies the lock owner within the
  90. thread and among all the threads. The address of an instance of this
  91. structure is used as id.
  92. */
  93. typedef struct st_thr_lock_owner
  94. {
  95. THR_LOCK_INFO *info;
  96. } THR_LOCK_OWNER;
  97. typedef struct st_thr_lock_data {
  98. THR_LOCK_OWNER *owner;
  99. struct st_thr_lock_data *next,**prev;
  100. struct st_thr_lock *lock;
  101. pthread_cond_t *cond;
  102. enum thr_lock_type type;
  103. void *status_param; /* Param to status functions */
  104. void *debug_print_param;
  105. } THR_LOCK_DATA;
  106. struct st_lock_list {
  107. THR_LOCK_DATA *data,**last;
  108. };
  109. typedef struct st_thr_lock {
  110. LIST list;
  111. pthread_mutex_t mutex;
  112. struct st_lock_list read_wait;
  113. struct st_lock_list read;
  114. struct st_lock_list write_wait;
  115. struct st_lock_list write;
  116. /* write_lock_count is incremented for write locks and reset on read locks */
  117. ulong write_lock_count;
  118. uint read_no_write_count;
  119. void (*get_status)(void*, int); /* When one gets a lock */
  120. void (*copy_status)(void*,void*);
  121. void (*update_status)(void*); /* Before release of write */
  122. void (*restore_status)(void*); /* Before release of read */
  123. my_bool (*check_status)(void *);
  124. } THR_LOCK;
  125. extern LIST *thr_lock_thread_list;
  126. extern pthread_mutex_t THR_LOCK_lock;
  127. my_bool init_thr_lock(void); /* Must be called once/thread */
  128. #define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg)
  129. void thr_lock_info_init(THR_LOCK_INFO *info);
  130. void thr_lock_init(THR_LOCK *lock);
  131. void thr_lock_delete(THR_LOCK *lock);
  132. void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data,
  133. void *status_param);
  134. enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data,
  135. THR_LOCK_OWNER *owner,
  136. enum thr_lock_type lock_type);
  137. void thr_unlock(THR_LOCK_DATA *data);
  138. enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data,
  139. uint count, THR_LOCK_OWNER *owner);
  140. void thr_multi_unlock(THR_LOCK_DATA **data,uint count);
  141. void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock);
  142. my_bool thr_abort_locks_for_thread(THR_LOCK *lock, my_thread_id thread);
  143. void thr_print_locks(void); /* For debugging */
  144. my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data,
  145. enum thr_lock_type new_lock_type);
  146. void thr_downgrade_write_lock(THR_LOCK_DATA *data,
  147. enum thr_lock_type new_lock_type);
  148. my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data);
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* _thr_lock_h */