~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/lock.cc

  • Committer: Grant Limberg
  • Date: 2008-08-12 21:13:01 UTC
  • mto: (322.1.1 codestyle)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: grant@glsoftware.net-20080812211301-ym3wsowelkgp16s2
renamed all instances of MYSQL_ to DRIZZLE_

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
#define GET_LOCK_UNLOCK         1
87
87
#define GET_LOCK_STORE_LOCKS    2
88
88
 
89
 
static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table,uint count,
 
89
static DRIZZLE_LOCK *get_lock_data(THD *thd, TABLE **table,uint count,
90
90
                                 uint flags, TABLE **write_locked);
91
91
static int lock_external(THD *thd, TABLE **table,uint count);
92
92
static int unlock_external(THD *thd, TABLE **table,uint count);
101
101
    tables                      An array of pointers to the tables to lock.
102
102
    count                       The number of tables to lock.
103
103
    flags                       Options:
104
 
      MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK      Ignore a global read lock
105
 
      MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY      Ignore SET GLOBAL READ_ONLY
106
 
      MYSQL_LOCK_IGNORE_FLUSH                 Ignore a flush tables.
107
 
      MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN        Instead of reopening altered
 
104
      DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK      Ignore a global read lock
 
105
      DRIZZLE_LOCK_IGNORE_GLOBAL_READ_ONLY      Ignore SET GLOBAL READ_ONLY
 
106
      DRIZZLE_LOCK_IGNORE_FLUSH                 Ignore a flush tables.
 
107
      DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN        Instead of reopening altered
108
108
                                              or dropped tables by itself,
109
109
                                              mysql_lock_tables() should
110
110
                                              notify upper level and rely
187
187
        lock request will set its lock type properly.
188
188
*/
189
189
 
190
 
static void reset_lock_data_and_free(MYSQL_LOCK **mysql_lock)
 
190
static void reset_lock_data_and_free(DRIZZLE_LOCK **mysql_lock)
191
191
{
192
 
  MYSQL_LOCK *sql_lock= *mysql_lock;
 
192
  DRIZZLE_LOCK *sql_lock= *mysql_lock;
193
193
  THR_LOCK_DATA **ldata, **ldata_end;
194
194
 
195
195
  /* Clear the lock type of all lock data to avoid reusage. */
205
205
}
206
206
 
207
207
 
208
 
MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count,
 
208
DRIZZLE_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count,
209
209
                              uint flags, bool *need_reopen)
210
210
{
211
 
  MYSQL_LOCK *sql_lock;
 
211
  DRIZZLE_LOCK *sql_lock;
212
212
  TABLE *write_lock_used;
213
213
  int rc;
214
214
 
224
224
      break;
225
225
 
226
226
    if (global_read_lock && write_lock_used &&
227
 
        ! (flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK))
 
227
        ! (flags & DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK))
228
228
    {
229
229
      /*
230
230
        Someone has issued LOCK ALL TABLES FOR READ and we want a write lock
244
244
      }
245
245
    }
246
246
 
247
 
    if (!(flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY) &&
 
247
    if (!(flags & DRIZZLE_LOCK_IGNORE_GLOBAL_READ_ONLY) &&
248
248
        write_lock_used &&
249
249
        opt_readonly &&
250
250
        !thd->slave_thread)
289
289
      sql_lock->lock_count= 0;                  // Locks are already freed
290
290
      // Fall through: unlock, reset lock data, free and retry
291
291
    }
292
 
    else if (!thd->some_tables_deleted || (flags & MYSQL_LOCK_IGNORE_FLUSH))
 
292
    else if (!thd->some_tables_deleted || (flags & DRIZZLE_LOCK_IGNORE_FLUSH))
293
293
    {
294
294
      /*
295
295
        Thread was killed or lock aborted. Let upper level close all
319
319
    */
320
320
    reset_lock_data_and_free(&sql_lock);
321
321
retry:
322
 
    if (flags & MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN)
 
322
    if (flags & DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN)
323
323
    {
324
324
      *need_reopen= true;
325
325
      break;
377
377
}
378
378
 
379
379
 
380
 
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock)
 
380
void mysql_unlock_tables(THD *thd, DRIZZLE_LOCK *sql_lock)
381
381
{
382
382
  if (sql_lock->lock_count)
383
383
    thr_multi_unlock(sql_lock->locks,sql_lock->lock_count);
395
395
 
396
396
void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count)
397
397
{
398
 
  MYSQL_LOCK *sql_lock;
 
398
  DRIZZLE_LOCK *sql_lock;
399
399
  TABLE *write_lock_used;
400
400
  if ((sql_lock= get_lock_data(thd, table, count, GET_LOCK_UNLOCK,
401
401
                               &write_lock_used)))
407
407
  unlock all tables locked for read.
408
408
*/
409
409
 
410
 
void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock)
 
410
void mysql_unlock_read_tables(THD *thd, DRIZZLE_LOCK *sql_lock)
411
411
{
412
412
  uint i,found;
413
413
 
483
483
                          effect is desired.
484
484
*/
485
485
 
486
 
void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table,
 
486
void mysql_lock_remove(THD *thd, DRIZZLE_LOCK *locked,TABLE *table,
487
487
                       bool always_unlock)
488
488
{
489
489
  if (always_unlock == true)
551
551
void mysql_lock_downgrade_write(THD *thd, TABLE *table,
552
552
                                thr_lock_type new_lock_type)
553
553
{
554
 
  MYSQL_LOCK *locked;
 
554
  DRIZZLE_LOCK *locked;
555
555
  TABLE *write_lock_used;
556
556
  if ((locked = get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK,
557
557
                              &write_lock_used)))
567
567
 
568
568
void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock)
569
569
{
570
 
  MYSQL_LOCK *locked;
 
570
  DRIZZLE_LOCK *locked;
571
571
  TABLE *write_lock_used;
572
572
 
573
573
  if ((locked= get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK,
595
595
 
596
596
bool mysql_lock_abort_for_thread(THD *thd, TABLE *table)
597
597
{
598
 
  MYSQL_LOCK *locked;
 
598
  DRIZZLE_LOCK *locked;
599
599
  TABLE *write_lock_used;
600
600
  bool result= false;
601
601
 
614
614
}
615
615
 
616
616
 
617
 
MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b)
 
617
DRIZZLE_LOCK *mysql_lock_merge(DRIZZLE_LOCK *a,DRIZZLE_LOCK *b)
618
618
{
619
 
  MYSQL_LOCK *sql_lock;
 
619
  DRIZZLE_LOCK *sql_lock;
620
620
  TABLE **table, **end_table;
621
621
 
622
 
  if (!(sql_lock= (MYSQL_LOCK*)
 
622
  if (!(sql_lock= (DRIZZLE_LOCK*)
623
623
        my_malloc(sizeof(*sql_lock)+
624
624
                  sizeof(THR_LOCK_DATA*)*(a->lock_count+b->lock_count)+
625
625
                  sizeof(TABLE*)*(a->table_count+b->table_count),MYF(MY_WME))))
681
681
TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle,
682
682
                                      TABLE_LIST *haystack)
683
683
{
684
 
  MYSQL_LOCK            *mylock;
 
684
  DRIZZLE_LOCK            *mylock;
685
685
  TABLE                 **lock_tables;
686
686
  TABLE                 *table;
687
687
  TABLE                 *table2;
791
791
  @param write_lock_used   Store pointer to last table with WRITE_ALLOW_WRITE
792
792
*/
793
793
 
794
 
static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
 
794
static DRIZZLE_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
795
795
                                 uint flags, TABLE **write_lock_used)
796
796
{
797
797
  uint i,tables,lock_count;
798
 
  MYSQL_LOCK *sql_lock;
 
798
  DRIZZLE_LOCK *sql_lock;
799
799
  THR_LOCK_DATA **locks, **locks_buf, **locks_start;
800
800
  TABLE **to, **table_buf;
801
801
 
819
819
    update the table values. So the second part of the array is copied
820
820
    from the first part immediately before calling thr_multi_lock().
821
821
  */
822
 
  if (!(sql_lock= (MYSQL_LOCK*)
 
822
  if (!(sql_lock= (DRIZZLE_LOCK*)
823
823
        my_malloc(sizeof(*sql_lock) +
824
824
                  sizeof(THR_LOCK_DATA*) * tables * 2 +
825
825
                  sizeof(table_ptr) * lock_count,