mirror of https://github.com/OpenTTD/OpenTTD
Codefix: potential check of thread-shared field evades lock acquisition
parent
ac2087a3eb
commit
f57b6248a1
|
@ -191,8 +191,8 @@ public:
|
||||||
*/
|
*/
|
||||||
inline void Push(const Titem &item)
|
inline void Push(const Titem &item)
|
||||||
{
|
{
|
||||||
if (this->value != Tinvalid) {
|
|
||||||
std::lock_guard<std::mutex> lock(SmallStack::GetPool().GetMutex());
|
std::lock_guard<std::mutex> lock(SmallStack::GetPool().GetMutex());
|
||||||
|
if (this->value != Tinvalid) {
|
||||||
Tindex new_item = SmallStack::GetPool().Create();
|
Tindex new_item = SmallStack::GetPool().Create();
|
||||||
if (new_item != Tmax_size) {
|
if (new_item != Tmax_size) {
|
||||||
PooledSmallStack &pushed = SmallStack::GetPool().Get(new_item);
|
PooledSmallStack &pushed = SmallStack::GetPool().Get(new_item);
|
||||||
|
@ -211,11 +211,11 @@ public:
|
||||||
*/
|
*/
|
||||||
inline Titem Pop()
|
inline Titem Pop()
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(SmallStack::GetPool().GetMutex());
|
||||||
Titem ret = this->value;
|
Titem ret = this->value;
|
||||||
if (this->next == Tmax_size) {
|
if (this->next == Tmax_size) {
|
||||||
this->value = Tinvalid;
|
this->value = Tinvalid;
|
||||||
} else {
|
} else {
|
||||||
std::lock_guard<std::mutex> lock(SmallStack::GetPool().GetMutex());
|
|
||||||
PooledSmallStack &popped = SmallStack::GetPool().Get(this->next);
|
PooledSmallStack &popped = SmallStack::GetPool().Get(this->next);
|
||||||
this->value = popped.value;
|
this->value = popped.value;
|
||||||
if (popped.branch_count == 0) {
|
if (popped.branch_count == 0) {
|
||||||
|
|
Loading…
Reference in New Issue