kcplantdb.h   kcplantdb.h 
skipping to change at line 150 skipping to change at line 150
* @param visitor a visitor object. * @param visitor a visitor object.
* @param writable true for writable operation, or false for read-only operation. * @param writable true for writable operation, or false for read-only operation.
* @param step true to move the cursor to the next record, or false for no move. * @param step true to move the cursor to the next record, or false for no move.
* @return true on success, or false on failure. * @return true on success, or false on failure.
* @note The operation for each record is performed atomically and othe r threads accessing * @note The operation for each record is performed atomically and othe r threads accessing
* the same record are blocked. To avoid deadlock, any explicit databa se operation must not * the same record are blocked. To avoid deadlock, any explicit databa se operation must not
* be performed in this function. * be performed in this function.
*/ */
bool accept(Visitor* visitor, bool writable = true, bool step = false) { bool accept(Visitor* visitor, bool writable = true, bool step = false) {
_assert_(visitor); _assert_(visitor);
db_->mlock_.lock_reader(); bool wrlock = writable && (db_->tran_ || db_->autotran_);
if (wrlock) {
db_->mlock_.lock_writer();
} else {
db_->mlock_.lock_reader();
}
if (db_->omode_ == 0) { if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened"); db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
db_->mlock_.unlock(); db_->mlock_.unlock();
return false; return false;
} }
if (writable && !(db_->writer_)) { if (writable && !(db_->writer_)) {
db_->set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); db_->set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
db_->mlock_.unlock(); db_->mlock_.unlock();
return false; return false;
} }
if (!kbuf_) { if (!kbuf_) {
db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); db_->set_error(_KCCODELINE_, Error::NOREC, "no record");
db_->mlock_.unlock(); db_->mlock_.unlock();
return false; return false;
} }
bool err = false; bool err = false;
bool hit = false; bool hit = false;
if (lid_ > 0 && !accept_spec(visitor, writable, step, &hit)) err = tr ue; if (lid_ > 0 && !accept_spec(visitor, writable, step, &hit)) err = tr ue;
if (!err && !hit) { if (!err && !hit) {
db_->mlock_.unlock(); if (!wrlock) {
db_->mlock_.lock_writer(); db_->mlock_.unlock();
db_->mlock_.lock_writer();
}
if (kbuf_) { if (kbuf_) {
bool retry = true; bool retry = true;
while (!err && retry) { while (!err && retry) {
if (!accept_atom(visitor, step, &retry)) err = true; if (!accept_atom(visitor, step, &retry)) err = true;
} }
} else { } else {
db_->set_error(_KCCODELINE_, Error::NOREC, "no record"); db_->set_error(_KCCODELINE_, Error::NOREC, "no record");
err = true; err = true;
} }
} }
skipping to change at line 965 skipping to change at line 972
* @param ksiz the size of the key region. * @param ksiz the size of the key region.
* @param visitor a visitor object. * @param visitor a visitor object.
* @param writable true for writable operation, or false for read-only op eration. * @param writable true for writable operation, or false for read-only op eration.
* @return true on success, or false on failure. * @return true on success, or false on failure.
* @note The operation for each record is performed atomically and other threads accessing the * @note The operation for each record is performed atomically and other threads accessing the
* same record are blocked. To avoid deadlock, any explicit database ope ration must not be * same record are blocked. To avoid deadlock, any explicit database ope ration must not be
* performed in this function. * performed in this function.
*/ */
bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writabl e = true) { bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writabl e = true) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && visitor); _assert_(kbuf && ksiz <= MEMMAXSIZ && visitor);
mlock_.lock_reader(); bool wrlock = writable && (tran_ || autotran_);
if (wrlock) {
mlock_.lock_writer();
} else {
mlock_.lock_reader();
}
if (omode_ == 0) { if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened"); set_error(_KCCODELINE_, Error::INVALID, "not opened");
mlock_.unlock(); mlock_.unlock();
return false; return false;
} }
if (writable && !writer_) { if (writable && !writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied"); set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
mlock_.unlock(); mlock_.unlock();
return false; return false;
} }
skipping to change at line 1018 skipping to change at line 1030
bool flush = false; bool flush = false;
bool err = false; bool err = false;
int64_t id = node->id; int64_t id = node->id;
if (atran && !reorg && !fix_auto_transaction_leaf(node)) err = true; if (atran && !reorg && !fix_auto_transaction_leaf(node)) err = true;
if (cusage_ > pccap_) { if (cusage_ > pccap_) {
int32_t idx = id % SLOTNUM; int32_t idx = id % SLOTNUM;
LeafSlot* lslot = lslots_ + idx; LeafSlot* lslot = lslots_ + idx;
if (!clean_leaf_cache_part(lslot)) err = true; if (!clean_leaf_cache_part(lslot)) err = true;
flush = true; flush = true;
} }
mlock_.unlock();
if (reorg) { if (reorg) {
mlock_.lock_writer(); if (!wrlock) {
mlock_.unlock();
mlock_.lock_writer();
}
node = search_tree(link, false, hist, &hnum); node = search_tree(link, false, hist, &hnum);
if (node) { if (node) {
if (!reorganize_tree(node, hist, hnum)) err = true; if (!reorganize_tree(node, hist, hnum)) err = true;
if (atran && !tran_ && !fix_auto_transaction_tree()) err = true; if (atran && !tran_ && !fix_auto_transaction_tree()) err = true;
} }
mlock_.unlock(); mlock_.unlock();
} else if (flush) { } else if (flush) {
if (!wrlock) {
mlock_.unlock();
mlock_.lock_writer();
}
int32_t idx = id % SLOTNUM; int32_t idx = id % SLOTNUM;
LeafSlot* lslot = lslots_ + idx; LeafSlot* lslot = lslots_ + idx;
mlock_.lock_writer();
if (!flush_leaf_cache_part(lslot)) err = true; if (!flush_leaf_cache_part(lslot)) err = true;
InnerSlot* islot = islots_ + idx; InnerSlot* islot = islots_ + idx;
if (islot->warm->count() > lslot->warm->count() + lslot->hot->count() + 1 && if (islot->warm->count() > lslot->warm->count() + lslot->hot->count() + 1 &&
!flush_inner_cache_part(islot)) err = true; !flush_inner_cache_part(islot)) err = true;
mlock_.unlock(); mlock_.unlock();
} else {
mlock_.unlock();
} }
if (rbuf != rstack) delete[] rbuf; if (rbuf != rstack) delete[] rbuf;
if (lbuf != lstack) delete[] lbuf; if (lbuf != lstack) delete[] lbuf;
if (async) { if (async) {
mlock_.lock_writer(); mlock_.lock_writer();
if (!fix_auto_synchronization()) err = true; if (!fix_auto_synchronization()) err = true;
mlock_.unlock(); mlock_.unlock();
} }
return !err; return !err;
} }
 End of changes. 8 change blocks. 
7 lines changed or deleted 26 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/