Changeset - r25710:60c9c8536270
[Not reviewed]
master
0 2 0
Patric Stout - 3 years ago 2021-06-17 16:58:59
truebrain@openttd.org
Fix: thread safety issue during exiting the game (#9380)

_exit_game is read by the draw-thread to know when to exit, but
most of the time written by the game-thread.
2 files changed with 3 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -38,13 +38,13 @@ uint16 _game_speed = 100; ///< Current g
 
bool _left_button_down;     ///< Is left mouse button pressed?
 
bool _left_button_clicked;  ///< Is left mouse button clicked?
 
bool _right_button_down;    ///< Is right mouse button pressed?
 
bool _right_button_clicked; ///< Is right mouse button clicked?
 
DrawPixelInfo _screen;
 
bool _screen_disable_anim = false;   ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
 
bool _exit_game;
 
std::atomic<bool> _exit_game;
 
GameMode _game_mode;
 
SwitchMode _switch_mode;  ///< The next mainloop command.
 
PauseMode _pause_mode;
 
Palette _cur_palette;
 

	
 
static byte _stringwidth_table[FS_END][224]; ///< Cache containing width of often used characters. @see GetCharacterWidth()
src/openttd.h
Show inline comments
 
@@ -7,12 +7,13 @@
 

	
 
/** @file openttd.h Some generic types. */
 

	
 
#ifndef OPENTTD_H
 
#define OPENTTD_H
 

	
 
#include <atomic>
 
#include "core/enum_type.hpp"
 

	
 
/** Mode which defines the state of the game. */
 
enum GameMode {
 
	GM_MENU,
 
	GM_NORMAL,
 
@@ -49,13 +50,13 @@ enum DisplayOptions {
 
	DO_SHOW_WAYPOINT_NAMES = 6, ///< Display waypoint names.
 
	DO_SHOW_COMPETITOR_SIGNS = 7, ///< Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are always shown, even if this option is turned off.
 
};
 

	
 
extern GameMode _game_mode;
 
extern SwitchMode _switch_mode;
 
extern bool _exit_game;
 
extern std::atomic<bool> _exit_game;
 
extern bool _save_config;
 

	
 
/** Modes of pausing we've got */
 
enum PauseMode : byte {
 
	PM_UNPAUSED              = 0,      ///< A normal unpaused game
 
	PM_PAUSED_NORMAL         = 1 << 0, ///< A game normally paused
0 comments (0 inline, 0 general)