Skip to content

Commit

Permalink
add a new mutex lock; standardise lookup values
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenpham committed Sep 8, 2018
1 parent 36e499d commit fb0f643
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.o
*.exe
*.dll
*.zip
.vs
x64
FelicityEgtb.xcodeproj/project.xcworkspace/xcshareddata
FelicityEgtb.xcodeproj/project.xcworkspace/xcuserdata/
Binary file not shown.
13 changes: 10 additions & 3 deletions source/EgtbLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void EgtbLookup::removeBuffers() {
if (pCompressBuf) free(pCompressBuf);

reset();

loadStatus = EgtbLoadStatus::none;
}

std::string EgtbLookup::getName() const {
Expand Down Expand Up @@ -335,17 +337,22 @@ int EgtbLookup::getCell(int groupIdx, int itemidx, int subIdx) {

const int8_t* pScore = data[groupIdx];
i64 idx = (itemidx - startpos[groupIdx]) * luGroupSizes[groupIdx] + subIdx;

int score = (int)pScore[idx];
if (score != 0) {
if (isVersion2()) {
score = EgtbFile::cellToScore(score);
} else if (score != 0) {
score += score > 0 ? EGTB_SCORE_BASE : -EGTB_SCORE_BASE;
}

return score;
}

int EgtbLookup::lookup(const int* pieceList, Side side, const int* idxArr, const i64* idxMult, u32 order) {
if (loadStatus == EgtbLoadStatus::none) {
_preload();
std::lock_guard<std::mutex> thelock(loadMutex);
if (loadStatus == EgtbLoadStatus::none) {
_preload();
}
}

if (loadStatus == EgtbLoadStatus::error) {
Expand Down
8 changes: 7 additions & 1 deletion source/EgtbLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace egtb {
const int EGTBLU_HEADER_SIZE = 48;
const int EGTBLU_HEADER_SIGN = 1765;
const int EGTBLU_PROPERTY_COMPRESS = (1 << 4);
const int EGTBLU_PROPERTY_VERSION_2 = (1 << 5);

const int EGTBLU_COMPRESS_BLOCK_SIZE = (7 * 22 * 32);
const int EGTBLU_SMART_MODE_THRESHOLD = 10L * 1024 * 1024L;

Expand Down Expand Up @@ -66,6 +68,10 @@ namespace egtb {

void removeBuffers();

bool isVersion2() const {
return property & EGTBLU_PROPERTY_VERSION_2;
}

private:
u32* keyTable;
u32* blockTable;
Expand All @@ -81,7 +87,7 @@ namespace egtb {
EgtbLoadMode loadMode;
EgtbLoadStatus loadStatus;

std::mutex mtx;
std::mutex mtx, loadMutex;

int getScore(i64 key, int groupIdx, int subIdx);
int getCell(int groupIdx, int itemidx, int subIdx);
Expand Down

0 comments on commit fb0f643

Please sign in to comment.