summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Dbx_kv/src/dbintf.h1
-rw-r--r--plugins/Dbx_kv/src/dbmodulechain.cpp19
-rw-r--r--plugins/Dbx_kyoto/src/commonheaders.h28
-rw-r--r--plugins/Dbx_kyoto/src/dbevents.cpp202
-rw-r--r--plugins/Dbx_kyoto/src/dbintf.h1
-rw-r--r--plugins/Dbx_kyoto/src/dbmodulechain.cpp21
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kccachedb.h114
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kcdbext.h28
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kcdirdb.h130
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kchashdb.h108
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kcplantdb.h148
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kcprotodb.h82
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kcstashdb.h101
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kctextdb.h56
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kcthread.cc1151
-rw-r--r--plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h375
-rw-r--r--plugins/Dbx_mdb/src/dbintf.h1
-rw-r--r--plugins/Dbx_mdb/src/dbmodulechain.cpp9
18 files changed, 417 insertions, 2158 deletions
diff --git a/plugins/Dbx_kv/src/dbintf.h b/plugins/Dbx_kv/src/dbintf.h
index 4a65db7fda..b9decbc0c3 100644
--- a/plugins/Dbx_kv/src/dbintf.h
+++ b/plugins/Dbx_kv/src/dbintf.h
@@ -262,6 +262,7 @@ protected:
HANDLE hEventAddedEvent, hEventDeletedEvent, hEventFilterAddedEvent;
MCONTACT m_hLastCachedContact;
int m_maxModuleID;
+ ModuleName *m_lastmn;
void AddToList(char *name, DWORD ofs);
DWORD FindExistingModuleNameOfs(const char *szName);
diff --git a/plugins/Dbx_kv/src/dbmodulechain.cpp b/plugins/Dbx_kv/src/dbmodulechain.cpp
index d1491fc68a..2f6b71e401 100644
--- a/plugins/Dbx_kv/src/dbmodulechain.cpp
+++ b/plugins/Dbx_kv/src/dbmodulechain.cpp
@@ -70,10 +70,15 @@ int CDbxKV::InitModuleNames(void)
DWORD CDbxKV::FindExistingModuleNameOfs(const char *szName)
{
ModuleName mn = { (char*)szName, 0 };
+ if (m_lastmn && !strcmp(mn.name, m_lastmn->name))
+ return m_lastmn->ofs;
int index = m_lMods.getIndex(&mn);
- if (index != -1)
- return m_lMods[index]->ofs;
+ if (index != -1) {
+ ModuleName *pmn = m_lMods[index];
+ m_lastmn = pmn;
+ return pmn->ofs;
+ }
return 0;
}
@@ -112,10 +117,16 @@ DWORD CDbxKV::GetModuleNameOfs(const char *szName)
char* CDbxKV::GetModuleNameByOfs(DWORD ofs)
{
+ if (m_lastmn && m_lastmn->ofs == ofs)
+ return m_lastmn->name;
+
ModuleName mn = { NULL, ofs };
int index = m_lOfs.getIndex(&mn);
- if (index != -1)
- return m_lOfs[index]->name;
+ if (index != -1) {
+ ModuleName *pmn = m_lOfs[index];
+ m_lastmn = pmn;
+ return pmn->name;
+ }
return NULL;
}
diff --git a/plugins/Dbx_kyoto/src/commonheaders.h b/plugins/Dbx_kyoto/src/commonheaders.h
index a8a6e11b8b..27a0a54bd8 100644
--- a/plugins/Dbx_kyoto/src/commonheaders.h
+++ b/plugins/Dbx_kyoto/src/commonheaders.h
@@ -54,6 +54,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern HINSTANCE g_hInst;
extern LIST<CDbxKyoto> g_Dbs;
+struct VisitorCopy : public TreeDB::Visitor
+{
+ __forceinline explicit VisitorCopy() : kbuf_(NULL), ksiz_(0) {}
+
+ const char* visit_full(const char* kbuf, size_t ksiz, const char* vbuf, size_t vsiz, size_t* sp)
+ {
+ kbuf_ = kbuf;
+ ksiz_ = ksiz;
+ return NOP;
+ }
+ const char* kbuf_;
+ size_t ksiz_;
+};
+
+struct VisitorCopyRec : public TreeDB::Visitor
+{
+ __forceinline explicit VisitorCopyRec() : vbuf_(NULL), vsiz_(0) {}
+
+ const char* visit_full(const char* kbuf, size_t ksiz, const char* vbuf, size_t vsiz, size_t* sp)
+ {
+ vbuf_ = vbuf;
+ vsiz_ = vsiz;
+ return NOP;
+ }
+ const char* vbuf_;
+ size_t vsiz_;
+};
+
class cursor_ptr
{
TreeDB::Cursor *m_cursor;
diff --git a/plugins/Dbx_kyoto/src/dbevents.cpp b/plugins/Dbx_kyoto/src/dbevents.cpp
index cb38afcf26..34d00eb17c 100644
--- a/plugins/Dbx_kyoto/src/dbevents.cpp
+++ b/plugins/Dbx_kyoto/src/dbevents.cpp
@@ -76,28 +76,31 @@ STDMETHODIMP_(MEVENT) CDbxKyoto::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
dbe.flags |= DBEF_ENCRYPTED;
}
}
+ DWORD dwEventId;
+ {
+ mir_cslock lck(m_csDbAccess);
+ dwEventId = ++m_dwMaxEventId;
- DWORD dwEventId = ++m_dwMaxEventId;
-
- BYTE *pDest = (BYTE*)_alloca(sizeof(DBEvent) + dbe.cbBlob);
- memcpy(pDest, &dbe, sizeof(DBEvent));
- memcpy(pDest + sizeof(DBEvent), pBlob, dbe.cbBlob);
- m_dbEvents.set((LPCSTR)&dwEventId, sizeof(int), (LPCSTR)pDest, sizeof(DBEvent) + dbe.cbBlob);
+ BYTE *pDest = (BYTE*)_alloca(sizeof(DBEvent) + dbe.cbBlob);
+ memcpy(pDest, &dbe, sizeof(DBEvent));
+ memcpy(pDest + sizeof(DBEvent), pBlob, dbe.cbBlob);
+ m_dbEvents.set((LPCSTR)&dwEventId, sizeof(int), (LPCSTR)pDest, sizeof(DBEvent) + dbe.cbBlob);
- // add a sorting key
- DBEventSortingKey key2 = { contactID, dbe.timestamp, dwEventId };
- m_dbEventsSort.set((LPCSTR)&key2, sizeof(key2), "", 1);
+ // add a sorting key
+ DBEventSortingKey key2 = { contactID, dbe.timestamp, dwEventId };
+ m_dbEventsSort.set((LPCSTR)&key2, sizeof(key2), "", 1);
- cc->Advance(dwEventId, dbe);
- m_dbContacts.set((LPCSTR)&contactID, sizeof(int), (LPCSTR)&cc->dbc, sizeof(DBContact));
+ cc->Advance(dwEventId, dbe);
+ m_dbContacts.set((LPCSTR)&contactID, sizeof(int), (LPCSTR)&cc->dbc, sizeof(DBContact));
- // insert an event into a sub's history too
- if (ccSub != NULL) {
- key2.dwContactId = ccSub->contactID;
- m_dbEventsSort.set((LPCSTR)&key2, sizeof(key2), "", 1);
+ // insert an event into a sub's history too
+ if (ccSub != NULL) {
+ key2.dwContactId = ccSub->contactID;
+ m_dbEventsSort.set((LPCSTR)&key2, sizeof(key2), "", 1);
- ccSub->Advance(dwEventId, dbe);
- m_dbContacts.set((LPCSTR)&ccSub->contactID, sizeof(int), (LPCSTR)&ccSub->dbc, sizeof(DBContact));
+ ccSub->Advance(dwEventId, dbe);
+ m_dbContacts.set((LPCSTR)&ccSub->contactID, sizeof(int), (LPCSTR)&ccSub->dbc, sizeof(DBContact));
+ }
}
// Notify only in safe mode or on really new events
@@ -115,27 +118,32 @@ STDMETHODIMP_(BOOL) CDbxKyoto::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
if (cc == NULL || cc->dbc.dwEventCount == 0)
return 1;
- DBEvent dbe;
- if (-1 == m_dbEvents.get((LPCSTR)&hDbEvent, sizeof(MEVENT), (LPSTR)&dbe, sizeof(dbe)))
- return 1;
-
- DWORD dwSavedContact = dbe.contactID;
- DBEventSortingKey key2 = { contactID, dbe.timestamp, hDbEvent };
- m_dbEvents.remove((LPCSTR)&hDbEvent, sizeof(MEVENT));
+ DBEvent *dbe;
+ {
+ mir_cslock lck(m_csDbAccess);
+ VisitorCopyRec visitor;
+ if (!m_dbEvents.accept((LPCSTR)&hDbEvent, sizeof(MEVENT), &visitor, false))
+ return 1;
- // remove a sorting key
- m_dbEventsSort.remove((LPCSTR)&key2, sizeof(key2));
+ dbe = (DBEvent*)visitor.vbuf_;
+ DWORD dwSavedContact = dbe->contactID;
+ DBEventSortingKey key2 = { contactID, dbe->timestamp, hDbEvent };
+ m_dbEvents.remove((LPCSTR)&hDbEvent, sizeof(MEVENT));
- // remove a sub's history entry too
- if (contactID != dwSavedContact) {
- key2.dwContactId = dwSavedContact;
+ // remove a sorting key
m_dbEventsSort.remove((LPCSTR)&key2, sizeof(key2));
- }
- // update a contact
- cc->dbc.dwEventCount--;
- if (cc->dbc.dwFirstUnread == hDbEvent)
- FindNextUnread(cc, key2);
+ // remove a sub's history entry too
+ if (contactID != dwSavedContact) {
+ key2.dwContactId = dwSavedContact;
+ m_dbEventsSort.remove((LPCSTR)&key2, sizeof(key2));
+ }
+
+ // update a contact
+ cc->dbc.dwEventCount--;
+ if (cc->dbc.dwFirstUnread == hDbEvent)
+ FindNextUnread(cc, key2);
+ }
// call notifier while outside mutex
NotifyEventHooks(hEventDeletedEvent, contactID, hDbEvent);
@@ -145,6 +153,7 @@ STDMETHODIMP_(BOOL) CDbxKyoto::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent)
STDMETHODIMP_(LONG) CDbxKyoto::GetBlobSize(MEVENT hDbEvent)
{
DBEvent dbe;
+ mir_cslock lck(m_csDbAccess);
if (-1 == m_dbEvents.get((LPCSTR)&hDbEvent, sizeof(MEVENT), (LPSTR)&dbe, sizeof(dbe)))
return -1;
@@ -159,11 +168,12 @@ STDMETHODIMP_(BOOL) CDbxKyoto::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
return 1;
}
- char rec[65536];
- if (-1 == m_dbEvents.get((LPCSTR)&hDbEvent, sizeof(MEVENT), rec, sizeof(rec)))
+ mir_cslock lck(m_csDbAccess);
+ VisitorCopyRec visitor;
+ if (!m_dbEvents.accept((LPCSTR)&hDbEvent, sizeof(MEVENT), &visitor, false))
return 1;
- DBEvent *dbe = (DBEvent*)rec;
+ DBEvent *dbe = (DBEvent*)visitor.vbuf_;
if (dbe->dwSignature != DBEVENT_SIGNATURE)
return 1;
@@ -174,7 +184,7 @@ STDMETHODIMP_(BOOL) CDbxKyoto::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
int bytesToCopy = (dbei->cbBlob < dbe->cbBlob) ? dbei->cbBlob : dbe->cbBlob;
dbei->cbBlob = dbe->cbBlob;
if (bytesToCopy && dbei->pBlob) {
- BYTE *pSrc = (BYTE*)rec + sizeof(DBEvent);
+ BYTE *pSrc = (BYTE*)visitor.vbuf_ + sizeof(DBEvent);
if (dbe->flags & DBEF_ENCRYPTED) {
dbei->flags &= ~DBEF_ENCRYPTED;
size_t len;
@@ -223,12 +233,12 @@ STDMETHODIMP_(BOOL) CDbxKyoto::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent
if (cc == NULL)
return -1;
- char rec[65536];
- int32_t recLen = m_dbEvents.get((LPCSTR)&hDbEvent, sizeof(MEVENT), rec, sizeof(rec));
- if (recLen == -1)
+ mir_cslock lck(m_csDbAccess);
+ VisitorCopyRec visitor;
+ if (!m_dbEvents.accept((LPCSTR)&hDbEvent, sizeof(MEVENT), &visitor, false))
return -1;
- DBEvent *dbe = (DBEvent*)rec;
+ DBEvent *dbe = (DBEvent*)visitor.vbuf_;
if (dbe->dwSignature != DBEVENT_SIGNATURE)
return -1;
@@ -238,7 +248,7 @@ STDMETHODIMP_(BOOL) CDbxKyoto::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent
DBEventSortingKey key2 = { contactID, dbe->timestamp, hDbEvent };
dbe->flags |= DBEF_READ;
- m_dbEvents.set((LPCSTR)&hDbEvent, sizeof(MEVENT), rec, recLen);
+ m_dbEvents.set((LPCSTR)&hDbEvent, sizeof(MEVENT), visitor.vbuf_, visitor.vsiz_);
FindNextUnread(cc, key2);
m_dbContacts.set((LPCSTR)&contactID, sizeof(int), (LPCSTR)&cc->dbc, sizeof(cc->dbc));
@@ -251,29 +261,29 @@ STDMETHODIMP_(MCONTACT) CDbxKyoto::GetEventContact(MEVENT hDbEvent)
{
if (hDbEvent == 0) return INVALID_CONTACT_ID;
- char rec[65536];
- if (-1 == m_dbEvents.get((LPCSTR)&hDbEvent, sizeof(MEVENT), rec, sizeof(rec)))
+ mir_cslock lck(m_csDbAccess);
+ VisitorCopyRec visitor;
+ if (!m_dbEvents.accept((LPCSTR)&hDbEvent, sizeof(MEVENT), &visitor, false))
return 1;
- DBEvent *dbe = (DBEvent*)rec;
+ DBEvent *dbe = (DBEvent*)visitor.vbuf_;
return (dbe->dwSignature == DBEVENT_SIGNATURE) ? dbe->contactID : INVALID_CONTACT_ID;
}
STDMETHODIMP_(MEVENT) CDbxKyoto::FindFirstEvent(MCONTACT contactID)
{
- size_t size;
- DBEventSortingKey keyVal = { contactID, 0, 0 }, *pKey;
+ DBEventSortingKey keyVal = { contactID, 0, 0 };
{
mir_cslock lck(m_csDbAccess);
m_evCursor->jump((LPCSTR)&keyVal, sizeof(keyVal));
- pKey = (DBEventSortingKey*)m_evCursor->get_key(&size);
+ if (!m_evCursor->kbuf_)
+ return m_evLast = 0;
+
+ keyVal = *(DBEventSortingKey*)m_evCursor->kbuf_;
}
- if (pKey == NULL)
- return m_evLast = 0;
- m_tsLast = pKey->ts;
- m_evLast = (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
- delete[] pKey;
+ m_tsLast = keyVal.ts;
+ m_evLast = (keyVal.dwContactId == contactID) ? keyVal.dwEventId : 0;
return m_evLast;
}
@@ -285,20 +295,18 @@ STDMETHODIMP_(MEVENT) CDbxKyoto::FindFirstUnreadEvent(MCONTACT contactID)
STDMETHODIMP_(MEVENT) CDbxKyoto::FindLastEvent(MCONTACT contactID)
{
- size_t size;
- DBEventSortingKey keyVal = { contactID, 0xFFFFFFFF, 0xFFFFFFFF }, *pKey;
+ DBEventSortingKey keyVal = { contactID, 0xFFFFFFFF, 0xFFFFFFFF };
{
mir_cslock lck(m_csDbAccess);
m_evCursor->jump_back((LPCSTR)&keyVal, sizeof(keyVal));
- pKey = (DBEventSortingKey*)m_evCursor->get_key(&size);
- }
+ if (!m_evCursor->kbuf_)
+ return m_evLast = 0;
- if (pKey == NULL)
- return m_evLast = 0;
+ keyVal = *(DBEventSortingKey*)m_evCursor->kbuf_;
+ }
- m_tsLast = pKey->ts;
- m_evLast = (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
- delete[] pKey;
+ m_tsLast = keyVal.ts;
+ m_evLast = (keyVal.dwContactId == contactID) ? keyVal.dwEventId : 0;
return m_evLast;
}
@@ -306,30 +314,26 @@ STDMETHODIMP_(MEVENT) CDbxKyoto::FindNextEvent(MCONTACT contactID, MEVENT hDbEve
{
if (hDbEvent == 0) return m_evLast = 0;
- DWORD ts;
-
- if (m_evLast != hDbEvent) {
- DBEvent dbe;
- if (-1 == m_dbEvents.get((LPCSTR)&hDbEvent, sizeof(MEVENT), (LPSTR)&dbe, sizeof(dbe)))
- return 0;
- m_tsLast = ts = dbe.timestamp;
- }
- else ts = m_tsLast;
-
- size_t size;
- DBEventSortingKey keyVal = { contactID, ts, hDbEvent + 1 }, *pKey;
+ DBEventSortingKey keyVal = { contactID, 0, hDbEvent + 1 };
{
mir_cslock lck(m_csDbAccess);
+ if (m_evLast != hDbEvent) {
+ DBEvent dbe;
+ if (-1 == m_dbEvents.get((LPCSTR)&hDbEvent, sizeof(MEVENT), (LPSTR)&dbe, sizeof(dbe)))
+ return 0;
+ m_tsLast = keyVal.ts = dbe.timestamp;
+ }
+ else keyVal.ts = m_tsLast;
+
m_evCursor->jump((LPCSTR)&keyVal, sizeof(keyVal));
- pKey = (DBEventSortingKey*)m_evCursor->get_key(&size);
- }
+ if (!m_evCursor->kbuf_)
+ return m_evLast = 0;
- if (pKey == NULL)
- return m_evLast = 0;
+ keyVal = *(DBEventSortingKey*)m_evCursor->kbuf_;
+ }
- m_tsLast = pKey->ts;
- m_evLast = (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
- delete[] pKey;
+ m_tsLast = keyVal.ts;
+ m_evLast = (keyVal.dwContactId == contactID) ? keyVal.dwEventId : 0;
return m_evLast;
}
@@ -337,30 +341,26 @@ STDMETHODIMP_(MEVENT) CDbxKyoto::FindPrevEvent(MCONTACT contactID, MEVENT hDbEve
{
if (hDbEvent == 0) return m_evLast = 0;
- DWORD ts;
-
- if (m_evLast != hDbEvent) {
- DBEvent dbe;
- if (-1 == m_dbEvents.get((LPCSTR)&hDbEvent, sizeof(MEVENT), (LPSTR)&dbe, sizeof(dbe)))
- return 0;
- m_tsLast = ts = dbe.timestamp;
- }
- else ts = m_tsLast;
-
- size_t size;
- DBEventSortingKey keyVal = { contactID, ts, hDbEvent - 1 }, *pKey;
+ DBEventSortingKey keyVal = { contactID, 0, hDbEvent - 1 };
{
mir_cslock lck(m_csDbAccess);
+ if (m_evLast != hDbEvent) {
+ DBEvent dbe;
+ if (-1 == m_dbEvents.get((LPCSTR)&hDbEvent, sizeof(MEVENT), (LPSTR)&dbe, sizeof(dbe)))
+ return 0;
+ m_tsLast = keyVal.ts = dbe.timestamp;
+ }
+ else keyVal.ts = m_tsLast;
+
m_evCursor->jump_back((LPCSTR)&keyVal, sizeof(keyVal));
- pKey = (DBEventSortingKey*)m_evCursor->get_key(&size);
- }
+ if (!m_evCursor->kbuf_)
+ return m_evLast = 0;
- if (pKey == NULL)
- return m_evLast = 0;
+ keyVal = *(DBEventSortingKey*)m_evCursor->kbuf_;
+ }
- m_tsLast = pKey->ts;
- m_evLast = (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
- delete[] pKey;
+ m_tsLast = keyVal.ts;
+ m_evLast = (keyVal.dwContactId == contactID) ? keyVal.dwEventId : 0;
return m_evLast;
}
diff --git a/plugins/Dbx_kyoto/src/dbintf.h b/plugins/Dbx_kyoto/src/dbintf.h
index c46a99e903..e78aaff6cb 100644
--- a/plugins/Dbx_kyoto/src/dbintf.h
+++ b/plugins/Dbx_kyoto/src/dbintf.h
@@ -261,6 +261,7 @@ protected:
HANDLE hEventAddedEvent, hEventDeletedEvent, hEventFilterAddedEvent;
MCONTACT m_hLastCachedContact;
int m_maxModuleID;
+ ModuleName *m_lastmn;
void AddToList(char *name, DWORD ofs);
DWORD FindExistingModuleNameOfs(const char *szName);
diff --git a/plugins/Dbx_kyoto/src/dbmodulechain.cpp b/plugins/Dbx_kyoto/src/dbmodulechain.cpp
index 78df791887..c27d8abcf1 100644
--- a/plugins/Dbx_kyoto/src/dbmodulechain.cpp
+++ b/plugins/Dbx_kyoto/src/dbmodulechain.cpp
@@ -68,10 +68,15 @@ int CDbxKyoto::InitModuleNames(void)
DWORD CDbxKyoto::FindExistingModuleNameOfs(const char *szName)
{
ModuleName mn = { (char*)szName, 0 };
+ if (m_lastmn && !strcmp(mn.name, m_lastmn->name))
+ return m_lastmn->ofs;
int index = m_lMods.getIndex(&mn);
- if (index != -1)
- return m_lMods[index]->ofs;
+ if (index != -1) {
+ ModuleName *pmn = m_lMods[index];
+ m_lastmn = pmn;
+ return pmn->ofs;
+ }
return 0;
}
@@ -107,11 +112,17 @@ DWORD CDbxKyoto::GetModuleNameOfs(const char *szName)
char* CDbxKyoto::GetModuleNameByOfs(DWORD ofs)
{
+ if (m_lastmn && m_lastmn->ofs == ofs)
+ return m_lastmn->name;
+
ModuleName mn = { NULL, ofs };
int index = m_lOfs.getIndex(&mn);
- if (index != -1)
- return m_lOfs[index]->name;
-
+ if (index != -1) {
+ ModuleName *pmn = m_lOfs[index];
+ m_lastmn = pmn;
+ return pmn->name;
+ }
+
return NULL;
}
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kccachedb.h b/plugins/Dbx_kyoto/src/kyotocabinet/kccachedb.h
index 26938ac32f..a29f8e0fed 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kccachedb.h
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kccachedb.h
@@ -83,7 +83,7 @@ class CacheDB : public BasicDB {
*/
explicit Cursor(CacheDB* db) : db_(db), sidx_(-1), rec_(NULL) {
_assert_(db);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.push_back(this);
}
/**
@@ -92,7 +92,7 @@ class CacheDB : public BasicDB {
virtual ~Cursor() {
_assert_(true);
if (!db_) return;
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.remove(this);
}
/**
@@ -107,7 +107,7 @@ class CacheDB : public BasicDB {
*/
bool accept(Visitor* visitor, bool writable = true, bool step = false) {
_assert_(visitor);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -158,7 +158,7 @@ class CacheDB : public BasicDB {
*/
bool jump() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -184,7 +184,7 @@ class CacheDB : public BasicDB {
*/
bool jump(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -242,7 +242,7 @@ class CacheDB : public BasicDB {
*/
bool jump_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -256,7 +256,7 @@ class CacheDB : public BasicDB {
*/
bool jump_back(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -270,7 +270,7 @@ class CacheDB : public BasicDB {
*/
bool jump_back(const std::string& key) {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -284,7 +284,7 @@ class CacheDB : public BasicDB {
*/
bool step() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -303,7 +303,7 @@ class CacheDB : public BasicDB {
*/
bool step_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -373,7 +373,7 @@ class CacheDB : public BasicDB {
* Default constructor.
*/
explicit CacheDB() :
- mlock_(), flock_(), error_(), logger_(NULL), logkinds_(0), mtrigger_(NULL),
+ flock_(), error_(), logger_(NULL), logkinds_(0), mtrigger_(NULL),
omode_(0), curs_(), path_(""), type_(TYPECACHE),
opts_(0), bnum_(DEFBNUM), capcnt_(-1), capsiz_(-1),
opaque_(), embcomp_(ZLIBRAWCOMP), comp_(NULL), slots_(), rttmode_(true), tran_(false) {
@@ -409,7 +409,7 @@ class CacheDB : public BasicDB {
*/
bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writable = true) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && visitor);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -441,7 +441,7 @@ class CacheDB : public BasicDB {
bool accept_bulk(const std::vector<std::string>& keys, Visitor* visitor,
bool writable = true) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -505,7 +505,7 @@ class CacheDB : public BasicDB {
*/
bool iterate(Visitor *visitor, bool writable = true, ProgressChecker* checker = NULL) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -578,7 +578,7 @@ class CacheDB : public BasicDB {
*/
bool scan_parallel(Visitor *visitor, size_t thnum, ProgressChecker* checker = NULL) {
_assert_(visitor && thnum <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -734,7 +734,7 @@ class CacheDB : public BasicDB {
*/
bool open(const std::string& path, uint32_t mode = OWRITER | OCREATE) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -761,7 +761,7 @@ class CacheDB : public BasicDB {
*/
bool close() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -790,7 +790,7 @@ class CacheDB : public BasicDB {
bool synchronize(bool hard = false, FileProcessor* proc = NULL,
ProgressChecker* checker = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -825,7 +825,7 @@ class CacheDB : public BasicDB {
*/
bool occupy(bool writable = true, FileProcessor* proc = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, writable);
+ // ScopedRWLock lock(&mlock_, writable);
bool err = false;
if (proc && !proc->process(path_, count_impl(), size_impl())) {
set_error(_KCCODELINE_, Error::LOGIC, "processing failed");
@@ -844,19 +844,19 @@ class CacheDB : public BasicDB {
_assert_(true);
uint32_t wcnt = 0;
while (true) {
- mlock_.lock_writer();
+ // mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!(omode_ & OWRITER)) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!tran_) break;
- mlock_.unlock();
+ // mlock_.unlock();
if (wcnt >= LOCKBUSYLOOP) {
Thread::chill();
} else {
@@ -866,7 +866,7 @@ class CacheDB : public BasicDB {
}
tran_ = true;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction");
- mlock_.unlock();
+ // mlock_.unlock();
return true;
}
/**
@@ -877,25 +877,25 @@ class CacheDB : public BasicDB {
*/
bool begin_transaction_try(bool hard = false) {
_assert_(true);
- mlock_.lock_writer();
+ // mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!(omode_ & OWRITER)) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (tran_) {
set_error(_KCCODELINE_, Error::LOGIC, "competition avoided");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
tran_ = true;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction_try");
- mlock_.unlock();
+ // mlock_.unlock();
return true;
}
/**
@@ -905,7 +905,7 @@ class CacheDB : public BasicDB {
*/
bool end_transaction(bool commit = true) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -930,7 +930,7 @@ class CacheDB : public BasicDB {
*/
bool clear() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -950,7 +950,7 @@ class CacheDB : public BasicDB {
*/
int64_t count() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -963,7 +963,7 @@ class CacheDB : public BasicDB {
*/
int64_t size() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -976,7 +976,7 @@ class CacheDB : public BasicDB {
*/
std::string path() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return "";
@@ -990,7 +990,7 @@ class CacheDB : public BasicDB {
*/
bool status(std::map<std::string, std::string>* strmap) {
_assert_(strmap);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1048,7 +1048,7 @@ class CacheDB : public BasicDB {
void log(const char* file, int32_t line, const char* func, Logger::Kind kind,
const char* message) {
_assert_(file && line > 0 && func && message);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (!logger_) return;
logger_->log(file, line, func, kind, message);
}
@@ -1062,7 +1062,7 @@ class CacheDB : public BasicDB {
*/
bool tune_logger(Logger* logger, uint32_t kinds = Logger::WARN | Logger::ERROR) {
_assert_(logger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1078,7 +1078,7 @@ class CacheDB : public BasicDB {
*/
bool tune_meta_trigger(MetaTrigger* trigger) {
_assert_(trigger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1093,7 +1093,7 @@ class CacheDB : public BasicDB {
*/
bool tune_options(int8_t opts) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1108,7 +1108,7 @@ class CacheDB : public BasicDB {
*/
bool tune_buckets(int64_t bnum) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1123,7 +1123,7 @@ class CacheDB : public BasicDB {
*/
bool tune_compressor(Compressor* comp) {
_assert_(comp);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1138,7 +1138,7 @@ class CacheDB : public BasicDB {
*/
bool cap_count(int64_t count) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1153,7 +1153,7 @@ class CacheDB : public BasicDB {
*/
bool cap_size(int64_t size) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1169,7 +1169,7 @@ class CacheDB : public BasicDB {
*/
bool switch_rotation(bool rttmode) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
rttmode_ = rttmode;
return true;
}
@@ -1179,7 +1179,7 @@ class CacheDB : public BasicDB {
*/
char* opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return NULL;
@@ -1192,7 +1192,7 @@ class CacheDB : public BasicDB {
*/
bool synchronize_opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1284,7 +1284,7 @@ class CacheDB : public BasicDB {
*/
bool tune_type(int8_t type) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1298,7 +1298,7 @@ class CacheDB : public BasicDB {
*/
uint8_t libver() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1311,7 +1311,7 @@ class CacheDB : public BasicDB {
*/
uint8_t librev() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1324,7 +1324,7 @@ class CacheDB : public BasicDB {
*/
uint8_t fmtver() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1337,7 +1337,7 @@ class CacheDB : public BasicDB {
*/
uint8_t chksum() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1350,7 +1350,7 @@ class CacheDB : public BasicDB {
*/
uint8_t type() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1363,7 +1363,7 @@ class CacheDB : public BasicDB {
*/
uint8_t opts() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1376,7 +1376,7 @@ class CacheDB : public BasicDB {
*/
Compressor* comp() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return NULL;
@@ -1389,7 +1389,7 @@ class CacheDB : public BasicDB {
*/
bool recovered() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1402,7 +1402,7 @@ class CacheDB : public BasicDB {
*/
bool reorganized() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -2013,8 +2013,6 @@ class CacheDB : public BasicDB {
CacheDB(const CacheDB&);
/** Dummy Operator to forbid the use. */
CacheDB& operator =(const CacheDB&);
- /** The method lock. */
- RWLock mlock_;
/** The file lock. */
Mutex flock_;
/** The last happened error. */
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kcdbext.h b/plugins/Dbx_kyoto/src/kyotocabinet/kcdbext.h
index 001c09a1d4..9a6beb1360 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kcdbext.h
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kcdbext.h
@@ -854,7 +854,7 @@ class IndexDB {
* Default constructor.
*/
explicit IndexDB() :
- mlock_(), db_(), omode_(0),
+ db_(), omode_(0),
rcomp_(NULL), tmppath_(""), tmpdbs_(NULL), dbnum_(DEFDBNUM), dbclock_(0),
cache_(NULL), csiz_(0), clim_(0) {
_assert_(true);
@@ -913,7 +913,7 @@ class IndexDB {
bool open(const std::string& path = ":",
uint32_t mode = BasicDB::OWRITER | BasicDB::OCREATE) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "already opened");
return false;
@@ -1045,7 +1045,7 @@ class IndexDB {
*/
bool close() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "not opened");
return false;
@@ -1090,7 +1090,7 @@ class IndexDB {
*/
bool set(const char* kbuf, size_t ksiz, const char* vbuf, size_t vsiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && vbuf && vsiz <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "not opened");
return false;
@@ -1126,7 +1126,7 @@ class IndexDB {
*/
bool add(const char* kbuf, size_t ksiz, const char* vbuf, size_t vsiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && vbuf && vsiz <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "not opened");
return false;
@@ -1165,7 +1165,7 @@ class IndexDB {
*/
bool replace(const char* kbuf, size_t ksiz, const char* vbuf, size_t vsiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && vbuf && vsiz <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "not opened");
return false;
@@ -1205,7 +1205,7 @@ class IndexDB {
*/
bool append(const char* kbuf, size_t ksiz, const char* vbuf, size_t vsiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && vbuf && vsiz <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "not opened");
return false;
@@ -1237,7 +1237,7 @@ class IndexDB {
*/
bool remove(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "not opened");
return false;
@@ -1274,7 +1274,7 @@ class IndexDB {
*/
char* get(const char* kbuf, size_t ksiz, size_t* sp) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && sp);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "not opened");
*sp = 0;
@@ -1382,7 +1382,7 @@ class IndexDB {
*/
bool synchronize(bool hard = false, BasicDB::FileProcessor* proc = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "not opened");
return false;
@@ -1403,7 +1403,7 @@ class IndexDB {
*/
bool clear() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, BasicDB::Error::INVALID, "not opened");
return false;
@@ -1422,7 +1422,7 @@ class IndexDB {
*/
int64_t count() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
return count_impl();
}
/**
@@ -1431,7 +1431,7 @@ class IndexDB {
*/
int64_t size() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
return size_impl();
}
/**
@@ -1658,8 +1658,6 @@ class IndexDB {
IndexDB(const IndexDB&);
/** Dummy Operator to forbid the use. */
IndexDB& operator =(const IndexDB&);
- /** The method lock. */
- RWLock mlock_;
/** The internal database. */
PolyDB db_;
/** The open mode. */
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kcdirdb.h b/plugins/Dbx_kyoto/src/kyotocabinet/kcdirdb.h
index c80ba2d143..5425337d8b 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kcdirdb.h
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kcdirdb.h
@@ -85,7 +85,7 @@ class DirDB : public BasicDB {
*/
explicit Cursor(DirDB* db) : db_(db), dir_(), alive_(false), name_("") {
_assert_(db);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.push_back(this);
}
/**
@@ -94,7 +94,7 @@ class DirDB : public BasicDB {
virtual ~Cursor() {
_assert_(true);
if (!db_) return;
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.remove(this);
}
/**
@@ -109,7 +109,7 @@ class DirDB : public BasicDB {
*/
bool accept(Visitor* visitor, bool writable = true, bool step = false) {
_assert_(visitor);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -175,7 +175,7 @@ class DirDB : public BasicDB {
*/
bool jump() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (alive_ && !disable()) return false;
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
@@ -203,7 +203,7 @@ class DirDB : public BasicDB {
*/
bool jump(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (alive_ && !disable()) return false;
if (!dir_.open(db_->path_)) {
db_->set_error(_KCCODELINE_, Error::SYSTEM, "opening a directory failed");
@@ -247,7 +247,7 @@ class DirDB : public BasicDB {
*/
bool jump_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -261,7 +261,7 @@ class DirDB : public BasicDB {
*/
bool jump_back(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -275,7 +275,7 @@ class DirDB : public BasicDB {
*/
bool jump_back(const std::string& key) {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -289,7 +289,7 @@ class DirDB : public BasicDB {
*/
bool step() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -313,7 +313,7 @@ class DirDB : public BasicDB {
*/
bool step_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -375,7 +375,7 @@ class DirDB : public BasicDB {
* Default constructor.
*/
explicit DirDB() :
- mlock_(), rlock_(RLOCKSLOT), error_(),
+ error_(),
logger_(NULL), logkinds_(0), mtrigger_(NULL),
omode_(0), writer_(false), autotran_(false), autosync_(false),
recov_(false), reorg_(false),
@@ -415,7 +415,7 @@ class DirDB : public BasicDB {
*/
bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writable = true) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && visitor);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -427,13 +427,7 @@ class DirDB : public BasicDB {
bool err = false;
char name[NUMBUFSIZ];
size_t lidx = hashpath(kbuf, ksiz, name) % RLOCKSLOT;
- if (writable) {
- rlock_.lock_writer(lidx);
- } else {
- rlock_.lock_reader(lidx);
- }
if (!accept_impl(kbuf, ksiz, visitor, name)) err = true;
- rlock_.unlock(lidx);
return !err;
}
/**
@@ -449,7 +443,7 @@ class DirDB : public BasicDB {
bool accept_bulk(const std::vector<std::string>& keys, Visitor* visitor,
bool writable = true) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -479,11 +473,6 @@ class DirDB : public BasicDB {
std::set<size_t>::iterator lit = lidxs.begin();
std::set<size_t>::iterator litend = lidxs.end();
while (lit != litend) {
- if (writable) {
- rlock_.lock_writer(*lit);
- } else {
- rlock_.lock_reader(*lit);
- }
++lit;
}
for (size_t i = 0; i < knum; i++) {
@@ -496,7 +485,6 @@ class DirDB : public BasicDB {
lit = lidxs.begin();
litend = lidxs.end();
while (lit != litend) {
- rlock_.unlock(*lit);
++lit;
}
delete[] rkeys;
@@ -513,7 +501,7 @@ class DirDB : public BasicDB {
*/
bool iterate(Visitor *visitor, bool writable = true, ProgressChecker* checker = NULL) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -540,7 +528,7 @@ class DirDB : public BasicDB {
*/
bool scan_parallel(Visitor *visitor, size_t thnum, ProgressChecker* checker = NULL) {
_assert_(visitor && thnum <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -548,10 +536,8 @@ class DirDB : public BasicDB {
if (thnum < 1) thnum = 0;
if (thnum > (size_t)INT8MAX) thnum = INT8MAX;
ScopedVisitor svis(visitor);
- rlock_.lock_reader_all();
bool err = false;
if (!scan_parallel_impl(visitor, thnum, checker)) err = true;
- rlock_.unlock_all();
trigger_meta(MetaTrigger::ITERATE, "scan_parallel");
return !err;
}
@@ -604,7 +590,7 @@ class DirDB : public BasicDB {
*/
bool open(const std::string& path, uint32_t mode = OWRITER | OCREATE) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -807,7 +793,7 @@ class DirDB : public BasicDB {
*/
bool close() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -842,16 +828,14 @@ class DirDB : public BasicDB {
bool synchronize(bool hard = false, FileProcessor* proc = NULL,
ProgressChecker* checker = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
}
- rlock_.lock_reader_all();
bool err = false;
if (!synchronize_impl(hard, proc, checker)) err = true;
trigger_meta(MetaTrigger::SYNCHRONIZE, "synchronize");
- rlock_.unlock_all();
return !err;
}
/**
@@ -865,7 +849,7 @@ class DirDB : public BasicDB {
*/
bool occupy(bool writable = true, FileProcessor* proc = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, writable);
+ // ScopedRWLock lock(&mlock_, writable);
bool err = false;
if (proc && !proc->process(path_, count_, size_impl())) {
set_error(_KCCODELINE_, Error::LOGIC, "processing failed");
@@ -884,19 +868,19 @@ class DirDB : public BasicDB {
_assert_(true);
uint32_t wcnt = 0;
while (true) {
- mlock_.lock_writer();
+ // mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!tran_) break;
- mlock_.unlock();
+ // mlock_.unlock();
if (wcnt >= LOCKBUSYLOOP) {
Thread::chill();
} else {
@@ -906,12 +890,12 @@ class DirDB : public BasicDB {
}
trhard_ = hard;
if (!begin_transaction_impl()) {
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
tran_ = true;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction");
- mlock_.unlock();
+ // mlock_.unlock();
return true;
}
/**
@@ -922,30 +906,30 @@ class DirDB : public BasicDB {
*/
bool begin_transaction_try(bool hard = false) {
_assert_(true);
- mlock_.lock_writer();
+ // mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (tran_) {
set_error(_KCCODELINE_, Error::LOGIC, "competition avoided");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
trhard_ = hard;
if (!begin_transaction_impl()) {
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
tran_ = true;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction_try");
- mlock_.unlock();
+ // mlock_.unlock();
return true;
}
/**
@@ -955,7 +939,7 @@ class DirDB : public BasicDB {
*/
bool end_transaction(bool commit = true) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -980,7 +964,7 @@ class DirDB : public BasicDB {
*/
bool clear() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1035,7 +1019,7 @@ class DirDB : public BasicDB {
*/
int64_t count() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -1048,7 +1032,7 @@ class DirDB : public BasicDB {
*/
int64_t size() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -1061,7 +1045,7 @@ class DirDB : public BasicDB {
*/
std::string path() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return "";
@@ -1075,7 +1059,7 @@ class DirDB : public BasicDB {
*/
bool status(std::map<std::string, std::string>* strmap) {
_assert_(strmap);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1119,7 +1103,7 @@ class DirDB : public BasicDB {
void log(const char* file, int32_t line, const char* func, Logger::Kind kind,
const char* message) {
_assert_(file && line > 0 && func && message);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (!logger_) return;
logger_->log(file, line, func, kind, message);
}
@@ -1133,7 +1117,7 @@ class DirDB : public BasicDB {
*/
bool tune_logger(Logger* logger, uint32_t kinds = Logger::WARN | Logger::ERROR) {
_assert_(logger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1149,7 +1133,7 @@ class DirDB : public BasicDB {
*/
bool tune_meta_trigger(MetaTrigger* trigger) {
_assert_(trigger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1164,7 +1148,7 @@ class DirDB : public BasicDB {
*/
bool tune_options(int8_t opts) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1179,7 +1163,7 @@ class DirDB : public BasicDB {
*/
bool tune_compressor(Compressor* comp) {
_assert_(comp);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1193,7 +1177,7 @@ class DirDB : public BasicDB {
*/
char* opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return NULL;
@@ -1206,7 +1190,7 @@ class DirDB : public BasicDB {
*/
bool synchronize_opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1225,7 +1209,7 @@ class DirDB : public BasicDB {
*/
uint8_t flags() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1313,7 +1297,7 @@ class DirDB : public BasicDB {
*/
bool tune_type(int8_t type) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1327,7 +1311,7 @@ class DirDB : public BasicDB {
*/
uint8_t libver() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1340,7 +1324,7 @@ class DirDB : public BasicDB {
*/
uint8_t librev() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1353,7 +1337,7 @@ class DirDB : public BasicDB {
*/
uint8_t fmtver() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1366,7 +1350,7 @@ class DirDB : public BasicDB {
*/
uint8_t chksum() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1379,7 +1363,7 @@ class DirDB : public BasicDB {
*/
uint8_t type() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1392,7 +1376,7 @@ class DirDB : public BasicDB {
*/
uint8_t opts() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1405,7 +1389,7 @@ class DirDB : public BasicDB {
*/
Compressor* comp() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return NULL;
@@ -1418,7 +1402,7 @@ class DirDB : public BasicDB {
*/
bool recovered() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1431,7 +1415,7 @@ class DirDB : public BasicDB {
*/
bool reorganized() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -2357,10 +2341,6 @@ class DirDB : public BasicDB {
DirDB(const DirDB&);
/** Dummy Operator to forbid the use. */
DirDB& operator =(const DirDB&);
- /** The method lock. */
- RWLock mlock_;
- /** The record locks. */
- SlottedRWLock rlock_;
/** The last happened error. */
TSD<Error> error_;
/** The internal logger. */
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kchashdb.h b/plugins/Dbx_kyoto/src/kyotocabinet/kchashdb.h
index 9370e6ed35..a128b86b10 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kchashdb.h
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kchashdb.h
@@ -137,7 +137,6 @@ class HashDB : public BasicDB {
*/
explicit Cursor(HashDB* db) : db_(db), off_(0), end_(0) {
_assert_(db);
- ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.push_back(this);
}
/**
@@ -146,7 +145,6 @@ class HashDB : public BasicDB {
virtual ~Cursor() {
_assert_(true);
if (!db_) return;
- ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.remove(this);
}
/**
@@ -161,7 +159,6 @@ class HashDB : public BasicDB {
*/
bool accept(Visitor* visitor, bool writable = true, bool step = false) {
_assert_(visitor);
- ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -280,7 +277,6 @@ class HashDB : public BasicDB {
*/
bool jump() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -302,7 +298,6 @@ class HashDB : public BasicDB {
*/
bool jump(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -366,7 +361,6 @@ class HashDB : public BasicDB {
*/
bool jump_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -380,7 +374,6 @@ class HashDB : public BasicDB {
*/
bool jump_back(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -394,7 +387,6 @@ class HashDB : public BasicDB {
*/
bool jump_back(const std::string& key) {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -408,7 +400,6 @@ class HashDB : public BasicDB {
*/
bool step() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -433,7 +424,6 @@ class HashDB : public BasicDB {
*/
bool step_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -511,7 +501,7 @@ class HashDB : public BasicDB {
* Default constructor.
*/
explicit HashDB() :
- mlock_(), rlock_(RLOCKSLOT), flock_(), atlock_(), error_(),
+ flock_(), atlock_(), error_(),
logger_(NULL), logkinds_(0), mtrigger_(NULL),
omode_(0), writer_(false), autotran_(false), autosync_(false),
reorg_(false), trim_(false),
@@ -555,20 +545,16 @@ class HashDB : public BasicDB {
*/
bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writable = true) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && visitor);
- mlock_.lock_reader();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
return false;
}
if (writable) {
if (!writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
return false;
}
if (!(flags_ & FOPEN) && !autotran_ && !tran_ && !set_flag(FOPEN, true)) {
- mlock_.unlock();
return false;
}
}
@@ -576,23 +562,16 @@ class HashDB : public BasicDB {
uint64_t hash = hash_record(kbuf, ksiz);
uint32_t pivot = fold_hash(hash);
int64_t bidx = hash % bnum_;
- size_t lidx = bidx % RLOCKSLOT;
- if (writable) {
- rlock_.lock_writer(lidx);
- } else {
- rlock_.lock_reader(lidx);
- }
- if (!accept_impl(kbuf, ksiz, visitor, bidx, pivot, false)) err = true;
- rlock_.unlock(lidx);
- mlock_.unlock();
- if (!err && dfunit_ > 0 && frgcnt_ >= dfunit_ && mlock_.lock_writer_try()) {
+
+ if (!accept_impl(kbuf, ksiz, visitor, bidx, pivot, false)) err = true;
+
+ if (!err && dfunit_ > 0 && frgcnt_ >= dfunit_) {
int64_t unit = frgcnt_;
if (unit >= dfunit_) {
if (unit > DFRGMAX) unit = DFRGMAX;
if (!defrag_impl(unit * DFRGCEF)) err = true;
frgcnt_ -= unit;
}
- mlock_.unlock();
}
return !err;
}
@@ -609,20 +588,16 @@ class HashDB : public BasicDB {
bool accept_bulk(const std::vector<std::string>& keys, Visitor* visitor,
bool writable = true) {
_assert_(visitor);
- mlock_.lock_reader();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
return false;
}
if (writable) {
if (!writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
return false;
}
if (!(flags_ & FOPEN) && !autotran_ && !tran_ && !set_flag(FOPEN, true)) {
- mlock_.unlock();
return false;
}
}
@@ -630,7 +605,6 @@ class HashDB : public BasicDB {
size_t knum = keys.size();
if (knum < 1) {
visitor->visit_after();
- mlock_.unlock();
return true;
}
bool err = false;
@@ -655,11 +629,6 @@ class HashDB : public BasicDB {
std::set<size_t>::iterator lit = lidxs.begin();
std::set<size_t>::iterator litend = lidxs.end();
while (lit != litend) {
- if (writable) {
- rlock_.lock_writer(*lit);
- } else {
- rlock_.lock_reader(*lit);
- }
++lit;
}
for (size_t i = 0; i < knum; i++) {
@@ -672,20 +641,17 @@ class HashDB : public BasicDB {
lit = lidxs.begin();
litend = lidxs.end();
while (lit != litend) {
- rlock_.unlock(*lit);
++lit;
}
delete[] rkeys;
visitor->visit_after();
- mlock_.unlock();
- if (!err && dfunit_ > 0 && frgcnt_ >= dfunit_ && mlock_.lock_writer_try()) {
+ if (!err && dfunit_ > 0 && frgcnt_ >= dfunit_) {
int64_t unit = frgcnt_;
if (unit >= dfunit_) {
if (unit > DFRGMAX) unit = DFRGMAX;
if (!defrag_impl(unit * DFRGCEF)) err = true;
frgcnt_ -= unit;
}
- mlock_.unlock();
}
return !err;
}
@@ -700,7 +666,6 @@ class HashDB : public BasicDB {
*/
bool iterate(Visitor *visitor, bool writable = true, ProgressChecker* checker = NULL) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -711,7 +676,6 @@ class HashDB : public BasicDB {
return false;
}
if (!(flags_ & FOPEN) && !autotran_ && !tran_ && !set_flag(FOPEN, true)) {
- mlock_.unlock();
return false;
}
}
@@ -733,7 +697,6 @@ class HashDB : public BasicDB {
*/
bool scan_parallel(Visitor *visitor, size_t thnum, ProgressChecker* checker = NULL) {
_assert_(visitor && thnum <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -742,10 +705,8 @@ class HashDB : public BasicDB {
if (thnum > (size_t)INT8MAX) thnum = INT8MAX;
if ((int64_t)thnum > bnum_) thnum = bnum_;
ScopedVisitor svis(visitor);
- rlock_.lock_reader_all();
bool err = false;
if (!scan_parallel_impl(visitor, thnum, checker)) err = true;
- rlock_.unlock_all();
trigger_meta(MetaTrigger::ITERATE, "scan_parallel");
return !err;
}
@@ -798,7 +759,6 @@ class HashDB : public BasicDB {
*/
bool open(const std::string& path, uint32_t mode = OWRITER | OCREATE) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -932,7 +892,6 @@ class HashDB : public BasicDB {
*/
bool close() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -969,16 +928,13 @@ class HashDB : public BasicDB {
bool synchronize(bool hard = false, FileProcessor* proc = NULL,
ProgressChecker* checker = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
}
- rlock_.lock_reader_all();
bool err = false;
if (!synchronize_impl(hard, proc, checker)) err = true;
trigger_meta(MetaTrigger::SYNCHRONIZE, "synchronize");
- rlock_.unlock_all();
return !err;
}
/**
@@ -992,7 +948,6 @@ class HashDB : public BasicDB {
*/
bool occupy(bool writable = true, FileProcessor* proc = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, writable);
bool err = false;
if (proc && !proc->process(path_, count_, lsiz_)) {
set_error(_KCCODELINE_, Error::LOGIC, "processing failed");
@@ -1011,19 +966,15 @@ class HashDB : public BasicDB {
_assert_(true);
uint32_t wcnt = 0;
while (true) {
- mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
return false;
}
if (!writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
return false;
}
if (!tran_) break;
- mlock_.unlock();
if (wcnt >= LOCKBUSYLOOP) {
Thread::chill();
} else {
@@ -1033,12 +984,10 @@ class HashDB : public BasicDB {
}
trhard_ = hard;
if (!begin_transaction_impl()) {
- mlock_.unlock();
return false;
}
tran_ = true;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction");
- mlock_.unlock();
return true;
}
/**
@@ -1049,30 +998,24 @@ class HashDB : public BasicDB {
*/
bool begin_transaction_try(bool hard = false) {
_assert_(true);
- mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
return false;
}
if (!writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
return false;
}
if (tran_) {
set_error(_KCCODELINE_, Error::LOGIC, "competition avoided");
- mlock_.unlock();
return false;
}
trhard_ = hard;
if (!begin_transaction_impl()) {
- mlock_.unlock();
return false;
}
tran_ = true;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction_try");
- mlock_.unlock();
return true;
}
/**
@@ -1082,7 +1025,6 @@ class HashDB : public BasicDB {
*/
bool end_transaction(bool commit = true) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1107,7 +1049,6 @@ class HashDB : public BasicDB {
*/
bool clear() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1147,7 +1088,6 @@ class HashDB : public BasicDB {
*/
int64_t count() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -1160,7 +1100,6 @@ class HashDB : public BasicDB {
*/
int64_t size() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -1173,7 +1112,6 @@ class HashDB : public BasicDB {
*/
std::string path() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return "";
@@ -1187,7 +1125,6 @@ class HashDB : public BasicDB {
*/
bool status(std::map<std::string, std::string>* strmap) {
_assert_(strmap);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1255,7 +1192,6 @@ class HashDB : public BasicDB {
void log(const char* file, int32_t line, const char* func, Logger::Kind kind,
const char* message) {
_assert_(file && line > 0 && func && message);
- ScopedRWLock lock(&mlock_, false);
if (!logger_) return;
logger_->log(file, line, func, kind, message);
}
@@ -1269,7 +1205,6 @@ class HashDB : public BasicDB {
*/
bool tune_logger(Logger* logger, uint32_t kinds = Logger::WARN | Logger::ERROR) {
_assert_(logger);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1285,7 +1220,6 @@ class HashDB : public BasicDB {
*/
bool tune_meta_trigger(MetaTrigger* trigger) {
_assert_(trigger);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1300,7 +1234,6 @@ class HashDB : public BasicDB {
*/
bool tune_alignment(int8_t apow) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1316,7 +1249,6 @@ class HashDB : public BasicDB {
*/
bool tune_fbp(int8_t fpow) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1333,7 +1265,6 @@ class HashDB : public BasicDB {
*/
bool tune_options(int8_t opts) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1348,7 +1279,6 @@ class HashDB : public BasicDB {
*/
bool tune_buckets(int64_t bnum) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1364,7 +1294,6 @@ class HashDB : public BasicDB {
*/
bool tune_map(int64_t msiz) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1379,7 +1308,6 @@ class HashDB : public BasicDB {
*/
bool tune_defrag(int64_t dfunit) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1394,7 +1322,6 @@ class HashDB : public BasicDB {
*/
bool tune_compressor(Compressor* comp) {
_assert_(comp);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1408,7 +1335,6 @@ class HashDB : public BasicDB {
*/
char* opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return NULL;
@@ -1421,7 +1347,6 @@ class HashDB : public BasicDB {
*/
bool synchronize_opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1441,7 +1366,6 @@ class HashDB : public BasicDB {
*/
bool defrag(int64_t step = 0) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1466,7 +1390,6 @@ class HashDB : public BasicDB {
*/
uint8_t flags() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1554,7 +1477,6 @@ class HashDB : public BasicDB {
*/
bool tune_type(int8_t type) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1568,7 +1490,6 @@ class HashDB : public BasicDB {
*/
uint8_t libver() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1581,7 +1502,6 @@ class HashDB : public BasicDB {
*/
uint8_t librev() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1594,7 +1514,6 @@ class HashDB : public BasicDB {
*/
uint8_t fmtver() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1607,7 +1526,6 @@ class HashDB : public BasicDB {
*/
uint8_t chksum() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1620,7 +1538,6 @@ class HashDB : public BasicDB {
*/
uint8_t type() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1633,7 +1550,6 @@ class HashDB : public BasicDB {
*/
uint8_t apow() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1646,7 +1562,6 @@ class HashDB : public BasicDB {
*/
uint8_t fpow() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1659,7 +1574,6 @@ class HashDB : public BasicDB {
*/
uint8_t opts() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1672,7 +1586,6 @@ class HashDB : public BasicDB {
*/
int64_t bnum() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1685,7 +1598,6 @@ class HashDB : public BasicDB {
*/
int64_t msiz() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1698,7 +1610,6 @@ class HashDB : public BasicDB {
*/
int64_t dfunit() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -1711,7 +1622,6 @@ class HashDB : public BasicDB {
*/
Compressor* comp() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return NULL;
@@ -1724,7 +1634,6 @@ class HashDB : public BasicDB {
*/
bool recovered() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1737,7 +1646,6 @@ class HashDB : public BasicDB {
*/
bool reorganized() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -3749,10 +3657,6 @@ class HashDB : public BasicDB {
HashDB(const HashDB&);
/** Dummy Operator to forbid the use. */
HashDB& operator =(const HashDB&);
- /** The method lock. */
- RWLock mlock_;
- /** The record locks. */
- SlottedRWLock rlock_;
/** The file lock. */
Mutex flock_;
/** The auto transaction lock. */
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kcplantdb.h b/plugins/Dbx_kyoto/src/kyotocabinet/kcplantdb.h
index 83750db5f7..92a979e317 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kcplantdb.h
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kcplantdb.h
@@ -125,7 +125,6 @@ class PlantDB : public BasicDB {
explicit Cursor(PlantDB* db) :
db_(db), stack_(), kbuf_(NULL), ksiz_(0), lid_(0), back_(false) {
_assert_(db);
- ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.push_back(this);
}
/**
@@ -134,7 +133,6 @@ class PlantDB : public BasicDB {
virtual ~Cursor() {
_assert_(true);
if (!db_) return;
- ScopedRWLock lock(&db_->mlock_, true);
if (kbuf_) clear_position();
db_->curs_.remove(this);
}
@@ -150,25 +148,16 @@ class PlantDB : public BasicDB {
*/
bool accept(Visitor* visitor, bool writable = true, bool step = false) {
_assert_(visitor);
- bool wrlock = writable && (db_->tran_ || db_->autotran_);
- if (wrlock) {
- db_->mlock_.lock_writer();
- } else {
- db_->mlock_.lock_reader();
- }
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
- db_->mlock_.unlock();
return false;
}
if (writable && !(db_->writer_)) {
db_->set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- db_->mlock_.unlock();
return false;
}
if (!kbuf_) {
db_->set_error(_KCCODELINE_, Error::NOREC, "no record");
- db_->mlock_.unlock();
return false;
}
bool err = false;
@@ -179,10 +168,6 @@ class PlantDB : public BasicDB {
if (!err && !hit) {
- if (!wrlock) {
- db_->mlock_.unlock();
- db_->mlock_.lock_writer();
- }
if (kbuf_) {
bool retry = true;
while (!err && retry) {
@@ -193,7 +178,6 @@ class PlantDB : public BasicDB {
err = true;
}
}
- db_->mlock_.unlock();
return !err;
}
/**
@@ -202,7 +186,6 @@ class PlantDB : public BasicDB {
*/
bool jump() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, false);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -221,7 +204,6 @@ class PlantDB : public BasicDB {
*/
bool jump(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, false);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -252,7 +234,6 @@ class PlantDB : public BasicDB {
*/
bool jump_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, false);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -271,7 +252,6 @@ class PlantDB : public BasicDB {
*/
bool jump_back(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, false);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -285,8 +265,6 @@ class PlantDB : public BasicDB {
bool hit = false;
if (lid_ > 0 && !back_position_spec(&hit)) err = true;
if (!err && !hit) {
- db_->mlock_.unlock();
- db_->mlock_.lock_writer();
if (kbuf_) {
if (!back_position_atom()) err = true;
} else {
@@ -331,15 +309,12 @@ class PlantDB : public BasicDB {
*/
bool step_back() {
_assert_(true);
- db_->mlock_.lock_reader();
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
- db_->mlock_.unlock();
return false;
}
if (!kbuf_) {
db_->set_error(_KCCODELINE_, Error::NOREC, "no record");
- db_->mlock_.unlock();
return false;
}
back_ = true;
@@ -347,8 +322,6 @@ class PlantDB : public BasicDB {
bool hit = false;
if (lid_ > 0 && !back_position_spec(&hit)) err = true;
if (!err && !hit) {
- db_->mlock_.unlock();
- db_->mlock_.lock_writer();
if (kbuf_) {
if (!back_position_atom()) err = true;
} else {
@@ -356,7 +329,6 @@ class PlantDB : public BasicDB {
err = true;
}
}
- db_->mlock_.unlock();
return !err;
}
/**
@@ -367,7 +339,7 @@ class PlantDB : public BasicDB {
_assert_(true);
return db_;
}
- private:
+
/**
* Clear the position.
*/
@@ -414,7 +386,6 @@ class PlantDB : public BasicDB {
db_->db_.report(_KCCODELINE_, Logger::WARN, "id=%lld", (long long)id);
return false;
}
- ScopedRWLock lock(&node->lock, false);
RecordArray& recs = node->recs;
if (!recs.empty()) {
set_position(recs.front(), id);
@@ -440,7 +411,6 @@ class PlantDB : public BasicDB {
db_->db_.report(_KCCODELINE_, Logger::WARN, "id=%lld", (long long)id);
return false;
}
- ScopedRWLock lock(&node->lock, false);
RecordArray& recs = node->recs;
if (!recs.empty()) {
set_position(recs.back(), id);
@@ -479,11 +449,6 @@ class PlantDB : public BasicDB {
Link* link = NULL;
int64_t hist[LEVELMAX];
int32_t hnum = 0;
- if (writable) {
- node->lock.lock_writer();
- } else {
- node->lock.lock_reader();
- }
RecordArray& recs = node->recs;
if (!recs.empty()) {
Record* frec = recs.front();
@@ -587,7 +552,6 @@ class PlantDB : public BasicDB {
}
bool atran = db_->autotran_ && !db_->tran_ && node->dirty;
bool async = db_->autosync_ && !db_->autotran_ && !db_->tran_ && node->dirty;
- node->lock.unlock();
if (hit && step) {
clear_position();
if (back_) {
@@ -601,8 +565,6 @@ class PlantDB : public BasicDB {
if (link || flush || async) {
int64_t id = node->id;
if (atran && !link && !db_->fix_auto_transaction_leaf(node)) err = true;
- db_->mlock_.unlock();
- db_->mlock_.lock_writer();
if (link) {
node = db_->search_tree(link, true, hist, &hnum);
if (node) {
@@ -844,18 +806,15 @@ class PlantDB : public BasicDB {
rec->vsiz = 0;
std::memcpy(rbuf + sizeof(*rec), kbuf_, ksiz_);
bool err = false;
- node->lock.lock_reader();
const RecordArray& recs = node->recs;
typename RecordArray::const_iterator ritend = node->recs.end();
typename RecordArray::const_iterator rit = std::lower_bound(recs.begin(), ritend,
rec, db_->reccomp_);
clear_position();
if (rit == ritend) {
- node->lock.unlock();
if (!set_position(node->next)) err = true;
} else {
set_position(*rit, node->id);
- node->lock.unlock();
}
if (rbuf != rstack) delete[] rbuf;
if (lbuf != lstack) delete[] lbuf;
@@ -879,20 +838,15 @@ class PlantDB : public BasicDB {
std::memcpy(rbuf + sizeof(*rec), kbuf_, ksiz_);
LeafNode* node = db_->load_leaf_node(lid_, false);
if (node) {
- node->lock.lock_reader();
RecordArray& recs = node->recs;
- if (recs.empty()) {
- node->lock.unlock();
- } else {
+ if (!recs.empty()) {
Record* frec = recs.front();
Record* lrec = recs.back();
if (db_->reccomp_(rec, frec)) {
hit = true;
clear_position();
- node->lock.unlock();
if (!set_position_back(node->prev)) err = true;
} else if (db_->reccomp_(lrec, rec)) {
- node->lock.unlock();
} else {
hit = true;
typename RecordArray::iterator ritbeg = recs.begin();
@@ -901,12 +855,10 @@ class PlantDB : public BasicDB {
rec, db_->reccomp_);
clear_position();
if (rit == ritbeg) {
- node->lock.unlock();
if (!set_position_back(node->prev)) err = true;
} else {
--rit;
set_position(*rit, node->id);
- node->lock.unlock();
}
}
}
@@ -944,7 +896,6 @@ class PlantDB : public BasicDB {
rec->vsiz = 0;
std::memcpy(rbuf + sizeof(*rec), kbuf_, ksiz_);
bool err = false;
- node->lock.lock_reader();
const RecordArray& recs = node->recs;
typename RecordArray::const_iterator ritbeg = node->recs.begin();
typename RecordArray::const_iterator ritend = node->recs.end();
@@ -952,16 +903,13 @@ class PlantDB : public BasicDB {
rec, db_->reccomp_);
clear_position();
if (rit == ritbeg) {
- node->lock.unlock();
if (!set_position_back(node->prev)) err = true;
} else if (rit == ritend) {
ritend--;
set_position(*ritend, node->id);
- node->lock.unlock();
} else {
--rit;
set_position(*rit, node->id);
- node->lock.unlock();
}
if (rbuf != rstack) delete[] rbuf;
if (lbuf != lstack) delete[] lbuf;
@@ -1003,7 +951,7 @@ class PlantDB : public BasicDB {
* Default constructor.
*/
explicit PlantDB() :
- mlock_(), mtrigger_(NULL), omode_(0), writer_(false), autotran_(false), autosync_(false),
+ mtrigger_(NULL), omode_(0), writer_(false), autotran_(false), autosync_(false),
db_(), curs_(), apow_(DEFAPOW), fpow_(DEFFPOW), opts_(0), bnum_(DEFBNUM),
psiz_(DEFPSIZ), pccap_(DEFPCCAP),
root_(0), first_(0), last_(0), lcnt_(0), icnt_(0), count_(0), cusage_(0),
@@ -1041,20 +989,12 @@ class PlantDB : public BasicDB {
*/
bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writable = true) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && visitor);
- bool wrlock = writable && (tran_ || autotran_);
- if (wrlock) {
- mlock_.lock_writer();
- } else {
- mlock_.lock_reader();
- }
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
return false;
}
if (writable && !writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
return false;
}
char lstack[KCPDRECBUFSIZ];
@@ -1070,7 +1010,6 @@ class PlantDB : public BasicDB {
if (!node) {
set_error(_KCCODELINE_, Error::BROKEN, "search failed");
if (lbuf != lstack) delete[] lbuf;
- mlock_.unlock();
return false;
}
char rstack[KCPDRECBUFSIZ];
@@ -1080,15 +1019,11 @@ class PlantDB : public BasicDB {
rec->ksiz = ksiz;
rec->vsiz = 0;
std::memcpy(rbuf + sizeof(*rec), kbuf, ksiz);
- if (writable) {
- node->lock.lock_writer();
- } else {
- node->lock.lock_reader();
- }
- bool reorg = accept_impl(node, rec, visitor);
+
+ bool reorg = accept_impl(node, rec, visitor);
bool atran = autotran_ && !tran_ && node->dirty;
bool async = autosync_ && !autotran_ && !tran_ && node->dirty;
- node->lock.unlock();
+
bool flush = false;
bool err = false;
int64_t id = node->id;
@@ -1100,37 +1035,23 @@ class PlantDB : public BasicDB {
flush = true;
}
if (reorg) {
- if (!wrlock) {
- mlock_.unlock();
- mlock_.lock_writer();
- }
node = search_tree(link, false, hist, &hnum);
if (node) {
if (!reorganize_tree(node, hist, hnum)) err = true;
if (atran && !tran_ && !fix_auto_transaction_tree()) err = true;
}
- mlock_.unlock();
} else if (flush) {
- if (!wrlock) {
- mlock_.unlock();
- mlock_.lock_writer();
- }
int32_t idx = id % SLOTNUM;
LeafSlot* lslot = lslots_ + idx;
if (!flush_leaf_cache_part(lslot)) err = true;
InnerSlot* islot = islots_ + idx;
if (islot->warm->count() > lslot->warm->count() + lslot->hot->count() + 1 &&
!flush_inner_cache_part(islot)) err = true;
- mlock_.unlock();
- } else {
- mlock_.unlock();
}
if (rbuf != rstack) delete[] rbuf;
if (lbuf != lstack) delete[] lbuf;
if (async) {
- mlock_.lock_writer();
if (!fix_auto_synchronization()) err = true;
- mlock_.unlock();
}
return !err;
}
@@ -1147,7 +1068,6 @@ class PlantDB : public BasicDB {
bool accept_bulk(const std::vector<std::string>& keys, Visitor* visitor,
bool writable = true) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1220,7 +1140,6 @@ class PlantDB : public BasicDB {
*/
bool iterate(Visitor *visitor, bool writable = true, ProgressChecker* checker = NULL) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1342,7 +1261,6 @@ class PlantDB : public BasicDB {
*/
bool scan_parallel(Visitor *visitor, size_t thnum, ProgressChecker* checker = NULL) {
_assert_(visitor && thnum <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1490,7 +1408,6 @@ class PlantDB : public BasicDB {
*/
bool open(const std::string& path, uint32_t mode = OWRITER | OCREATE) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1589,7 +1506,6 @@ class PlantDB : public BasicDB {
*/
bool close() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1641,43 +1557,34 @@ class PlantDB : public BasicDB {
bool synchronize(bool hard = false, FileProcessor* proc = NULL,
ProgressChecker* checker = NULL) {
_assert_(true);
- mlock_.lock_reader();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
return false;
}
bool err = false;
if (writer_) {
if (checker && !checker->check("synchronize", "cleaning the leaf node cache", -1, -1)) {
set_error(_KCCODELINE_, Error::LOGIC, "checker failed");
- mlock_.unlock();
return false;
}
if (!clean_leaf_cache()) err = true;
if (checker && !checker->check("synchronize", "cleaning the inner node cache", -1, -1)) {
set_error(_KCCODELINE_, Error::LOGIC, "checker failed");
- mlock_.unlock();
return false;
}
if (!clean_inner_cache()) err = true;
- mlock_.unlock();
- mlock_.lock_writer();
if (checker && !checker->check("synchronize", "flushing the leaf node cache", -1, -1)) {
set_error(_KCCODELINE_, Error::LOGIC, "checker failed");
- mlock_.unlock();
return false;
}
if (!flush_leaf_cache(true)) err = true;
if (checker && !checker->check("synchronize", "flushing the inner node cache", -1, -1)) {
set_error(_KCCODELINE_, Error::LOGIC, "checker failed");
- mlock_.unlock();
return false;
}
if (!flush_inner_cache(true)) err = true;
if (checker && !checker->check("synchronize", "dumping the meta data", -1, -1)) {
set_error(_KCCODELINE_, Error::LOGIC, "checker failed");
- mlock_.unlock();
return false;
}
if (!dump_meta()) err = true;
@@ -1695,7 +1602,6 @@ class PlantDB : public BasicDB {
} wrapper(proc, count_);
if (!db_.synchronize(hard, &wrapper, checker)) err = true;
trigger_meta(MetaTrigger::SYNCHRONIZE, "synchronize");
- mlock_.unlock();
return !err;
}
/**
@@ -1709,7 +1615,6 @@ class PlantDB : public BasicDB {
*/
bool occupy(bool writable = true, FileProcessor* proc = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, writable);
bool err = false;
if (proc && !proc->process(db_.path(), count_, db_.size())) {
set_error(_KCCODELINE_, Error::LOGIC, "processing failed");
@@ -1728,19 +1633,15 @@ class PlantDB : public BasicDB {
_assert_(true);
uint32_t wcnt = 0;
while (true) {
- mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
return false;
}
if (!writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
return false;
}
if (!tran_) break;
- mlock_.unlock();
if (wcnt >= LOCKBUSYLOOP) {
Thread::chill();
} else {
@@ -1749,12 +1650,10 @@ class PlantDB : public BasicDB {
}
}
if (!begin_transaction_impl(hard)) {
- mlock_.unlock();
return false;
}
tran_ = true;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction");
- mlock_.unlock();
return true;
}
/**
@@ -1765,29 +1664,23 @@ class PlantDB : public BasicDB {
*/
bool begin_transaction_try(bool hard = false) {
_assert_(true);
- mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
return false;
}
if (!writer_) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
return false;
}
if (tran_) {
set_error(_KCCODELINE_, Error::LOGIC, "competition avoided");
- mlock_.unlock();
return false;
}
if (!begin_transaction_impl(hard)) {
- mlock_.unlock();
return false;
}
tran_ = true;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction_try");
- mlock_.unlock();
return true;
}
/**
@@ -1797,7 +1690,6 @@ class PlantDB : public BasicDB {
*/
bool end_transaction(bool commit = true) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1822,7 +1714,6 @@ class PlantDB : public BasicDB {
*/
bool clear() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1856,7 +1747,6 @@ class PlantDB : public BasicDB {
*/
int64_t count() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -1869,7 +1759,6 @@ class PlantDB : public BasicDB {
*/
int64_t size() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -1882,7 +1771,6 @@ class PlantDB : public BasicDB {
*/
std::string path() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return "";
@@ -1896,7 +1784,6 @@ class PlantDB : public BasicDB {
*/
bool status(std::map<std::string, std::string>* strmap) {
_assert_(strmap);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1965,7 +1852,6 @@ class PlantDB : public BasicDB {
void log(const char* file, int32_t line, const char* func, Logger::Kind kind,
const char* message) {
_assert_(file && line > 0 && func && message);
- ScopedRWLock lock(&mlock_, false);
db_.log(file, line, func, kind, message);
}
/**
@@ -1978,7 +1864,6 @@ class PlantDB : public BasicDB {
*/
bool tune_logger(Logger* logger, uint32_t kinds = Logger::WARN | Logger::ERROR) {
_assert_(logger);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1992,7 +1877,6 @@ class PlantDB : public BasicDB {
*/
bool tune_meta_trigger(MetaTrigger* trigger) {
_assert_(trigger);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2007,7 +1891,6 @@ class PlantDB : public BasicDB {
*/
bool tune_alignment(int8_t apow) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2022,7 +1905,6 @@ class PlantDB : public BasicDB {
*/
bool tune_fbp(int8_t fpow) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2039,7 +1921,6 @@ class PlantDB : public BasicDB {
*/
bool tune_options(int8_t opts) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2054,7 +1935,6 @@ class PlantDB : public BasicDB {
*/
bool tune_buckets(int64_t bnum) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2069,7 +1949,6 @@ class PlantDB : public BasicDB {
*/
bool tune_page(int32_t psiz) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2084,7 +1963,6 @@ class PlantDB : public BasicDB {
*/
bool tune_map(int64_t msiz) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2098,7 +1976,6 @@ class PlantDB : public BasicDB {
*/
bool tune_defrag(int64_t dfunit) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2112,7 +1989,6 @@ class PlantDB : public BasicDB {
*/
bool tune_page_cache(int64_t pccap) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2127,7 +2003,6 @@ class PlantDB : public BasicDB {
*/
bool tune_compressor(Compressor* comp) {
_assert_(comp);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2144,7 +2019,6 @@ class PlantDB : public BasicDB {
*/
bool tune_comparator(Comparator* rcomp) {
_assert_(rcomp);
- ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -2158,7 +2032,6 @@ class PlantDB : public BasicDB {
*/
char* opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return NULL;
@@ -2171,7 +2044,6 @@ class PlantDB : public BasicDB {
*/
bool synchronize_opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -2185,7 +2057,6 @@ class PlantDB : public BasicDB {
*/
bool defrag(int64_t step = 0) {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -2204,7 +2075,6 @@ class PlantDB : public BasicDB {
*/
uint8_t flags() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -2217,7 +2087,6 @@ class PlantDB : public BasicDB {
*/
Comparator* rcomp() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return 0;
@@ -2314,7 +2183,6 @@ class PlantDB : public BasicDB {
* Leaf node of B+ tree.
*/
struct LeafNode {
- RWLock lock; ///< lock
int64_t id; ///< page ID number
RecordArray recs; ///< sorted array of records
int64_t size; ///< total size of records
@@ -2352,7 +2220,6 @@ class PlantDB : public BasicDB {
* Inner node of B+ tree.
*/
struct InnerNode {
- RWLock lock; ///< lock
int64_t id; ///< page ID numger
int64_t heir; ///< child before the first link
LinkArray links; ///< sorted array of links
@@ -2564,7 +2431,6 @@ class PlantDB : public BasicDB {
*/
bool save_leaf_node(LeafNode* node) {
_assert_(node);
- ScopedRWLock lock(&node->lock, false);
if (!node->dirty) return true;
bool err = false;
char hbuf[NUMBUFSIZ];
@@ -3875,8 +3741,6 @@ class PlantDB : public BasicDB {
PlantDB(const PlantDB&);
/** Dummy Operator to forbid the use. */
PlantDB& operator =(const PlantDB&);
- /** The method lock. */
- RWLock mlock_;
/** The internal meta operation trigger. */
MetaTrigger* mtrigger_;
/** The open mode. */
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kcprotodb.h b/plugins/Dbx_kyoto/src/kyotocabinet/kcprotodb.h
index 5350ced154..7abe493916 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kcprotodb.h
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kcprotodb.h
@@ -72,7 +72,7 @@ class ProtoDB : public BasicDB {
*/
explicit Cursor(ProtoDB* db) : db_(db), it_(db->recs_.end()) {
_assert_(db);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.push_back(this);
}
/**
@@ -81,7 +81,7 @@ class ProtoDB : public BasicDB {
virtual ~Cursor() {
_assert_(true);
if (!db_) return;
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.remove(this);
}
/**
@@ -96,7 +96,7 @@ class ProtoDB : public BasicDB {
*/
bool accept(Visitor* visitor, bool writable = true, bool step = false) {
_assert_(visitor);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -150,7 +150,7 @@ class ProtoDB : public BasicDB {
*/
bool jump() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -170,7 +170,7 @@ class ProtoDB : public BasicDB {
*/
bool jump(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -197,7 +197,7 @@ class ProtoDB : public BasicDB {
*/
bool jump_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -221,7 +221,7 @@ class ProtoDB : public BasicDB {
*/
bool jump_back(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -269,7 +269,7 @@ class ProtoDB : public BasicDB {
*/
bool step() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -291,7 +291,7 @@ class ProtoDB : public BasicDB {
*/
bool step_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -339,7 +339,7 @@ class ProtoDB : public BasicDB {
* Default constructor.
*/
explicit ProtoDB() :
- mlock_(), error_(), logger_(NULL), logkinds_(0), mtrigger_(NULL),
+ error_(), logger_(NULL), logkinds_(0), mtrigger_(NULL),
omode_(0), recs_(), curs_(), path_(""), size_(0), opaque_(),
tran_(false), trlogs_(), trsize_(0) {
_assert_(true);
@@ -376,7 +376,7 @@ class ProtoDB : public BasicDB {
bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writable = true) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && visitor);
if (writable) {
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -429,7 +429,7 @@ class ProtoDB : public BasicDB {
}
}
} else {
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -469,7 +469,7 @@ class ProtoDB : public BasicDB {
bool accept_bulk(const std::vector<std::string>& keys, Visitor* visitor,
bool writable = true) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -542,7 +542,7 @@ class ProtoDB : public BasicDB {
*/
bool iterate(Visitor *visitor, bool writable = true, ProgressChecker* checker = NULL) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -602,7 +602,7 @@ class ProtoDB : public BasicDB {
*/
bool scan_parallel(Visitor *visitor, size_t thnum, ProgressChecker* checker = NULL) {
_assert_(visitor && thnum <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -749,7 +749,7 @@ class ProtoDB : public BasicDB {
*/
bool open(const std::string& path, uint32_t mode = OWRITER | OCREATE) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -767,7 +767,7 @@ class ProtoDB : public BasicDB {
*/
bool close() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -804,7 +804,7 @@ class ProtoDB : public BasicDB {
bool synchronize(bool hard = false, FileProcessor* proc = NULL,
ProgressChecker* checker = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -839,7 +839,7 @@ class ProtoDB : public BasicDB {
*/
bool occupy(bool writable = true, FileProcessor* proc = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, writable);
+ // ScopedRWLock lock(&mlock_, writable);
bool err = false;
if (proc && !proc->process(path_, recs_.size(), size_)) {
set_error(_KCCODELINE_, Error::LOGIC, "processing failed");
@@ -858,19 +858,19 @@ class ProtoDB : public BasicDB {
_assert_(true);
uint32_t wcnt = 0;
while (true) {
- mlock_.lock_writer();
+ // mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!(omode_ & OWRITER)) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!tran_) break;
- mlock_.unlock();
+ // mlock_.unlock();
if (wcnt >= LOCKBUSYLOOP) {
Thread::chill();
} else {
@@ -881,7 +881,7 @@ class ProtoDB : public BasicDB {
tran_ = true;
trsize_ = size_;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction");
- mlock_.unlock();
+ // mlock_.unlock();
return true;
}
/**
@@ -892,26 +892,26 @@ class ProtoDB : public BasicDB {
*/
bool begin_transaction_try(bool hard = false) {
_assert_(true);
- mlock_.lock_writer();
+ // mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!(omode_ & OWRITER)) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (tran_) {
set_error(_KCCODELINE_, Error::LOGIC, "competition avoided");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
tran_ = true;
trsize_ = size_;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction_try");
- mlock_.unlock();
+ // mlock_.unlock();
return true;
}
/**
@@ -921,7 +921,7 @@ class ProtoDB : public BasicDB {
*/
bool end_transaction(bool commit = true) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -964,7 +964,7 @@ class ProtoDB : public BasicDB {
*/
bool clear() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -989,7 +989,7 @@ class ProtoDB : public BasicDB {
*/
int64_t count() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -1002,7 +1002,7 @@ class ProtoDB : public BasicDB {
*/
int64_t size() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -1015,7 +1015,7 @@ class ProtoDB : public BasicDB {
*/
std::string path() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return "";
@@ -1029,7 +1029,7 @@ class ProtoDB : public BasicDB {
*/
bool status(std::map<std::string, std::string>* strmap) {
_assert_(strmap);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1065,7 +1065,7 @@ class ProtoDB : public BasicDB {
void log(const char* file, int32_t line, const char* func, Logger::Kind kind,
const char* message) {
_assert_(file && line > 0 && func && message);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (!logger_) return;
logger_->log(file, line, func, kind, message);
}
@@ -1079,7 +1079,7 @@ class ProtoDB : public BasicDB {
*/
bool tune_logger(Logger* logger, uint32_t kinds = Logger::WARN | Logger::ERROR) {
_assert_(logger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1095,7 +1095,7 @@ class ProtoDB : public BasicDB {
*/
bool tune_meta_trigger(MetaTrigger* trigger) {
_assert_(trigger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1109,7 +1109,7 @@ class ProtoDB : public BasicDB {
*/
char* opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return NULL;
@@ -1122,7 +1122,7 @@ class ProtoDB : public BasicDB {
*/
bool synchronize_opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1251,8 +1251,6 @@ class ProtoDB : public BasicDB {
ProtoDB(const ProtoDB&);
/** Dummy Operator to forbid the use. */
ProtoDB& operator =(const ProtoDB&);
- /** The method lock. */
- RWLock mlock_;
/** The last happened error. */
TSD<Error> error_;
/** The internal logger. */
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kcstashdb.h b/plugins/Dbx_kyoto/src/kyotocabinet/kcstashdb.h
index 2ce5599e7c..62c919c654 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kcstashdb.h
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kcstashdb.h
@@ -77,7 +77,7 @@ class StashDB : public BasicDB {
*/
explicit Cursor(StashDB* db) : db_(db), bidx_(-1), rbuf_(NULL) {
_assert_(db);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.push_back(this);
}
/**
@@ -86,7 +86,7 @@ class StashDB : public BasicDB {
virtual ~Cursor() {
_assert_(true);
if (!db_) return;
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.remove(this);
}
/**
@@ -101,7 +101,7 @@ class StashDB : public BasicDB {
*/
bool accept(Visitor* visitor, bool writable = true, bool step = false) {
_assert_(visitor);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -135,7 +135,7 @@ class StashDB : public BasicDB {
*/
bool jump() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -161,7 +161,7 @@ class StashDB : public BasicDB {
*/
bool jump(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -196,7 +196,7 @@ class StashDB : public BasicDB {
*/
bool jump_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -210,7 +210,7 @@ class StashDB : public BasicDB {
*/
bool jump_back(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -224,7 +224,7 @@ class StashDB : public BasicDB {
*/
bool jump_back(const std::string& key) {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -238,7 +238,7 @@ class StashDB : public BasicDB {
*/
bool step() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -257,7 +257,7 @@ class StashDB : public BasicDB {
*/
bool step_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -310,7 +310,7 @@ class StashDB : public BasicDB {
* Default constructor.
*/
explicit StashDB() :
- mlock_(), rlock_(RLOCKSLOT), flock_(), error_(),
+ flock_(), error_(),
logger_(NULL), logkinds_(0), mtrigger_(NULL),
omode_(0), curs_(), path_(""), bnum_(DEFBNUM), opaque_(),
count_(0), size_(0), buckets_(NULL),
@@ -347,7 +347,7 @@ class StashDB : public BasicDB {
*/
bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writable = true) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && visitor);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -357,14 +357,7 @@ class StashDB : public BasicDB {
return false;
}
size_t bidx = hash_record(kbuf, ksiz) % bnum_;
- size_t lidx = bidx % RLOCKSLOT;
- if (writable) {
- rlock_.lock_writer(lidx);
- } else {
- rlock_.lock_reader(lidx);
- }
accept_impl(kbuf, ksiz, visitor, bidx);
- rlock_.unlock(lidx);
return true;
}
/**
@@ -380,7 +373,7 @@ class StashDB : public BasicDB {
bool accept_bulk(const std::vector<std::string>& keys, Visitor* visitor,
bool writable = true) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -410,11 +403,6 @@ class StashDB : public BasicDB {
std::set<size_t>::iterator lit = lidxs.begin();
std::set<size_t>::iterator litend = lidxs.end();
while (lit != litend) {
- if (writable) {
- rlock_.lock_writer(*lit);
- } else {
- rlock_.lock_reader(*lit);
- }
++lit;
}
for (size_t i = 0; i < knum; i++) {
@@ -424,7 +412,6 @@ class StashDB : public BasicDB {
lit = lidxs.begin();
litend = lidxs.end();
while (lit != litend) {
- rlock_.unlock(*lit);
++lit;
}
delete[] rkeys;
@@ -441,7 +428,7 @@ class StashDB : public BasicDB {
*/
bool iterate(Visitor *visitor, bool writable = true, ProgressChecker* checker = NULL) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -498,7 +485,7 @@ class StashDB : public BasicDB {
*/
bool scan_parallel(Visitor *visitor, size_t thnum, ProgressChecker* checker = NULL) {
_assert_(visitor && thnum <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -561,7 +548,6 @@ class StashDB : public BasicDB {
Error error_;
};
bool err = false;
- rlock_.lock_reader_all();
ThreadImpl* threads = new ThreadImpl[thnum];
double range = (double)bnum_ / thnum;
for (size_t i = 0; i < thnum; i++) {
@@ -582,7 +568,6 @@ class StashDB : public BasicDB {
}
}
delete[] threads;
- rlock_.unlock_all();
if (err) return false;
if (checker && !checker->check("scan_parallel", "ending", -1, allcnt)) {
set_error(_KCCODELINE_, Error::LOGIC, "checker failed");
@@ -639,7 +624,7 @@ class StashDB : public BasicDB {
*/
bool open(const std::string& path, uint32_t mode = OWRITER | OCREATE) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -665,7 +650,7 @@ class StashDB : public BasicDB {
*/
bool close() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -706,7 +691,7 @@ class StashDB : public BasicDB {
bool synchronize(bool hard = false, FileProcessor* proc = NULL,
ProgressChecker* checker = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -741,7 +726,7 @@ class StashDB : public BasicDB {
*/
bool occupy(bool writable = true, FileProcessor* proc = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, writable);
+ // ScopedRWLock lock(&mlock_, writable);
bool err = false;
if (proc && !proc->process(path_, count_, size_impl())) {
set_error(_KCCODELINE_, Error::LOGIC, "processing failed");
@@ -760,19 +745,19 @@ class StashDB : public BasicDB {
_assert_(true);
uint32_t wcnt = 0;
while (true) {
- mlock_.lock_writer();
+ // mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!(omode_ & OWRITER)) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!tran_) break;
- mlock_.unlock();
+ // mlock_.unlock();
if (wcnt >= LOCKBUSYLOOP) {
Thread::chill();
} else {
@@ -784,7 +769,7 @@ class StashDB : public BasicDB {
trcount_ = count_;
trsize_ = size_;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction");
- mlock_.unlock();
+ // mlock_.unlock();
return true;
}
/**
@@ -795,27 +780,27 @@ class StashDB : public BasicDB {
*/
bool begin_transaction_try(bool hard = false) {
_assert_(true);
- mlock_.lock_writer();
+ // mlock_.lock_writer();
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (!(omode_ & OWRITER)) {
set_error(_KCCODELINE_, Error::NOPERM, "permission denied");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
if (tran_) {
set_error(_KCCODELINE_, Error::LOGIC, "competition avoided");
- mlock_.unlock();
+ // mlock_.unlock();
return false;
}
tran_ = true;
trcount_ = count_;
trsize_ = size_;
trigger_meta(MetaTrigger::BEGINTRAN, "begin_transaction_try");
- mlock_.unlock();
+ // mlock_.unlock();
return true;
}
/**
@@ -825,7 +810,7 @@ class StashDB : public BasicDB {
*/
bool end_transaction(bool commit = true) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -851,7 +836,7 @@ class StashDB : public BasicDB {
*/
bool clear() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -881,7 +866,7 @@ class StashDB : public BasicDB {
*/
int64_t count() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -894,7 +879,7 @@ class StashDB : public BasicDB {
*/
int64_t size() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -907,7 +892,7 @@ class StashDB : public BasicDB {
*/
std::string path() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return "";
@@ -921,7 +906,7 @@ class StashDB : public BasicDB {
*/
bool status(std::map<std::string, std::string>* strmap) {
_assert_(strmap);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -964,7 +949,7 @@ class StashDB : public BasicDB {
void log(const char* file, int32_t line, const char* func, Logger::Kind kind,
const char* message) {
_assert_(file && line > 0 && func && message);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (!logger_) return;
logger_->log(file, line, func, kind, message);
}
@@ -978,7 +963,7 @@ class StashDB : public BasicDB {
*/
bool tune_logger(Logger* logger, uint32_t kinds = Logger::WARN | Logger::ERROR) {
_assert_(logger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -994,7 +979,7 @@ class StashDB : public BasicDB {
*/
bool tune_meta_trigger(MetaTrigger* trigger) {
_assert_(trigger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1009,7 +994,7 @@ class StashDB : public BasicDB {
*/
bool tune_buckets(int64_t bnum) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1024,7 +1009,7 @@ class StashDB : public BasicDB {
*/
char* opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return NULL;
@@ -1037,7 +1022,7 @@ class StashDB : public BasicDB {
*/
bool synchronize_opaque() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -1434,10 +1419,6 @@ class StashDB : public BasicDB {
StashDB(const StashDB&);
/** Dummy Operator to forbid the use. */
StashDB& operator =(const StashDB&);
- /** The method lock. */
- RWLock mlock_;
- /** The record locks. */
- SlottedRWLock rlock_;
/** The file lock. */
Mutex flock_;
/** The last happened error. */
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kctextdb.h b/plugins/Dbx_kyoto/src/kyotocabinet/kctextdb.h
index 324af3d8f1..d707059fe1 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kctextdb.h
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kctextdb.h
@@ -63,7 +63,7 @@ class TextDB : public BasicDB {
*/
explicit Cursor(TextDB* db) : db_(db), off_(INT64MAX), end_(0), queue_(), line_() {
_assert_(db);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.push_back(this);
}
/**
@@ -72,7 +72,7 @@ class TextDB : public BasicDB {
virtual ~Cursor() {
_assert_(true);
if (!db_) return;
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
db_->curs_.remove(this);
}
/**
@@ -86,7 +86,7 @@ class TextDB : public BasicDB {
*/
bool accept(Visitor* visitor, bool writable = true, bool step = false) {
_assert_(visitor);
- ScopedRWLock lock(&db_->mlock_, false);
+ // ScopedRWLock lock(&db_->mlock_, false);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -105,7 +105,7 @@ class TextDB : public BasicDB {
*/
bool jump() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, false);
+ // ScopedRWLock lock(&db_->mlock_, false);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -128,7 +128,7 @@ class TextDB : public BasicDB {
*/
bool jump(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -157,7 +157,7 @@ class TextDB : public BasicDB {
*/
bool jump_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -171,7 +171,7 @@ class TextDB : public BasicDB {
*/
bool jump_back(const char* kbuf, size_t ksiz) {
_assert_(kbuf && ksiz <= MEMMAXSIZ);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -193,7 +193,7 @@ class TextDB : public BasicDB {
*/
bool step() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, false);
+ // ScopedRWLock lock(&db_->mlock_, false);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -212,7 +212,7 @@ class TextDB : public BasicDB {
*/
bool step_back() {
_assert_(true);
- ScopedRWLock lock(&db_->mlock_, true);
+ // ScopedRWLock lock(&db_->mlock_, true);
if (db_->omode_ == 0) {
db_->set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -359,7 +359,7 @@ class TextDB : public BasicDB {
*/
bool accept(const char* kbuf, size_t ksiz, Visitor* visitor, bool writable = true) {
_assert_(kbuf && ksiz <= MEMMAXSIZ && visitor);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -385,7 +385,7 @@ class TextDB : public BasicDB {
bool accept_bulk(const std::vector<std::string>& keys, Visitor* visitor,
bool writable = true) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -415,7 +415,7 @@ class TextDB : public BasicDB {
*/
bool iterate(Visitor *visitor, bool writable = true, ProgressChecker* checker = NULL) {
_assert_(visitor);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -442,7 +442,7 @@ class TextDB : public BasicDB {
*/
bool scan_parallel(Visitor *visitor, size_t thnum, ProgressChecker* checker = NULL) {
_assert_(visitor && thnum <= MEMMAXSIZ);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -503,7 +503,7 @@ class TextDB : public BasicDB {
*/
bool open(const std::string& path, uint32_t mode = OWRITER | OCREATE) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -550,7 +550,7 @@ class TextDB : public BasicDB {
*/
bool close() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -581,7 +581,7 @@ class TextDB : public BasicDB {
bool synchronize(bool hard = false, FileProcessor* proc = NULL,
ProgressChecker* checker = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -602,7 +602,7 @@ class TextDB : public BasicDB {
*/
bool occupy(bool writable = true, FileProcessor* proc = NULL) {
_assert_(true);
- ScopedRWLock lock(&mlock_, writable);
+ // ScopedRWLock lock(&mlock_, writable);
bool err = false;
if (proc && !proc->process(path_, -1, file_.size())) {
set_error(_KCCODELINE_, Error::LOGIC, "processing failed");
@@ -619,7 +619,7 @@ class TextDB : public BasicDB {
*/
bool begin_transaction(bool hard = false) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -635,7 +635,7 @@ class TextDB : public BasicDB {
*/
bool begin_transaction_try(bool hard = false) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -650,7 +650,7 @@ class TextDB : public BasicDB {
*/
bool end_transaction(bool commit = true) {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -664,7 +664,7 @@ class TextDB : public BasicDB {
*/
bool clear() {
_assert_(true);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -691,7 +691,7 @@ class TextDB : public BasicDB {
*/
int64_t count() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -705,7 +705,7 @@ class TextDB : public BasicDB {
*/
int64_t size() {
_assert_(true);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return -1;
@@ -727,7 +727,7 @@ class TextDB : public BasicDB {
*/
bool status(std::map<std::string, std::string>* strmap) {
_assert_(strmap);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ == 0) {
set_error(_KCCODELINE_, Error::INVALID, "not opened");
return false;
@@ -760,7 +760,7 @@ class TextDB : public BasicDB {
void log(const char* file, int32_t line, const char* func, Logger::Kind kind,
const char* message) {
_assert_(file && line > 0 && func && message);
- ScopedRWLock lock(&mlock_, false);
+ // ScopedRWLock lock(&mlock_, false);
if (!logger_) return;
logger_->log(file, line, func, kind, message);
}
@@ -774,7 +774,7 @@ class TextDB : public BasicDB {
*/
bool tune_logger(Logger* logger, uint32_t kinds = Logger::WARN | Logger::ERROR) {
_assert_(logger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -790,7 +790,7 @@ class TextDB : public BasicDB {
*/
bool tune_meta_trigger(MetaTrigger* trigger) {
_assert_(trigger);
- ScopedRWLock lock(&mlock_, true);
+ // ScopedRWLock lock(&mlock_, true);
if (omode_ != 0) {
set_error(_KCCODELINE_, Error::INVALID, "already opened");
return false;
@@ -1215,8 +1215,6 @@ class TextDB : public BasicDB {
TextDB(const TextDB&);
/** Dummy Operator to forbid the use. */
TextDB& operator =(const TextDB&);
- /** The method lock. */
- RWLock mlock_;
/** The last happened error. */
TSD<Error> error_;
/** The internal logger. */
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.cc b/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.cc
index 82d1bb9f27..e67a6ae4c4 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.cc
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.cc
@@ -615,1149 +615,6 @@ void SlottedMutex::unlock_all() {
}
-/**
- * Default constructor.
- */
-SpinLock::SpinLock() : opq_(NULL) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
-#elif _KC_GCCATOMIC
- _assert_(true);
-#else
- _assert_(true);
- ::pthread_spinlock_t* spin = new ::pthread_spinlock_t;
- if (::pthread_spin_init(spin, PTHREAD_PROCESS_PRIVATE) != 0)
- throw std::runtime_error("pthread_spin_init");
- opq_ = (void*)spin;
-#endif
-}
-
-
-/**
- * Destructor.
- */
-SpinLock::~SpinLock() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
-#elif _KC_GCCATOMIC
- _assert_(true);
-#else
- _assert_(true);
- ::pthread_spinlock_t* spin = (::pthread_spinlock_t*)opq_;
- ::pthread_spin_destroy(spin);
- delete spin;
-#endif
-}
-
-
-/**
- * Get the lock.
- */
-void SpinLock::lock() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- uint32_t wcnt = 0;
- while (::InterlockedCompareExchange((LONG*)&opq_, 1, 0) != 0) {
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- }
-#elif _KC_GCCATOMIC
- _assert_(true);
- uint32_t wcnt = 0;
- while (!__sync_bool_compare_and_swap(&opq_, 0, 1)) {
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- }
-#else
- _assert_(true);
- ::pthread_spinlock_t* spin = (::pthread_spinlock_t*)opq_;
- if (::pthread_spin_lock(spin) != 0) throw std::runtime_error("pthread_spin_lock");
-#endif
-}
-
-
-/**
- * Try to get the lock.
- */
-bool SpinLock::lock_try() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- return ::InterlockedCompareExchange((LONG*)&opq_, 1, 0) == 0;
-#elif _KC_GCCATOMIC
- _assert_(true);
- return __sync_bool_compare_and_swap(&opq_, 0, 1);
-#else
- _assert_(true);
- ::pthread_spinlock_t* spin = (::pthread_spinlock_t*)opq_;
- int32_t ecode = ::pthread_spin_trylock(spin);
- if (ecode == 0) return true;
- if (ecode != EBUSY) throw std::runtime_error("pthread_spin_trylock");
- return false;
-#endif
-}
-
-
-/**
- * Release the lock.
- */
-void SpinLock::unlock() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- ::InterlockedExchange((LONG*)&opq_, 0);
-#elif _KC_GCCATOMIC
- _assert_(true);
- __sync_lock_release(&opq_);
-#else
- _assert_(true);
- ::pthread_spinlock_t* spin = (::pthread_spinlock_t*)opq_;
- if (::pthread_spin_unlock(spin) != 0) throw std::runtime_error("pthread_spin_unlock");
-#endif
-}
-
-
-/**
- * SlottedSpinLock internal.
- */
-struct SlottedSpinLockCore {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || _KC_GCCATOMIC
- uint32_t* locks; ///< primitives
- size_t slotnum; ///< number of slots
-#else
- ::pthread_spinlock_t* spins; ///< primitives
- size_t slotnum; ///< number of slots
-#endif
-};
-
-
-/**
- * Constructor.
- */
-SlottedSpinLock::SlottedSpinLock(size_t slotnum) : opq_(NULL) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || _KC_GCCATOMIC
- _assert_(true);
- SlottedSpinLockCore* core = new SlottedSpinLockCore;
- uint32_t* locks = new uint32_t[slotnum];
- for (size_t i = 0; i < slotnum; i++) {
- locks[i] = 0;
- }
- core->locks = locks;
- core->slotnum = slotnum;
- opq_ = (void*)core;
-#else
- _assert_(true);
- SlottedSpinLockCore* core = new SlottedSpinLockCore;
- ::pthread_spinlock_t* spins = new ::pthread_spinlock_t[slotnum];
- for (size_t i = 0; i < slotnum; i++) {
- if (::pthread_spin_init(spins + i, PTHREAD_PROCESS_PRIVATE) != 0)
- throw std::runtime_error("pthread_spin_init");
- }
- core->spins = spins;
- core->slotnum = slotnum;
- opq_ = (void*)core;
-#endif
-}
-
-
-/**
- * Destructor.
- */
-SlottedSpinLock::~SlottedSpinLock() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || _KC_GCCATOMIC
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- delete[] core->locks;
- delete core;
-#else
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- ::pthread_spinlock_t* spins = core->spins;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- ::pthread_spin_destroy(spins + i);
- }
- delete[] spins;
- delete core;
-#endif
-}
-
-
-/**
- * Get the lock of a slot.
- */
-void SlottedSpinLock::lock(size_t idx) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- uint32_t* lock = core->locks + idx;
- uint32_t wcnt = 0;
- while (::InterlockedCompareExchange((LONG*)lock, 1, 0) != 0) {
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- }
-#elif _KC_GCCATOMIC
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- uint32_t* lock = core->locks + idx;
- uint32_t wcnt = 0;
- while (!__sync_bool_compare_and_swap(lock, 0, 1)) {
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- }
-#else
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- if (::pthread_spin_lock(core->spins + idx) != 0)
- throw std::runtime_error("pthread_spin_lock");
-#endif
-}
-
-
-/**
- * Release the lock of a slot.
- */
-void SlottedSpinLock::unlock(size_t idx) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- uint32_t* lock = core->locks + idx;
- ::InterlockedExchange((LONG*)lock, 0);
-#elif _KC_GCCATOMIC
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- uint32_t* lock = core->locks + idx;
- __sync_lock_release(lock);
-#else
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- if (::pthread_spin_unlock(core->spins + idx) != 0)
- throw std::runtime_error("pthread_spin_unlock");
-#endif
-}
-
-
-/**
- * Get the locks of all slots.
- */
-void SlottedSpinLock::lock_all() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- uint32_t* locks = core->locks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- uint32_t* lock = locks + i;
- uint32_t wcnt = 0;
- while (::InterlockedCompareExchange((LONG*)lock, 1, 0) != 0) {
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- }
- }
-#elif _KC_GCCATOMIC
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- uint32_t* locks = core->locks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- uint32_t* lock = locks + i;
- uint32_t wcnt = 0;
- while (!__sync_bool_compare_and_swap(lock, 0, 1)) {
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- }
- }
-#else
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- ::pthread_spinlock_t* spins = core->spins;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- if (::pthread_spin_lock(spins + i) != 0)
- throw std::runtime_error("pthread_spin_lock");
- }
-#endif
-}
-
-
-/**
- * Release the locks of all slots.
- */
-void SlottedSpinLock::unlock_all() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- uint32_t* locks = core->locks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- uint32_t* lock = locks + i;
- ::InterlockedExchange((LONG*)lock, 0);
- }
-#elif _KC_GCCATOMIC
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- uint32_t* locks = core->locks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- uint32_t* lock = locks + i;
- __sync_lock_release(lock);
- }
-#else
- _assert_(true);
- SlottedSpinLockCore* core = (SlottedSpinLockCore*)opq_;
- ::pthread_spinlock_t* spins = core->spins;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- if (::pthread_spin_unlock(spins + i) != 0)
- throw std::runtime_error("pthread_spin_unlock");
- }
-#endif
-}
-
-
-/**
- * Default constructor.
- */
-RWLock::RWLock() : opq_(NULL) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SpinRWLock* rwlock = new SpinRWLock;
- opq_ = (void*)rwlock;
-#else
- _assert_(true);
- ::pthread_rwlock_t* rwlock = new ::pthread_rwlock_t;
- if (::pthread_rwlock_init(rwlock, NULL) != 0) throw std::runtime_error("pthread_rwlock_init");
- opq_ = (void*)rwlock;
-#endif
-}
-
-
-/**
- * Destructor.
- */
-RWLock::~RWLock() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SpinRWLock* rwlock = (SpinRWLock*)opq_;
- delete rwlock;
-#else
- _assert_(true);
- ::pthread_rwlock_t* rwlock = (::pthread_rwlock_t*)opq_;
- ::pthread_rwlock_destroy(rwlock);
- delete rwlock;
-#endif
-}
-
-
-/**
- * Get the writer lock.
- */
-void RWLock::lock_writer() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SpinRWLock* rwlock = (SpinRWLock*)opq_;
- rwlock->lock_writer();
-#else
- _assert_(true);
- ::pthread_rwlock_t* rwlock = (::pthread_rwlock_t*)opq_;
- if (::pthread_rwlock_wrlock(rwlock) != 0) throw std::runtime_error("pthread_rwlock_lock");
-#endif
-}
-
-
-/**
- * Try to get the writer lock.
- */
-bool RWLock::lock_writer_try() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SpinRWLock* rwlock = (SpinRWLock*)opq_;
- return rwlock->lock_writer_try();
-#else
- _assert_(true);
- ::pthread_rwlock_t* rwlock = (::pthread_rwlock_t*)opq_;
- int32_t ecode = ::pthread_rwlock_trywrlock(rwlock);
- if (ecode == 0) return true;
- if (ecode != EBUSY) throw std::runtime_error("pthread_rwlock_trylock");
- return false;
-#endif
-}
-
-
-/**
- * Get a reader lock.
- */
-void RWLock::lock_reader() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SpinRWLock* rwlock = (SpinRWLock*)opq_;
- rwlock->lock_reader();
-#else
- _assert_(true);
- ::pthread_rwlock_t* rwlock = (::pthread_rwlock_t*)opq_;
- if (::pthread_rwlock_rdlock(rwlock) != 0) throw std::runtime_error("pthread_rwlock_lock");
-#endif
-}
-
-
-/**
- * Try to get a reader lock.
- */
-bool RWLock::lock_reader_try() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SpinRWLock* rwlock = (SpinRWLock*)opq_;
- return rwlock->lock_reader_try();
-#else
- _assert_(true);
- ::pthread_rwlock_t* rwlock = (::pthread_rwlock_t*)opq_;
- int32_t ecode = ::pthread_rwlock_tryrdlock(rwlock);
- if (ecode == 0) return true;
- if (ecode != EBUSY) throw std::runtime_error("pthread_rwlock_trylock");
- return false;
-#endif
-}
-
-
-/**
- * Release the lock.
- */
-void RWLock::unlock() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SpinRWLock* rwlock = (SpinRWLock*)opq_;
- rwlock->unlock();
-#else
- _assert_(true);
- ::pthread_rwlock_t* rwlock = (::pthread_rwlock_t*)opq_;
- if (::pthread_rwlock_unlock(rwlock) != 0) throw std::runtime_error("pthread_rwlock_unlock");
-#endif
-}
-
-
-/**
- * SlottedRWLock internal.
- */
-struct SlottedRWLockCore {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- RWLock* rwlocks; ///< primitives
- size_t slotnum; ///< number of slots
-#else
- ::pthread_rwlock_t* rwlocks; ///< primitives
- size_t slotnum; ///< number of slots
-#endif
-};
-
-
-/**
- * Constructor.
- */
-SlottedRWLock::SlottedRWLock(size_t slotnum) : opq_(NULL) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedRWLockCore* core = new SlottedRWLockCore;
- RWLock* rwlocks = new RWLock[slotnum];
- core->rwlocks = rwlocks;
- core->slotnum = slotnum;
- opq_ = (void*)core;
-#else
- _assert_(true);
- SlottedRWLockCore* core = new SlottedRWLockCore;
- ::pthread_rwlock_t* rwlocks = new ::pthread_rwlock_t[slotnum];
- for (size_t i = 0; i < slotnum; i++) {
- if (::pthread_rwlock_init(rwlocks + i, NULL) != 0)
- throw std::runtime_error("pthread_rwlock_init");
- }
- core->rwlocks = rwlocks;
- core->slotnum = slotnum;
- opq_ = (void*)core;
-#endif
-}
-
-
-/**
- * Destructor.
- */
-SlottedRWLock::~SlottedRWLock() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- delete[] core->rwlocks;
- delete core;
-#else
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- ::pthread_rwlock_t* rwlocks = core->rwlocks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- ::pthread_rwlock_destroy(rwlocks + i);
- }
- delete[] rwlocks;
- delete core;
-#endif
-}
-
-
-/**
- * Get the writer lock of a slot.
- */
-void SlottedRWLock::lock_writer(size_t idx) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- core->rwlocks[idx].lock_writer();
-#else
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- if (::pthread_rwlock_wrlock(core->rwlocks + idx) != 0)
- throw std::runtime_error("pthread_rwlock_wrlock");
-#endif
-}
-
-
-/**
- * Get the reader lock of a slot.
- */
-void SlottedRWLock::lock_reader(size_t idx) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- core->rwlocks[idx].lock_reader();
-#else
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- if (::pthread_rwlock_rdlock(core->rwlocks + idx) != 0)
- throw std::runtime_error("pthread_rwlock_rdlock");
-#endif
-}
-
-
-/**
- * Release the lock of a slot.
- */
-void SlottedRWLock::unlock(size_t idx) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- core->rwlocks[idx].unlock();
-#else
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- if (::pthread_rwlock_unlock(core->rwlocks + idx) != 0)
- throw std::runtime_error("pthread_rwlock_unlock");
-#endif
-}
-
-
-/**
- * Get the writer locks of all slots.
- */
-void SlottedRWLock::lock_writer_all() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- RWLock* rwlocks = core->rwlocks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- rwlocks[i].lock_writer();
- }
-#else
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- ::pthread_rwlock_t* rwlocks = core->rwlocks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- if (::pthread_rwlock_wrlock(rwlocks + i) != 0)
- throw std::runtime_error("pthread_rwlock_wrlock");
- }
-#endif
-}
-
-
-/**
- * Get the reader locks of all slots.
- */
-void SlottedRWLock::lock_reader_all() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- RWLock* rwlocks = core->rwlocks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- rwlocks[i].lock_reader();
- }
-#else
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- ::pthread_rwlock_t* rwlocks = core->rwlocks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- if (::pthread_rwlock_rdlock(rwlocks + i) != 0)
- throw std::runtime_error("pthread_rwlock_rdlock");
- }
-#endif
-}
-
-
-/**
- * Release the locks of all slots.
- */
-void SlottedRWLock::unlock_all() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- RWLock* rwlocks = core->rwlocks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- rwlocks[i].unlock();
- }
-#else
- _assert_(true);
- SlottedRWLockCore* core = (SlottedRWLockCore*)opq_;
- ::pthread_rwlock_t* rwlocks = core->rwlocks;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- if (::pthread_rwlock_unlock(rwlocks + i) != 0)
- throw std::runtime_error("pthread_rwlock_unlock");
- }
-#endif
-}
-
-
-/**
- * SpinRWLock internal.
- */
-struct SpinRWLockCore {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- LONG sem; ///< semaphore
- uint32_t cnt; ///< count of threads
-#elif _KC_GCCATOMIC
- int32_t sem; ///< semaphore
- uint32_t cnt; ///< count of threads
-#else
- ::pthread_spinlock_t sem; ///< semaphore
- uint32_t cnt; ///< count of threads
-#endif
-};
-
-
-/**
- * Lock the semephore of SpinRWLock.
- * @param core the internal fields.
- */
-static void spinrwlocklock(SpinRWLockCore* core);
-
-
-/**
- * Unlock the semephore of SpinRWLock.
- * @param core the internal fields.
- */
-static void spinrwlockunlock(SpinRWLockCore* core);
-
-
-/**
- * Default constructor.
- */
-SpinRWLock::SpinRWLock() : opq_(NULL) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || _KC_GCCATOMIC
- _assert_(true);
- SpinRWLockCore* core = new SpinRWLockCore;
- core->sem = 0;
- core->cnt = 0;
- opq_ = (void*)core;
-#else
- _assert_(true);
- SpinRWLockCore* core = new SpinRWLockCore;
- if (::pthread_spin_init(&core->sem, PTHREAD_PROCESS_PRIVATE) != 0)
- throw std::runtime_error("pthread_spin_init");
- core->cnt = 0;
- opq_ = (void*)core;
-#endif
-}
-
-
-/**
- * Destructor.
- */
-SpinRWLock::~SpinRWLock() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || _KC_GCCATOMIC
- _assert_(true);
- SpinRWLockCore* core = (SpinRWLockCore*)opq_;
- delete core;
-#else
- _assert_(true);
- SpinRWLockCore* core = (SpinRWLockCore*)opq_;
- ::pthread_spin_destroy(&core->sem);
- delete core;
-#endif
-}
-
-
-/**
- * Get the writer lock.
- */
-void SpinRWLock::lock_writer() {
- _assert_(true);
- SpinRWLockCore* core = (SpinRWLockCore*)opq_;
- spinrwlocklock(core);
- uint32_t wcnt = 0;
- while (core->cnt > 0) {
- spinrwlockunlock(core);
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- spinrwlocklock(core);
- }
- core->cnt = INT32MAX;
- spinrwlockunlock(core);
-}
-
-
-/**
- * Try to get the writer lock.
- */
-bool SpinRWLock::lock_writer_try() {
- _assert_(true);
- SpinRWLockCore* core = (SpinRWLockCore*)opq_;
- spinrwlocklock(core);
- if (core->cnt > 0) {
- spinrwlockunlock(core);
- return false;
- }
- core->cnt = INT32MAX;
- spinrwlockunlock(core);
- return true;
-}
-
-
-/**
- * Get a reader lock.
- */
-void SpinRWLock::lock_reader() {
- _assert_(true);
- SpinRWLockCore* core = (SpinRWLockCore*)opq_;
- spinrwlocklock(core);
- uint32_t wcnt = 0;
- while (core->cnt >= (uint32_t)INT32MAX) {
- spinrwlockunlock(core);
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- spinrwlocklock(core);
- }
- core->cnt++;
- spinrwlockunlock(core);
-}
-
-
-/**
- * Try to get a reader lock.
- */
-bool SpinRWLock::lock_reader_try() {
- _assert_(true);
- SpinRWLockCore* core = (SpinRWLockCore*)opq_;
- spinrwlocklock(core);
- if (core->cnt >= (uint32_t)INT32MAX) {
- spinrwlockunlock(core);
- return false;
- }
- core->cnt++;
- spinrwlockunlock(core);
- return true;
-}
-
-
-/**
- * Release the lock.
- */
-void SpinRWLock::unlock() {
- _assert_(true);
- SpinRWLockCore* core = (SpinRWLockCore*)opq_;
- spinrwlocklock(core);
- if (core->cnt >= (uint32_t)INT32MAX) {
- core->cnt = 0;
- } else {
- core->cnt--;
- }
- spinrwlockunlock(core);
-}
-
-
-/**
- * Promote a reader lock to the writer lock.
- */
-bool SpinRWLock::promote() {
- _assert_(true);
- SpinRWLockCore* core = (SpinRWLockCore*)opq_;
- spinrwlocklock(core);
- if (core->cnt > 1) {
- spinrwlockunlock(core);
- return false;
- }
- core->cnt = INT32MAX;
- spinrwlockunlock(core);
- return true;
-}
-
-
-/**
- * Demote the writer lock to a reader lock.
- */
-void SpinRWLock::demote() {
- _assert_(true);
- SpinRWLockCore* core = (SpinRWLockCore*)opq_;
- spinrwlocklock(core);
- core->cnt = 1;
- spinrwlockunlock(core);
-}
-
-
-/**
- * Lock the semephore of SpinRWLock.
- */
-static void spinrwlocklock(SpinRWLockCore* core) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(core);
- while (::InterlockedCompareExchange(&core->sem, 1, 0) != 0) {
- ::Sleep(0);
- }
-#elif _KC_GCCATOMIC
- _assert_(core);
- while (!__sync_bool_compare_and_swap(&core->sem, 0, 1)) {
- ::sched_yield();
- }
-#else
- _assert_(core);
- if (::pthread_spin_lock(&core->sem) != 0) throw std::runtime_error("pthread_spin_lock");
-#endif
-}
-
-
-/**
- * Unlock the semephore of SpinRWLock.
- */
-static void spinrwlockunlock(SpinRWLockCore* core) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(core);
- ::InterlockedExchange(&core->sem, 0);
-#elif _KC_GCCATOMIC
- _assert_(core);
- __sync_lock_release(&core->sem);
-#else
- _assert_(core);
- if (::pthread_spin_unlock(&core->sem) != 0) throw std::runtime_error("pthread_spin_unlock");
-#endif
-}
-
-
-/**
- * SlottedRWLock internal.
- */
-struct SlottedSpinRWLockCore {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- LONG sems[LOCKSEMNUM]; ///< semaphores
-#elif _KC_GCCATOMIC
- int32_t sems[LOCKSEMNUM]; ///< semaphores
-#else
- ::pthread_spinlock_t sems[LOCKSEMNUM]; ///< semaphores
-#endif
- uint32_t* cnts; ///< counts of threads
- size_t slotnum; ///< number of slots
-};
-
-
-/**
- * Lock the semephore of SlottedSpinRWLock.
- * @param core the internal fields.
- * @param idx the index of the semaphoe.
- */
-static void slottedspinrwlocklock(SlottedSpinRWLockCore* core, size_t idx);
-
-
-/**
- * Unlock the semephore of SlottedSpinRWLock.
- * @param core the internal fields.
- * @param idx the index of the semaphoe.
- */
-static void slottedspinrwlockunlock(SlottedSpinRWLockCore* core, size_t idx);
-
-
-/**
- * Constructor.
- */
-SlottedSpinRWLock::SlottedSpinRWLock(size_t slotnum) : opq_(NULL) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- SlottedSpinRWLockCore* core = new SlottedSpinRWLockCore;
- LONG* sems = core->sems;
- uint32_t* cnts = new uint32_t[slotnum];
- for (size_t i = 0; i < LOCKSEMNUM; i++) {
- sems[i] = 0;
- }
- for (size_t i = 0; i < slotnum; i++) {
- cnts[i] = 0;
- }
- core->cnts = cnts;
- core->slotnum = slotnum;
- opq_ = (void*)core;
-#elif _KC_GCCATOMIC
- SlottedSpinRWLockCore* core = new SlottedSpinRWLockCore;
- int32_t* sems = core->sems;
- uint32_t* cnts = new uint32_t[slotnum];
- for (size_t i = 0; i < LOCKSEMNUM; i++) {
- sems[i] = 0;
- }
- for (size_t i = 0; i < slotnum; i++) {
- cnts[i] = 0;
- }
- core->cnts = cnts;
- core->slotnum = slotnum;
- opq_ = (void*)core;
-#else
- _assert_(true);
- SlottedSpinRWLockCore* core = new SlottedSpinRWLockCore;
- ::pthread_spinlock_t* sems = core->sems;
- uint32_t* cnts = new uint32_t[slotnum];
- for (size_t i = 0; i < LOCKSEMNUM; i++) {
- if (::pthread_spin_init(sems + i, PTHREAD_PROCESS_PRIVATE) != 0)
- throw std::runtime_error("pthread_spin_init");
- }
- for (size_t i = 0; i < slotnum; i++) {
- cnts[i] = 0;
- }
- core->cnts = cnts;
- core->slotnum = slotnum;
- opq_ = (void*)core;
-#endif
-}
-
-
-/**
- * Destructor.
- */
-SlottedSpinRWLock::~SlottedSpinRWLock() {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || _KC_GCCATOMIC
- _assert_(true);
- SlottedSpinRWLockCore* core = (SlottedSpinRWLockCore*)opq_;
- delete[] core->cnts;
- delete core;
-#else
- _assert_(true);
- SlottedSpinRWLockCore* core = (SlottedSpinRWLockCore*)opq_;
- ::pthread_spinlock_t* sems = core->sems;
- for (size_t i = 0; i < LOCKSEMNUM; i++) {
- ::pthread_spin_destroy(sems + i);
- }
- delete[] core->cnts;
- delete core;
-#endif
-}
-
-
-/**
- * Get the writer lock of a slot.
- */
-void SlottedSpinRWLock::lock_writer(size_t idx) {
- _assert_(true);
- SlottedSpinRWLockCore* core = (SlottedSpinRWLockCore*)opq_;
- size_t semidx = idx % LOCKSEMNUM;
- slottedspinrwlocklock(core, semidx);
- uint32_t wcnt = 0;
- while (core->cnts[idx] > 0) {
- slottedspinrwlockunlock(core, semidx);
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- slottedspinrwlocklock(core, semidx);
- }
- core->cnts[idx] = INT32MAX;
- slottedspinrwlockunlock(core, semidx);
-}
-
-
-/**
- * Get the reader lock of a slot.
- */
-void SlottedSpinRWLock::lock_reader(size_t idx) {
- _assert_(true);
- SlottedSpinRWLockCore* core = (SlottedSpinRWLockCore*)opq_;
- size_t semidx = idx % LOCKSEMNUM;
- slottedspinrwlocklock(core, semidx);
- uint32_t wcnt = 0;
- while (core->cnts[idx] >= (uint32_t)INT32MAX) {
- slottedspinrwlockunlock(core, semidx);
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- slottedspinrwlocklock(core, semidx);
- }
- core->cnts[idx]++;
- slottedspinrwlockunlock(core, semidx);
-}
-
-
-/**
- * Release the lock of a slot.
- */
-void SlottedSpinRWLock::unlock(size_t idx) {
- _assert_(true);
- SlottedSpinRWLockCore* core = (SlottedSpinRWLockCore*)opq_;
- size_t semidx = idx % LOCKSEMNUM;
- slottedspinrwlocklock(core, semidx);
- if (core->cnts[idx] >= (uint32_t)INT32MAX) {
- core->cnts[idx] = 0;
- } else {
- core->cnts[idx]--;
- }
- slottedspinrwlockunlock(core, semidx);
-}
-
-
-/**
- * Get the writer locks of all slots.
- */
-void SlottedSpinRWLock::lock_writer_all() {
- _assert_(true);
- SlottedSpinRWLockCore* core = (SlottedSpinRWLockCore*)opq_;
- uint32_t* cnts = core->cnts;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- size_t semidx = i % LOCKSEMNUM;
- slottedspinrwlocklock(core, semidx);
- uint32_t wcnt = 0;
- while (cnts[i] > 0) {
- slottedspinrwlockunlock(core, semidx);
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- slottedspinrwlocklock(core, semidx);
- }
- cnts[i] = INT32MAX;
- slottedspinrwlockunlock(core, semidx);
- }
-}
-
-
-/**
- * Get the reader locks of all slots.
- */
-void SlottedSpinRWLock::lock_reader_all() {
- _assert_(true);
- SlottedSpinRWLockCore* core = (SlottedSpinRWLockCore*)opq_;
- uint32_t* cnts = core->cnts;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- size_t semidx = i % LOCKSEMNUM;
- slottedspinrwlocklock(core, semidx);
- uint32_t wcnt = 0;
- while (cnts[i] >= (uint32_t)INT32MAX) {
- slottedspinrwlockunlock(core, semidx);
- if (wcnt >= LOCKBUSYLOOP) {
- Thread::chill();
- } else {
- Thread::yield();
- wcnt++;
- }
- slottedspinrwlocklock(core, semidx);
- }
- cnts[i]++;
- slottedspinrwlockunlock(core, semidx);
- }
-}
-
-
-/**
- * Release the locks of all slots.
- */
-void SlottedSpinRWLock::unlock_all() {
- _assert_(true);
- SlottedSpinRWLockCore* core = (SlottedSpinRWLockCore*)opq_;
- uint32_t* cnts = core->cnts;
- size_t slotnum = core->slotnum;
- for (size_t i = 0; i < slotnum; i++) {
- size_t semidx = i % LOCKSEMNUM;
- slottedspinrwlocklock(core, semidx);
- if (cnts[i] >= (uint32_t)INT32MAX) {
- cnts[i] = 0;
- } else {
- cnts[i]--;
- }
- slottedspinrwlockunlock(core, semidx);
- }
-}
-
-
-/**
- * Lock the semephore of SlottedSpinRWLock.
- */
-static void slottedspinrwlocklock(SlottedSpinRWLockCore* core, size_t idx) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(core);
- while (::InterlockedCompareExchange(core->sems + idx, 1, 0) != 0) {
- ::Sleep(0);
- }
-#elif _KC_GCCATOMIC
- _assert_(core);
- while (!__sync_bool_compare_and_swap(core->sems + idx, 0, 1)) {
- ::sched_yield();
- }
-#else
- _assert_(core);
- if (::pthread_spin_lock(core->sems + idx) != 0) throw std::runtime_error("pthread_spin_lock");
-#endif
-}
-
-
-/**
- * Unlock the semephore of SlottedSpinRWLock.
- */
-static void slottedspinrwlockunlock(SlottedSpinRWLockCore* core, size_t idx) {
-#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_)
- _assert_(core);
- ::InterlockedExchange(core->sems + idx, 0);
-#elif _KC_GCCATOMIC
- _assert_(core);
- __sync_lock_release(core->sems + idx);
-#else
- _assert_(core);
- if (::pthread_spin_unlock(core->sems + idx) != 0)
- throw std::runtime_error("pthread_spin_unlock");
-#endif
-}
/**
@@ -2063,10 +920,8 @@ int64_t AtomicInt64::set(int64_t val) {
return oval;
#else
_assert_(true);
- lock_.lock();
int64_t oval = value_;
value_ = val;
- lock_.unlock();
return oval;
#endif
}
@@ -2086,10 +941,8 @@ int64_t AtomicInt64::add(int64_t val) {
return oval;
#else
_assert_(true);
- lock_.lock();
int64_t oval = value_;
value_ += val;
- lock_.unlock();
return oval;
#endif
}
@@ -2110,12 +963,10 @@ bool AtomicInt64::cas(int64_t oval, int64_t nval) {
#else
_assert_(true);
bool rv = false;
- lock_.lock();
if (value_ == oval) {
value_ = nval;
rv = true;
}
- lock_.unlock();
return rv;
#endif
}
@@ -2133,9 +984,7 @@ int64_t AtomicInt64::get() const {
return __sync_fetch_and_add((int64_t*)&value_, 0);
#else
_assert_(true);
- lock_.lock();
int64_t oval = value_;
- lock_.unlock();
return oval;
#endif
}
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h b/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h
index 7b77bbd909..e570411ec4 100644
--- a/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h
+++ b/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h
@@ -209,373 +209,6 @@ class SlottedMutex {
/**
- * Lightweight mutual exclusion device.
- */
-class SpinLock {
- public:
- /**
- * Default constructor.
- */
- explicit SpinLock();
- /**
- * Destructor.
- */
- ~SpinLock();
- /**
- * Get the lock.
- */
- void lock();
- /**
- * Try to get the lock.
- * @return true on success, or false on failure.
- */
- bool lock_try();
- /**
- * Release the lock.
- */
- void unlock();
- private:
- /** Dummy constructor to forbid the use. */
- SpinLock(const SpinLock&);
- /** Dummy Operator to forbid the use. */
- SpinLock& operator =(const SpinLock&);
- /** Opaque pointer. */
- void* opq_;
-};
-
-
-/**
- * Scoped spin lock device.
- */
-class ScopedSpinLock {
- public:
- /**
- * Constructor.
- * @param spinlock a spin lock to lock the block.
- */
- explicit ScopedSpinLock(SpinLock* spinlock) : spinlock_(spinlock) {
- _assert_(spinlock);
- spinlock_->lock();
- }
- /**
- * Destructor.
- */
- ~ScopedSpinLock() {
- _assert_(true);
- spinlock_->unlock();
- }
- private:
- /** Dummy constructor to forbid the use. */
- ScopedSpinLock(const ScopedSpinLock&);
- /** Dummy Operator to forbid the use. */
- ScopedSpinLock& operator =(const ScopedSpinLock&);
- /** The inner device. */
- SpinLock* spinlock_;
-};
-
-
-/**
- * Slotted spin lock devices.
- */
-class SlottedSpinLock {
- public:
- /**
- * Constructor.
- * @param slotnum the number of slots.
- */
- explicit SlottedSpinLock(size_t slotnum);
- /**
- * Destructor.
- */
- ~SlottedSpinLock();
- /**
- * Get the lock of a slot.
- * @param idx the index of a slot.
- */
- void lock(size_t idx);
- /**
- * Release the lock of a slot.
- * @param idx the index of a slot.
- */
- void unlock(size_t idx);
- /**
- * Get the locks of all slots.
- */
- void lock_all();
- /**
- * Release the locks of all slots.
- */
- void unlock_all();
- private:
- /** Opaque pointer. */
- void* opq_;
-};
-
-
-/**
- * Reader-writer locking device.
- */
-class RWLock {
- public:
- /**
- * Default constructor.
- */
- explicit RWLock();
- /**
- * Destructor.
- */
- ~RWLock();
- /**
- * Get the writer lock.
- */
- void lock_writer();
- /**
- * Try to get the writer lock.
- * @return true on success, or false on failure.
- */
- bool lock_writer_try();
- /**
- * Get a reader lock.
- */
- void lock_reader();
- /**
- * Try to get a reader lock.
- * @return true on success, or false on failure.
- */
- bool lock_reader_try();
- /**
- * Release the lock.
- */
- void unlock();
- private:
- /** Dummy constructor to forbid the use. */
- RWLock(const RWLock&);
- /** Dummy Operator to forbid the use. */
- RWLock& operator =(const RWLock&);
- /** Opaque pointer. */
- void* opq_;
-};
-
-
-/**
- * Scoped reader-writer locking device.
- */
-class ScopedRWLock {
- public:
- /**
- * Constructor.
- * @param rwlock a rwlock to lock the block.
- * @param writer true for writer lock, or false for reader lock.
- */
- explicit ScopedRWLock(RWLock* rwlock, bool writer) : rwlock_(rwlock) {
- _assert_(rwlock);
- if (writer) {
- rwlock_->lock_writer();
- } else {
- rwlock_->lock_reader();
- }
- }
- /**
- * Destructor.
- */
- ~ScopedRWLock() {
- _assert_(true);
- rwlock_->unlock();
- }
- private:
- /** Dummy constructor to forbid the use. */
- ScopedRWLock(const ScopedRWLock&);
- /** Dummy Operator to forbid the use. */
- ScopedRWLock& operator =(const ScopedRWLock&);
- /** The inner device. */
- RWLock* rwlock_;
-};
-
-
-/**
- * Slotted reader-writer lock devices.
- */
-class SlottedRWLock {
- public:
- /**
- * Constructor.
- * @param slotnum the number of slots.
- */
- explicit SlottedRWLock(size_t slotnum);
- /**
- * Destructor.
- */
- ~SlottedRWLock();
- /**
- * Get the writer lock of a slot.
- * @param idx the index of a slot.
- */
- void lock_writer(size_t idx);
- /**
- * Get the reader lock of a slot.
- * @param idx the index of a slot.
- */
- void lock_reader(size_t idx);
- /**
- * Release the lock of a slot.
- * @param idx the index of a slot.
- */
- void unlock(size_t idx);
- /**
- * Get the writer locks of all slots.
- */
- void lock_writer_all();
- /**
- * Get the reader locks of all slots.
- */
- void lock_reader_all();
- /**
- * Release the locks of all slots.
- */
- void unlock_all();
- private:
- /** Opaque pointer. */
- void* opq_;
-};
-
-
-/**
- * Lightweight reader-writer locking device.
- */
-class SpinRWLock {
- public:
- /**
- * Default constructor.
- */
- explicit SpinRWLock();
- /**
- * Destructor.
- */
- ~SpinRWLock();
- /**
- * Get the writer lock.
- */
- void lock_writer();
- /**
- * Try to get the writer lock.
- * @return true on success, or false on failure.
- */
- bool lock_writer_try();
- /**
- * Get a reader lock.
- */
- void lock_reader();
- /**
- * Try to get a reader lock.
- * @return true on success, or false on failure.
- */
- bool lock_reader_try();
- /**
- * Release the lock.
- */
- void unlock();
- /**
- * Promote a reader lock to the writer lock.
- * @return true on success, or false on failure.
- */
- bool promote();
- /**
- * Demote the writer lock to a reader lock.
- */
- void demote();
- private:
- /** Dummy constructor to forbid the use. */
- SpinRWLock(const SpinRWLock&);
- /** Dummy Operator to forbid the use. */
- SpinRWLock& operator =(const SpinRWLock&);
- /** Opaque pointer. */
- void* opq_;
-};
-
-
-/**
- * Scoped reader-writer locking device.
- */
-class ScopedSpinRWLock {
- public:
- /**
- * Constructor.
- * @param srwlock a spin rwlock to lock the block.
- * @param writer true for writer lock, or false for reader lock.
- */
- explicit ScopedSpinRWLock(SpinRWLock* srwlock, bool writer) : srwlock_(srwlock) {
- _assert_(srwlock);
- if (writer) {
- srwlock_->lock_writer();
- } else {
- srwlock_->lock_reader();
- }
- }
- /**
- * Destructor.
- */
- ~ScopedSpinRWLock() {
- _assert_(true);
- srwlock_->unlock();
- }
- private:
- /** Dummy constructor to forbid the use. */
- ScopedSpinRWLock(const ScopedSpinRWLock&);
- /** Dummy Operator to forbid the use. */
- ScopedSpinRWLock& operator =(const ScopedSpinRWLock&);
- /** The inner device. */
- SpinRWLock* srwlock_;
-};
-
-
-/**
- * Slotted lightweight reader-writer lock devices.
- */
-class SlottedSpinRWLock {
- public:
- /**
- * Constructor.
- * @param slotnum the number of slots.
- */
- explicit SlottedSpinRWLock(size_t slotnum);
- /**
- * Destructor.
- */
- ~SlottedSpinRWLock();
- /**
- * Get the writer lock of a slot.
- * @param idx the index of a slot.
- */
- void lock_writer(size_t idx);
- /**
- * Get the reader lock of a slot.
- * @param idx the index of a slot.
- */
- void lock_reader(size_t idx);
- /**
- * Release the lock of a slot.
- * @param idx the index of a slot.
- */
- void unlock(size_t idx);
- /**
- * Get the writer locks of all slots.
- */
- void lock_writer_all();
- /**
- * Get the reader locks of all slots.
- */
- void lock_reader_all();
- /**
- * Release the locks of all slots.
- */
- void unlock_all();
- private:
- /** Opaque pointer. */
- void* opq_;
-};
-
-
-/**
* Condition variable.
*/
class CondVar {
@@ -934,21 +567,21 @@ class AtomicInt64 {
/**
* Default constructor.
*/
- explicit AtomicInt64() : value_(0), lock_() {
+ explicit AtomicInt64() : value_(0) {
_assert_(true);
}
/**
* Copy constructor.
* @param src the source object.
*/
- AtomicInt64(const AtomicInt64& src) : value_(src.get()), lock_() {
+ AtomicInt64(const AtomicInt64& src) : value_(src.get()) {
_assert_(true);
};
/**
* Constructor.
* @param num the initial value.
*/
- AtomicInt64(int64_t num) : value_(num), lock_() {
+ AtomicInt64(int64_t num) : value_(num) {
_assert_(true);
}
/**
@@ -1047,8 +680,6 @@ class AtomicInt64 {
private:
/** The value. */
volatile int64_t value_;
- /** The alternative lock. */
- mutable SpinLock lock_;
};
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h
index d4b8a587a5..4183e6cd18 100644
--- a/plugins/Dbx_mdb/src/dbintf.h
+++ b/plugins/Dbx_mdb/src/dbintf.h
@@ -269,6 +269,7 @@ protected:
HANDLE hEventAddedEvent, hEventDeletedEvent, hEventFilterAddedEvent;
MCONTACT m_hLastCachedContact;
int m_maxModuleID;
+ ModuleName *m_lastmn;
void AddToList(char *name, DWORD ofs);
DWORD FindExistingModuleNameOfs(const char *szName);
diff --git a/plugins/Dbx_mdb/src/dbmodulechain.cpp b/plugins/Dbx_mdb/src/dbmodulechain.cpp
index 9342ea3cb1..fc33b8de8b 100644
--- a/plugins/Dbx_mdb/src/dbmodulechain.cpp
+++ b/plugins/Dbx_mdb/src/dbmodulechain.cpp
@@ -71,10 +71,15 @@ int CDbxMdb::InitModuleNames(void)
DWORD CDbxMdb::FindExistingModuleNameOfs(const char *szName)
{
ModuleName mn = { (char*)szName, 0 };
+ if (m_lastmn && !strcmp(mn.name, m_lastmn->name))
+ return m_lastmn->ofs;
int index = m_lMods.getIndex(&mn);
- if (index != -1)
- return m_lMods[index]->ofs;
+ if (index != -1) {
+ ModuleName *pmn = m_lMods[index];
+ m_lastmn = pmn;
+ return pmn->ofs;
+ }
return 0;
}