home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / include / thr_lock.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-01-21  |  3.8 KB  |  118 lines  |  [TEXT/CWIE]

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