The world's most popular open source database
00001 /* Copyright (C) 2000 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* For use with thr_lock:s */ 00018 00019 #ifndef _thr_lock_h 00020 #define _thr_lock_h 00021 #ifdef __cplusplus 00022 extern "C" { 00023 #endif 00024 00025 #include <my_pthread.h> 00026 #include <my_list.h> 00027 00028 struct st_thr_lock; 00029 extern ulong locks_immediate,locks_waited ; 00030 00031 enum thr_lock_type { TL_IGNORE=-1, 00032 TL_UNLOCK, /* UNLOCK ANY LOCK */ 00033 TL_READ, /* Read lock */ 00034 TL_READ_WITH_SHARED_LOCKS, 00035 /* High prior. than TL_WRITE. Allow concurrent insert */ 00036 TL_READ_HIGH_PRIORITY, 00037 /* READ, Don't allow concurrent insert */ 00038 TL_READ_NO_INSERT, 00039 /* 00040 Write lock, but allow other threads to read / write. 00041 Used by BDB tables in MySQL to mark that someone is 00042 reading/writing to the table. 00043 */ 00044 TL_WRITE_ALLOW_WRITE, 00045 /* 00046 Write lock, but allow other threads to read. 00047 Used by ALTER TABLE in MySQL to allow readers 00048 to use the table until ALTER TABLE is finished. 00049 */ 00050 TL_WRITE_ALLOW_READ, 00051 /* 00052 WRITE lock used by concurrent insert. Will allow 00053 READ, if one could use concurrent insert on table. 00054 */ 00055 TL_WRITE_CONCURRENT_INSERT, 00056 /* Write used by INSERT DELAYED. Allows READ locks */ 00057 TL_WRITE_DELAYED, 00058 /* WRITE lock that has lower priority than TL_READ */ 00059 TL_WRITE_LOW_PRIORITY, 00060 /* Normal WRITE lock */ 00061 TL_WRITE, 00062 /* Abort new lock request with an error */ 00063 TL_WRITE_ONLY}; 00064 00065 enum enum_thr_lock_result { THR_LOCK_SUCCESS= 0, THR_LOCK_ABORTED= 1, 00066 THR_LOCK_WAIT_TIMEOUT= 2, THR_LOCK_DEADLOCK= 3 }; 00067 00068 00069 extern ulong max_write_lock_count; 00070 extern ulong table_lock_wait_timeout; 00071 extern my_bool thr_lock_inited; 00072 extern enum thr_lock_type thr_upgraded_concurrent_insert_lock; 00073 00074 /* 00075 A description of the thread which owns the lock. The address 00076 of an instance of this structure is used to uniquely identify the thread. 00077 */ 00078 00079 typedef struct st_thr_lock_info 00080 { 00081 pthread_t thread; 00082 ulong thread_id; 00083 ulong n_cursors; 00084 } THR_LOCK_INFO; 00085 00086 /* 00087 Lock owner identifier. Globally identifies the lock owner within the 00088 thread and among all the threads. The address of an instance of this 00089 structure is used as id. 00090 */ 00091 00092 typedef struct st_thr_lock_owner 00093 { 00094 THR_LOCK_INFO *info; 00095 } THR_LOCK_OWNER; 00096 00097 00098 typedef struct st_thr_lock_data { 00099 THR_LOCK_OWNER *owner; 00100 struct st_thr_lock_data *next,**prev; 00101 struct st_thr_lock *lock; 00102 pthread_cond_t *cond; 00103 enum thr_lock_type type; 00104 void *status_param; /* Param to status functions */ 00105 void *debug_print_param; 00106 } THR_LOCK_DATA; 00107 00108 struct st_lock_list { 00109 THR_LOCK_DATA *data,**last; 00110 }; 00111 00112 typedef struct st_thr_lock { 00113 LIST list; 00114 pthread_mutex_t mutex; 00115 struct st_lock_list read_wait; 00116 struct st_lock_list read; 00117 struct st_lock_list write_wait; 00118 struct st_lock_list write; 00119 /* write_lock_count is incremented for write locks and reset on read locks */ 00120 ulong write_lock_count; 00121 uint read_no_write_count; 00122 void (*get_status)(void*, int); /* When one gets a lock */ 00123 void (*copy_status)(void*,void*); 00124 void (*update_status)(void*); /* Before release of write */ 00125 my_bool (*check_status)(void *); 00126 } THR_LOCK; 00127 00128 00129 extern LIST *thr_lock_thread_list; 00130 extern pthread_mutex_t THR_LOCK_lock; 00131 00132 my_bool init_thr_lock(void); /* Must be called once/thread */ 00133 #define thr_lock_owner_init(owner, info_arg) (owner)->info= (info_arg) 00134 void thr_lock_info_init(THR_LOCK_INFO *info); 00135 void thr_lock_init(THR_LOCK *lock); 00136 void thr_lock_delete(THR_LOCK *lock); 00137 void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data, 00138 void *status_param); 00139 enum enum_thr_lock_result thr_lock(THR_LOCK_DATA *data, 00140 THR_LOCK_OWNER *owner, 00141 enum thr_lock_type lock_type); 00142 void thr_unlock(THR_LOCK_DATA *data); 00143 enum enum_thr_lock_result thr_multi_lock(THR_LOCK_DATA **data, 00144 uint count, THR_LOCK_OWNER *owner); 00145 void thr_multi_unlock(THR_LOCK_DATA **data,uint count); 00146 void thr_abort_locks(THR_LOCK *lock, bool upgrade_lock); 00147 my_bool thr_abort_locks_for_thread(THR_LOCK *lock, pthread_t thread); 00148 void thr_print_locks(void); /* For debugging */ 00149 my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data); 00150 void thr_downgrade_write_lock(THR_LOCK_DATA *data, 00151 enum thr_lock_type new_lock_type); 00152 my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data); 00153 #ifdef __cplusplus 00154 } 00155 #endif 00156 #endif /* _thr_lock_h */
1.4.7

