did away with memoization for rle_ (cost of mutex was too high). pthread_[get|set]specific does not provide enough keys to make sense as an alternative

This commit is contained in:
Sears Russell 2008-11-27 00:08:59 +00:00
parent e22c35a1b5
commit 41460d041a
2 changed files with 27 additions and 17 deletions

View file

@ -59,19 +59,18 @@ template <class TYPE,class COUNT_TYPE>
inline TYPE *
Rle<TYPE,COUNT_TYPE>::recordRead(int xid, slot_index_t slot, byte* exceptions,
TYPE * scratch) {
pthread_mutex_lock(&last_mut_);
block_index_t n = nth_block_ptr(last_)->index <= slot ? last_ : 0;
// intptr_t last_ = (intptr_t)pthread_getspecific(last_key_);
block_index_t n = 0; // nth_block_ptr(last_)->index <= slot ? last_ : 0;
do {
triple_t * t = nth_block_ptr(n);
if (t->index <= slot && t->index + t->copies > slot) {
*scratch = t->data;
last_ = n;
pthread_mutex_unlock(&last_mut_);
// last_ = n;
// pthread_setspecific(last_key_, (const void*)last_);
return scratch;
}
n++;
} while (n < *block_count_ptr());
pthread_mutex_unlock(&last_mut_);
return 0;
}
#ifndef COMPRESSION_BINARY_FIND

View file

@ -46,20 +46,26 @@ class Rle {
recordFind(int xid, slot_index_t start, slot_index_t stop,
byte *exceptions, TYPE value,
std::pair<slot_index_t,slot_index_t>& scratch);
/**
void init_getspecific() {
// int ret =pthread_key_create(&last_key_, 0);
// assert(!ret);
}
/**
This constructor initializes a new Rle region.
@param xid the transaction that created the new region. Passing
in a XID implies that the page has just been allocated.
@param mem A pointer to the buffer manager's copy of the Rle page.
*/
Rle(int xid, void * mem): mem_(mem), last_(0) {
Rle(int xid, void * mem): mem_(mem) {
*block_count_ptr() = 1;
triple_t * n = last_block_ptr();
n->index = 0;
n->copies = 0;
n->data = 0;
pthread_mutex_init(&last_mut_,0);
init_getspecific();
// pthread_mutex_init(&last_mut_,0);
}
inline slot_index_t recordCount() {
triple_t *n = last_block_ptr();
@ -69,16 +75,16 @@ class Rle {
This constructor is called when existing RLE data is read from
disk.
*/
Rle(void * mem): mem_(mem), last_(0) {
pthread_mutex_init(&last_mut_,0);
Rle(void * mem): mem_(mem) {
init_getspecific();
}
Rle() : mem_(0), last_(0) {
pthread_mutex_init(&last_mut_,0);
Rle() : mem_(0) {
init_getspecific();
}
~Rle() {
pthread_mutex_destroy(&last_mut_);
// pthread_key_delete(last_key_);
}
/**
@see For::bytes_used();
@ -89,7 +95,9 @@ class Rle {
inline void init_mem(void * mem) {
mem_=mem;
last_=0;
// pthread_key_delete(last_key_); // need to set to zero in all threads....
// int ret = pthread_key_create(&last_key_,0);
// assert(!ret);
*block_count_ptr() = 1;
triple_t * n = nth_block_ptr(0);
n->index = 0;
@ -99,7 +107,9 @@ class Rle {
inline void mem(void * mem) {
mem_=mem;
last_=0;
// pthread_key_delete(last_key_); // need to set to zero in all threads....
// int ret = pthread_key_create(&last_key_,0);
// assert(!ret);
}
private:
inline TYPE offset() { return nth_block_ptr(0)->dat; }
@ -133,8 +143,9 @@ class Rle {
return nth_block_ptr(*block_count_ptr());
}
void * mem_;
block_index_t last_;
pthread_mutex_t last_mut_;
// block_index_t last_;
// pthread_mutex_t last_mut_;
// pthread_key_t last_key_;
};
} // namespace rose