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