~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Monty
  • Date: 2008-10-02 05:41:33 UTC
  • mfrom: (398.1.10 codestyle)
  • Revision ID: mordred@scylla.inaugust.com-20081002054133-tyxv5bmqpazfaqqi
Merged up to 408 of stdint-includes-fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
288
288
         oldest_unused_share->next)
289
289
  {
290
290
    pthread_mutex_lock(&oldest_unused_share->mutex);
291
 
    VOID(hash_delete(&table_def_cache, (uchar*) oldest_unused_share));
 
291
    hash_delete(&table_def_cache, (uchar*) oldest_unused_share);
292
292
  }
293
293
 
294
294
  return(share);
519
519
  OPEN_TableList **start_list, *open_list;
520
520
  TableList table_list;
521
521
 
522
 
  VOID(pthread_mutex_lock(&LOCK_open));
 
522
  pthread_mutex_lock(&LOCK_open);
523
523
  memset(&table_list, 0, sizeof(table_list));
524
524
  start_list= &open_list;
525
525
  open_list=0;
569
569
    start_list= &(*start_list)->next;
570
570
    *start_list=0;
571
571
  }
572
 
  VOID(pthread_mutex_unlock(&LOCK_open));
 
572
  pthread_mutex_unlock(&LOCK_open);
573
573
  return(open_list);
574
574
}
575
575
 
582
582
{                                               // Free all structures
583
583
  free_io_cache(table);
584
584
  if (table->file)                              // Not true if name lock
585
 
    VOID(closefrm(table, 1));                   // close file
 
585
    closefrm(table, 1);                 // close file
586
586
  return;
587
587
}
588
588
 
651
651
  assert(thd || (!wait_for_refresh && !tables));
652
652
 
653
653
  if (!have_lock)
654
 
    VOID(pthread_mutex_lock(&LOCK_open));
 
654
    pthread_mutex_lock(&LOCK_open);
655
655
  if (!tables)
656
656
  {
657
657
    refresh_version++;                          // Force close of open tables
661
661
      if (hash_delete(&open_cache,(uchar*) unused_tables))
662
662
        printf("Warning: Couldn't delete open table from hash\n");
663
663
#else
664
 
      VOID(hash_delete(&open_cache,(uchar*) unused_tables));
 
664
      hash_delete(&open_cache,(uchar*) unused_tables);
665
665
#endif
666
666
    }
667
667
    /* Free table shares */
668
668
    while (oldest_unused_share->next)
669
669
    {
670
670
      pthread_mutex_lock(&oldest_unused_share->mutex);
671
 
      VOID(hash_delete(&table_def_cache, (uchar*) oldest_unused_share));
 
671
      hash_delete(&table_def_cache, (uchar*) oldest_unused_share);
672
672
    }
673
673
    if (wait_for_refresh)
674
674
    {
797
797
    }
798
798
  }
799
799
  if (!have_lock)
800
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
800
    pthread_mutex_unlock(&LOCK_open);
801
801
  if (wait_for_refresh)
802
802
  {
803
803
    pthread_mutex_lock(&thd->mysys_var->mutex);
826
826
  memset(&tmp, 0, sizeof(TableList));
827
827
 
828
828
  if (!have_lock)
829
 
    VOID(pthread_mutex_lock(&LOCK_open));
 
829
    pthread_mutex_lock(&LOCK_open);
830
830
 
831
831
  for (idx= 0; idx < table_def_cache.records; idx++)
832
832
  {
859
859
    result= close_cached_tables(thd, tables, true, false, false);
860
860
 
861
861
  if (!have_lock)
862
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
862
    pthread_mutex_unlock(&LOCK_open);
863
863
 
864
864
  if (if_wait_for_refresh)
865
865
  {
947
947
 
948
948
  safe_mutex_assert_not_owner(&LOCK_open);
949
949
 
950
 
  VOID(pthread_mutex_lock(&LOCK_open));
 
950
  pthread_mutex_lock(&LOCK_open);
951
951
 
952
952
  while (thd->open_tables)
953
953
    found_old_table|= close_thread_table(thd, &thd->open_tables);
955
955
 
956
956
  /* Free tables to hold down open files */
957
957
  while (open_cache.records > table_cache_size && unused_tables)
958
 
    VOID(hash_delete(&open_cache,(uchar*) unused_tables)); /* purecov: tested */
 
958
    hash_delete(&open_cache,(uchar*) unused_tables); /* purecov: tested */
959
959
  if (found_old_table)
960
960
  {
961
961
    /* Tell threads waiting for refresh that something has happened */
962
962
    broadcast_refresh();
963
963
  }
964
964
 
965
 
  VOID(pthread_mutex_unlock(&LOCK_open));
 
965
  pthread_mutex_unlock(&LOCK_open);
966
966
}
967
967
 
968
968
 
1090
1090
  if (table->needs_reopen_or_name_lock() ||
1091
1091
      thd->version != refresh_version || !table->db_stat)
1092
1092
  {
1093
 
    VOID(hash_delete(&open_cache,(uchar*) table));
 
1093
    hash_delete(&open_cache,(uchar*) table);
1094
1094
    found_old_table=1;
1095
1095
  }
1096
1096
  else
1646
1646
      /* Remove table from open_tables list. */
1647
1647
      *prev= list->next;
1648
1648
      /* Close table. */
1649
 
      VOID(hash_delete(&open_cache,(uchar*) list)); // Close table
 
1649
      hash_delete(&open_cache,(uchar*) list); // Close table
1650
1650
    }
1651
1651
    else
1652
1652
    {
1688
1688
  else
1689
1689
  {
1690
1690
    handlerton *table_type= table->s->db_type();
1691
 
    VOID(pthread_mutex_lock(&LOCK_open));
 
1691
    pthread_mutex_lock(&LOCK_open);
1692
1692
    /*
1693
1693
      unlink_open_table() also tells threads waiting for refresh or close
1694
1694
      that something has happened.
1695
1695
    */
1696
1696
    unlink_open_table(thd, table, false);
1697
1697
    quick_rm_table(table_type, db_name, table_name, 0);
1698
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
1698
    pthread_mutex_unlock(&LOCK_open);
1699
1699
  }
1700
1700
}
1701
1701
 
1944
1944
  uint key_length;
1945
1945
 
1946
1946
  key_length= (uint)(my_stpcpy(my_stpcpy(key, db) + 1, table_name) - key) + 1;
1947
 
  VOID(pthread_mutex_lock(&LOCK_open));
 
1947
  pthread_mutex_lock(&LOCK_open);
1948
1948
 
1949
1949
  if (hash_search(&open_cache, (uchar *)key, key_length))
1950
1950
  {
1951
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
1951
    pthread_mutex_unlock(&LOCK_open);
1952
1952
    *table= 0;
1953
1953
    return(false);
1954
1954
  }
1955
1955
  if (!(*table= table_cache_insert_placeholder(thd, key, key_length)))
1956
1956
  {
1957
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
1957
    pthread_mutex_unlock(&LOCK_open);
1958
1958
    return(true);
1959
1959
  }
1960
1960
  (*table)->open_placeholder= 1;
1961
1961
  (*table)->next= thd->open_tables;
1962
1962
  thd->open_tables= *table;
1963
 
  VOID(pthread_mutex_unlock(&LOCK_open));
 
1963
  pthread_mutex_unlock(&LOCK_open);
1964
1964
  return(false);
1965
1965
}
1966
1966
 
2227
2227
    on disk.
2228
2228
  */
2229
2229
 
2230
 
  VOID(pthread_mutex_lock(&LOCK_open));
 
2230
  pthread_mutex_lock(&LOCK_open);
2231
2231
 
2232
2232
  /*
2233
2233
    If it's the first table from a list of tables used in a query,
2245
2245
    /* Someone did a refresh while thread was opening tables */
2246
2246
    if (refresh)
2247
2247
      *refresh=1;
2248
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
2248
    pthread_mutex_unlock(&LOCK_open);
2249
2249
    return(0);
2250
2250
  }
2251
2251
 
2305
2305
      /* Avoid self-deadlocks by detecting self-dependencies. */
2306
2306
      if (table->open_placeholder && table->in_use == thd)
2307
2307
      {
2308
 
        VOID(pthread_mutex_unlock(&LOCK_open));
 
2308
        pthread_mutex_unlock(&LOCK_open);
2309
2309
        my_error(ER_UPDATE_TABLE_USED, MYF(0), table->s->table_name.str);
2310
2310
        return(0);
2311
2311
      }
2346
2346
      }
2347
2347
      else
2348
2348
      {
2349
 
        VOID(pthread_mutex_unlock(&LOCK_open));
 
2349
        pthread_mutex_unlock(&LOCK_open);
2350
2350
      }
2351
2351
      /*
2352
2352
        There is a refresh in progress for this table.
2376
2376
    int error;
2377
2377
    /* Free cache if too big */
2378
2378
    while (open_cache.records > table_cache_size && unused_tables)
2379
 
      VOID(hash_delete(&open_cache,(uchar*) unused_tables)); /* purecov: tested */
 
2379
      hash_delete(&open_cache,(uchar*) unused_tables); /* purecov: tested */
2380
2380
 
2381
2381
    if (table_list->create)
2382
2382
    {
2384
2384
 
2385
2385
      if (check_if_table_exists(thd, table_list, &exists))
2386
2386
      {
2387
 
        VOID(pthread_mutex_unlock(&LOCK_open));
 
2387
        pthread_mutex_unlock(&LOCK_open);
2388
2388
        return(NULL);
2389
2389
      }
2390
2390
 
2395
2395
        */
2396
2396
        if (!(table= table_cache_insert_placeholder(thd, key, key_length)))
2397
2397
        {
2398
 
          VOID(pthread_mutex_unlock(&LOCK_open));
 
2398
          pthread_mutex_unlock(&LOCK_open);
2399
2399
          return(NULL);
2400
2400
        }
2401
2401
        /*
2406
2406
        table->open_placeholder= 1;
2407
2407
        table->next= thd->open_tables;
2408
2408
        thd->open_tables= table;
2409
 
        VOID(pthread_mutex_unlock(&LOCK_open));
 
2409
        pthread_mutex_unlock(&LOCK_open);
2410
2410
        return(table);
2411
2411
      }
2412
2412
      /* Table exists. Let us try to open it. */
2415
2415
    /* make a new table */
2416
2416
    if (!(table=(Table*) my_malloc(sizeof(*table),MYF(MY_WME))))
2417
2417
    {
2418
 
      VOID(pthread_mutex_unlock(&LOCK_open));
 
2418
      pthread_mutex_unlock(&LOCK_open);
2419
2419
      return(NULL);
2420
2420
    }
2421
2421
 
2424
2424
    if (error > 0)
2425
2425
    {
2426
2426
      my_free((uchar*)table, MYF(0));
2427
 
      VOID(pthread_mutex_unlock(&LOCK_open));
 
2427
      pthread_mutex_unlock(&LOCK_open);
2428
2428
      return(NULL);
2429
2429
    }
2430
2430
    if (error < 0)
2431
2431
    {
2432
2432
      my_free((uchar*)table, MYF(0));
2433
 
      VOID(pthread_mutex_unlock(&LOCK_open));
 
2433
      pthread_mutex_unlock(&LOCK_open);
2434
2434
      return(0); // VIEW
2435
2435
    }
2436
 
    VOID(my_hash_insert(&open_cache,(uchar*) table));
 
2436
    my_hash_insert(&open_cache,(uchar*) table);
2437
2437
  }
2438
2438
 
2439
 
  VOID(pthread_mutex_unlock(&LOCK_open));
 
2439
  pthread_mutex_unlock(&LOCK_open);
2440
2440
  if (refresh)
2441
2441
  {
2442
2442
    table->next=thd->open_tables;               /* Link into simple list */
2560
2560
  tmp.prev=             table->prev;
2561
2561
 
2562
2562
  if (table->file)
2563
 
    VOID(closefrm(table, 1));           // close file, free everything
 
2563
    closefrm(table, 1);         // close file, free everything
2564
2564
 
2565
2565
  *table= tmp;
2566
2566
  table->default_column_bitmaps();
2703
2703
    if (!tables || (!db_stat && reopen_table(table)))
2704
2704
    {
2705
2705
      my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
2706
 
      VOID(hash_delete(&open_cache,(uchar*) table));
 
2706
      hash_delete(&open_cache,(uchar*) table);
2707
2707
      error=1;
2708
2708
    }
2709
2709
    else
2968
2968
      else
2969
2969
      {
2970
2970
        /* We already have a name lock, remove copy */
2971
 
        VOID(hash_delete(&open_cache,(uchar*) table));
 
2971
        hash_delete(&open_cache,(uchar*) table);
2972
2972
      }
2973
2973
    }
2974
2974
    else
6238
6238
          So we hide error messages which happnes during deleting of these
6239
6239
          files(MYF(0)).
6240
6240
        */
6241
 
        VOID(my_delete(filePath, MYF(0))); 
 
6241
        my_delete(filePath, MYF(0)); 
6242
6242
      }
6243
6243
    }
6244
6244
    my_dirend(dirp);
6280
6280
    }
6281
6281
  }
6282
6282
  while (unused_tables && !unused_tables->s->version)
6283
 
    VOID(hash_delete(&open_cache,(uchar*) unused_tables));
 
6283
    hash_delete(&open_cache,(uchar*) unused_tables);
6284
6284
}
6285
6285
 
6286
6286
 
6378
6378
        result= result || (flags & RTFC_OWNED_BY_THD_FLAG);
6379
6379
    }
6380
6380
    while (unused_tables && !unused_tables->s->version)
6381
 
      VOID(hash_delete(&open_cache,(uchar*) unused_tables));
 
6381
      hash_delete(&open_cache,(uchar*) unused_tables);
6382
6382
 
6383
6383
    /* Remove table from table definition cache if it's not in use */
6384
6384
    if ((share= (TABLE_SHARE*) hash_search(&table_def_cache,(uchar*) key,
6388
6388
      if (share->ref_count == 0)
6389
6389
      {
6390
6390
        pthread_mutex_lock(&share->mutex);
6391
 
        VOID(hash_delete(&table_def_cache, (uchar*) share));
 
6391
        hash_delete(&table_def_cache, (uchar*) share);
6392
6392
      }
6393
6393
    }
6394
6394