~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_keycache.c

  • Committer: Monty Taylor
  • Date: 2008-07-02 14:35:48 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: monty@inaugust.com-20080702143548-onj30ry0sugr01uw
Removed all references to THREAD.

Show diffs side-by-side

added added

removed removed

Lines of Context:
221
221
#define FLUSH_CACHE         2000            /* sort this many blocks at once */
222
222
 
223
223
static int flush_all_key_blocks(KEY_CACHE *keycache);
224
 
#ifdef THREAD
225
224
static void wait_on_queue(KEYCACHE_WQUEUE *wqueue,
226
225
                          pthread_mutex_t *mutex);
227
226
static void release_whole_queue(KEYCACHE_WQUEUE *wqueue);
228
 
#else
229
 
#define wait_on_queue(wqueue, mutex)    do {} while (0)
230
 
#define release_whole_queue(wqueue)     do {} while (0)
231
 
#endif
232
227
static void free_block(KEY_CACHE *keycache, BLOCK_LINK *block);
233
228
#if !defined(DBUG_OFF)
234
229
static void test_key_cache(KEY_CACHE *keycache,
281
276
#endif /* defined(KEYCACHE_DEBUG_LOG) && defined(KEYCACHE_DEBUG) */
282
277
 
283
278
#if defined(KEYCACHE_DEBUG) || !defined(DBUG_OFF)
284
 
#ifdef THREAD
285
279
static long keycache_thread_id;
286
280
#define KEYCACHE_THREAD_TRACE(l)                                              \
287
281
             KEYCACHE_DBUG_PRINT(l,("|thread %ld",keycache_thread_id))
293
287
 
294
288
#define KEYCACHE_THREAD_TRACE_END(l)                                          \
295
289
            KEYCACHE_DBUG_PRINT(l,("]thread %ld",keycache_thread_id))
296
 
#else /* THREAD */
297
 
#define KEYCACHE_THREAD_TRACE(l)        KEYCACHE_DBUG_PRINT(l,(""))
298
 
#define KEYCACHE_THREAD_TRACE_BEGIN(l)  KEYCACHE_DBUG_PRINT(l,(""))
299
 
#define KEYCACHE_THREAD_TRACE_END(l)    KEYCACHE_DBUG_PRINT(l,(""))
300
 
#endif /* THREAD */
301
290
#else
302
291
#define KEYCACHE_THREAD_TRACE_BEGIN(l)
303
292
#define KEYCACHE_THREAD_TRACE_END(l)
576
565
 
577
566
  keycache_pthread_mutex_lock(&keycache->cache_lock);
578
567
 
579
 
#ifdef THREAD
580
568
  /*
581
569
    We may need to wait for another thread which is doing a resize
582
570
    already. This cannot happen in the MySQL server though. It allows
589
577
    wait_on_queue(&keycache->resize_queue, &keycache->cache_lock);
590
578
    /* purecov: end */
591
579
  }
592
 
#endif
593
580
 
594
581
  /*
595
582
    Mark the operation in progress. This blocks other threads from doing
618
605
    keycache->resize_in_flush= 0;
619
606
  }
620
607
 
621
 
#ifdef THREAD
622
608
  /*
623
609
    Some direct read/write operations (bypassing the cache) may still be
624
610
    unfinished. Wait until they are done. If the key cache can be used,
632
618
  */
633
619
  while (keycache->cnt_for_resize_op)
634
620
    wait_on_queue(&keycache->waiting_for_resize_cnt, &keycache->cache_lock);
635
 
#else
636
 
  KEYCACHE_DBUG_ASSERT(keycache->cnt_for_resize_op == 0);
637
 
#endif
638
621
 
639
622
  /*
640
623
    Free old cache structures, allocate new structures, and initialize
768
751
} /* end_key_cache */
769
752
 
770
753
 
771
 
#ifdef THREAD
772
 
 
773
754
/*
774
755
  Link a thread into double-linked queue of waiting threads.
775
756
 
949
930
  wqueue->last_thread= NULL;
950
931
}
951
932
 
952
 
#endif /* THREAD */
953
 
 
954
933
 
955
934
/*
956
935
  Unlink a block from the chain of dirty/clean blocks
1122
1101
  DBUG_ASSERT(block->prev_changed && *block->prev_changed == block);
1123
1102
  DBUG_ASSERT(!block->next_used);
1124
1103
  DBUG_ASSERT(!block->prev_used);
1125
 
#ifdef THREAD
1126
1104
  if (!hot && keycache->waiting_for_block.last_thread)
1127
1105
  {
1128
1106
    /* Signal that in the LRU warm sub-chain an available block has appeared */
1182
1160
#endif
1183
1161
    return;
1184
1162
  }
1185
 
#else /* THREAD */
1186
 
  KEYCACHE_DBUG_ASSERT(! (!hot && keycache->waiting_for_block.last_thread));
1187
 
      /* Condition not transformed using DeMorgan, to keep the text identical */
1188
 
#endif /* THREAD */
1189
1163
  pins= hot ? &keycache->used_ins : &keycache->used_last;
1190
1164
  ins= *pins;
1191
1165
  if (ins)
1403
1377
  DBUG_ASSERT(!block->next_used);
1404
1378
  DBUG_ASSERT(!block->prev_used);
1405
1379
  DBUG_ASSERT(block->hash_link->requests);
1406
 
#ifdef THREAD
1407
1380
  if (! --block->hash_link->requests && block->condvar)
1408
1381
    keycache_pthread_cond_signal(block->condvar);
1409
 
#else
1410
 
  --block->hash_link->requests;
1411
 
#endif
1412
1382
}
1413
1383
 
1414
1384
 
1420
1390
static void wait_for_readers(KEY_CACHE *keycache,
1421
1391
                             BLOCK_LINK *block)
1422
1392
{
1423
 
#ifdef THREAD
1424
1393
  struct st_my_thread_var *thread= my_thread_var;
1425
1394
  DBUG_ASSERT(block->status & (BLOCK_READ | BLOCK_IN_USE));
1426
1395
  DBUG_ASSERT(!(block->status & (BLOCK_ERROR | BLOCK_IN_FLUSH |
1443
1412
    keycache_pthread_cond_wait(&thread->suspend, &keycache->cache_lock);
1444
1413
    block->condvar= NULL;
1445
1414
  }
1446
 
#else
1447
 
  KEYCACHE_DBUG_ASSERT(block->hash_link->requests == 0);
1448
 
#endif
1449
1415
}
1450
1416
 
1451
1417
 
1475
1441
  if ((*hash_link->prev= hash_link->next))
1476
1442
    hash_link->next->prev= hash_link->prev;
1477
1443
  hash_link->block= NULL;
1478
 
#ifdef THREAD
1479
1444
  if (keycache->waiting_for_hash_link.last_thread)
1480
1445
  {
1481
1446
    /* Signal that a free hash link has appeared */
1511
1476
              hash_link);
1512
1477
    return;
1513
1478
  }
1514
 
#else /* THREAD */
1515
 
  KEYCACHE_DBUG_ASSERT(! (keycache->waiting_for_hash_link.last_thread));
1516
 
#endif /* THREAD */
1517
1479
  hash_link->next= keycache->free_hash_list;
1518
1480
  keycache->free_hash_list= hash_link;
1519
1481
}
1578
1540
    }
1579
1541
    else
1580
1542
    {
1581
 
#ifdef THREAD
1582
1543
      /* Wait for a free hash link */
1583
1544
      struct st_my_thread_var *thread= my_thread_var;
1584
1545
      KEYCACHE_PAGE page;
1592
1553
      keycache_pthread_cond_wait(&thread->suspend,
1593
1554
                                 &keycache->cache_lock);
1594
1555
      thread->opt_info= NULL;
1595
 
#else
1596
 
      KEYCACHE_DBUG_ASSERT(0);
1597
 
#endif
1598
1556
      goto restart;
1599
1557
    }
1600
1558
    hash_link->file= file;
2082
2040
          from the LRU ring.
2083
2041
        */
2084
2042
 
2085
 
#ifdef THREAD
2086
2043
        if (! keycache->used_last)
2087
2044
        {
2088
2045
          /*
2115
2072
          DBUG_ASSERT(!hash_link->block->next_used);
2116
2073
          DBUG_ASSERT(!hash_link->block->prev_used);
2117
2074
        }
2118
 
#else
2119
 
        KEYCACHE_DBUG_ASSERT(keycache->used_last);
2120
 
#endif
2121
2075
        /*
2122
2076
          If we waited above, hash_link->block has been assigned by
2123
2077
          link_block(). Otherwise it is still NULL. In the latter case
2575
2529
      set_if_smaller(read_length, keycache->key_cache_block_size-offset);
2576
2530
      KEYCACHE_DBUG_ASSERT(read_length > 0);
2577
2531
 
2578
 
#ifndef THREAD
2579
 
      if (block_length > keycache->key_cache_block_size || offset)
2580
 
        return_buffer=0;
2581
 
#endif
2582
 
 
2583
2532
      /* Request the cache block that matches file/pos. */
2584
2533
      keycache->global_cache_r_requests++;
2585
2534
      block=find_key_block(keycache, file, filepos, level, 0, &page_st);
2629
2578
      /* block status may have added BLOCK_ERROR in the above 'if'. */
2630
2579
      if (!((status= block->status) & BLOCK_ERROR))
2631
2580
      {
2632
 
#ifndef THREAD
2633
 
        if (! return_buffer)
2634
 
#endif
2635
2581
        {
2636
2582
          DBUG_ASSERT(block->status & (BLOCK_READ | BLOCK_IN_USE));
2637
2583
#if !defined(SERIALIZED_READ_FROM_CACHE)
2665
2611
        break;
2666
2612
      }
2667
2613
 
2668
 
#ifndef THREAD
2669
 
      /* This is only true if we where able to read everything in one block */
2670
 
      if (return_buffer)
2671
 
        DBUG_RETURN(block->buffer);
2672
 
#endif
2673
2614
  next_block:
2674
2615
      buff+= read_length;
2675
2616
      filepos+= read_length+offset;