mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Attempt to init() just once
In case something goes wrong baseAddress is set to zero and any further attempt to init() returns false. This is a prerequisite for future work.
This commit is contained in:
parent
2e3412fdd0
commit
a12542cbaa
1 changed files with 6 additions and 7 deletions
|
@ -1110,7 +1110,7 @@ void do_init(Entry& e, T& p, uint8_t* data)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Entry>
|
template<typename Entry>
|
||||||
bool init(Entry& e, const Position& pos)
|
void* init(Entry& e, const Position& pos)
|
||||||
{
|
{
|
||||||
const bool IsWDL = std::is_same<Entry, WDLEntry>::value;
|
const bool IsWDL = std::is_same<Entry, WDLEntry>::value;
|
||||||
const uint8_t* MAGIC = IsWDL ? WDL_MAGIC : DTZ_MAGIC;
|
const uint8_t* MAGIC = IsWDL ? WDL_MAGIC : DTZ_MAGIC;
|
||||||
|
@ -1118,12 +1118,12 @@ bool init(Entry& e, const Position& pos)
|
||||||
// Avoid a thread reads 'ready' == true while another is still in do_init(),
|
// Avoid a thread reads 'ready' == true while another is still in do_init(),
|
||||||
// this could happen due to compiler reordering.
|
// this could happen due to compiler reordering.
|
||||||
if (e.ready.load(std::memory_order_acquire))
|
if (e.ready.load(std::memory_order_acquire))
|
||||||
return true;
|
return e.baseAddress;
|
||||||
|
|
||||||
std::unique_lock<Mutex> lk(TB_mutex);
|
std::unique_lock<Mutex> lk(TB_mutex);
|
||||||
|
|
||||||
if (e.ready.load(std::memory_order_relaxed)) // Recheck under lock
|
if (e.ready.load(std::memory_order_relaxed)) // Recheck under lock
|
||||||
return true;
|
return e.baseAddress;
|
||||||
|
|
||||||
std::string fname, w, b;
|
std::string fname, w, b;
|
||||||
|
|
||||||
|
@ -1137,12 +1137,11 @@ bool init(Entry& e, const Position& pos)
|
||||||
+ (IsWDL ? ".rtbw" : ".rtbz");
|
+ (IsWDL ? ".rtbw" : ".rtbz");
|
||||||
|
|
||||||
uint8_t* data = TBFile(fname).map(&e.baseAddress, &e.mapping, MAGIC);
|
uint8_t* data = TBFile(fname).map(&e.baseAddress, &e.mapping, MAGIC);
|
||||||
if (!data)
|
if (data)
|
||||||
return false;
|
|
||||||
|
|
||||||
e.hasPawns ? do_init(e, e.pawn, data) : do_init(e, e.piece, data);
|
e.hasPawns ? do_init(e, e.pawn, data) : do_init(e, e.piece, data);
|
||||||
|
|
||||||
e.ready.store(true, std::memory_order_release);
|
e.ready.store(true, std::memory_order_release);
|
||||||
return true;
|
return e.baseAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename E, typename T = typename Ret<E>::type>
|
template<typename E, typename T = typename Ret<E>::type>
|
||||||
|
|
Loading…
Add table
Reference in a new issue