summaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-06-11 13:58:43 +0200
committerGitHub <noreply@github.com>2017-06-11 13:58:43 +0200
commit65819f3b9f8229666a30b91ef2d289ebc6085097 (patch)
tree722ba29a49ea1707c1db2633b2e84c5c7ebfe2eb /src/server.cpp
parentff73c7a5da6ab8ac0bb678ebf25b83e805397029 (diff)
downloadminetest-65819f3b9f8229666a30b91ef2d289ebc6085097.tar.gz
minetest-65819f3b9f8229666a30b91ef2d289ebc6085097.tar.bz2
minetest-65819f3b9f8229666a30b91ef2d289ebc6085097.zip
Use thread_local instead from some static settings (#5955)
thread_local permits to limit variable lifetime to thread duration. Use it on each setting place which uses static to cache variable result only for thread lifetime. This permits to keep the same performance level & reconfigure server from MT gui in those various variables places. Add thread_local to undersampling calculation too.
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/server.cpp b/src/server.cpp
index 5911bbaf1..a6af742a5 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -638,14 +638,15 @@ void Server::AsyncRunStep(bool initial_step)
ScopeProfiler sp(g_profiler, "Server: checking added and deleted objs");
// Radius inside which objects are active
- static const s16 radius =
+ static thread_local const s16 radius =
g_settings->getS16("active_object_send_range_blocks") * MAP_BLOCKSIZE;
// Radius inside which players are active
- static const bool is_transfer_limited =
+ static thread_local const bool is_transfer_limited =
g_settings->exists("unlimited_player_transfer_distance") &&
!g_settings->getBool("unlimited_player_transfer_distance");
- static const s16 player_transfer_dist = g_settings->getS16("player_transfer_distance") * MAP_BLOCKSIZE;
+ static thread_local const s16 player_transfer_dist =
+ g_settings->getS16("player_transfer_distance") * MAP_BLOCKSIZE;
s16 player_radius = player_transfer_dist;
if (player_radius == 0 && is_transfer_limited)
player_radius = radius;
@@ -982,7 +983,7 @@ void Server::AsyncRunStep(bool initial_step)
{
float &counter = m_savemap_timer;
counter += dtime;
- static const float save_interval =
+ static thread_local const float save_interval =
g_settings->getFloat("server_map_save_interval");
if (counter >= save_interval) {
counter = 0.0;
@@ -1684,7 +1685,7 @@ void Server::SendSpawnParticle(u16 peer_id, u16 protocol_version,
const struct TileAnimationParams &animation, u8 glow)
{
DSTACK(FUNCTION_NAME);
- static const float radius =
+ static thread_local const float radius =
g_settings->getS16("max_block_send_distance") * MAP_BLOCKSIZE * BS;
if (peer_id == PEER_ID_INEXISTENT) {
@@ -3676,8 +3677,9 @@ void dedicated_server_loop(Server &server, bool &kill)
IntervalLimiter m_profiler_interval;
- static const float steplen = g_settings->getFloat("dedicated_server_step");
- static const float profiler_print_interval =
+ static thread_local const float steplen =
+ g_settings->getFloat("dedicated_server_step");
+ static thread_local const float profiler_print_interval =
g_settings->getFloat("profiler_print_interval");
for(;;) {