Eneboo - Documentación para desarrolladores
|
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 extern ulong max_write_lock_count; 00066 extern my_bool thr_lock_inited; 00067 extern enum thr_lock_type thr_upgraded_concurrent_insert_lock; 00068 00069 typedef struct st_thr_lock_data { 00070 pthread_t thread; 00071 struct st_thr_lock_data *next,**prev; 00072 struct st_thr_lock *lock; 00073 pthread_cond_t *cond; 00074 enum thr_lock_type type; 00075 ulong thread_id; 00076 void *status_param; /* Param to status functions */ 00077 void *debug_print_param; 00078 } THR_LOCK_DATA; 00079 00080 struct st_lock_list { 00081 THR_LOCK_DATA *data,**last; 00082 }; 00083 00084 typedef struct st_thr_lock { 00085 LIST list; 00086 pthread_mutex_t mutex; 00087 struct st_lock_list read_wait; 00088 struct st_lock_list read; 00089 struct st_lock_list write_wait; 00090 struct st_lock_list write; 00091 /* write_lock_count is incremented for write locks and reset on read locks */ 00092 ulong write_lock_count; 00093 uint read_no_write_count; 00094 void (*get_status)(void*); /* When one gets a lock */ 00095 void (*copy_status)(void*,void*); 00096 void (*update_status)(void*); /* Before release of write */ 00097 my_bool (*check_status)(void *); 00098 } THR_LOCK; 00099 00100 00101 extern LIST *thr_lock_thread_list; 00102 extern pthread_mutex_t THR_LOCK_lock; 00103 00104 my_bool init_thr_lock(void); /* Must be called once/thread */ 00105 void thr_lock_init(THR_LOCK *lock); 00106 void thr_lock_delete(THR_LOCK *lock); 00107 void thr_lock_data_init(THR_LOCK *lock,THR_LOCK_DATA *data, 00108 void *status_param); 00109 int thr_lock(THR_LOCK_DATA *data,enum thr_lock_type lock_type); 00110 void thr_unlock(THR_LOCK_DATA *data); 00111 int thr_multi_lock(THR_LOCK_DATA **data,uint count); 00112 void thr_multi_unlock(THR_LOCK_DATA **data,uint count); 00113 void thr_abort_locks(THR_LOCK *lock); 00114 my_bool thr_abort_locks_for_thread(THR_LOCK *lock, pthread_t thread); 00115 void thr_print_locks(void); /* For debugging */ 00116 my_bool thr_upgrade_write_delay_lock(THR_LOCK_DATA *data); 00117 my_bool thr_reschedule_write_lock(THR_LOCK_DATA *data); 00118 #ifdef __cplusplus 00119 } 00120 #endif 00121 #endif /* _thr_lock_h */