Skip to content

Commit

Permalink
Fix thread-safety on PolConfig (#639)
Browse files Browse the repository at this point in the history
* Implementation, tests, core-changes

* More decay-based options to atomic
  • Loading branch information
KevinEady committed Apr 14, 2024
1 parent 1a2668e commit b01a6a6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
8 changes: 7 additions & 1 deletion docs/docs.polserver.com/pol100/corechanges.xml
Expand Up @@ -2,9 +2,15 @@
<ESCRIPT>
<header>
<topic>Latest Core Changes</topic>
<datemodified>03-24-2024</datemodified>
<datemodified>04-12-2024</datemodified>
</header>
<version name="POL100.2.0">
<entry>
<date>04-12-2024</date>
<author>Kevin:</author>
<change type="Changed">For thread-safety, the debug password in pol.cfg may no longer be changed<br/>
when the server is running.</change>
</entry>
<entry>
<date>03-24-2024</date>
<author>Kevin:</author>
Expand Down
3 changes: 3 additions & 0 deletions pol-core/doc/core-changes.txt
@@ -1,4 +1,7 @@
-- POL100.2.0 --
04-12-2024 Kevin:
Changed: For thread-safety, the debug password in pol.cfg may no longer be changed
when the server is running.
03-24-2024 Kevin:
Added: `lastrealm` parameter to WalkOnScript.
Added: Boat WalkOnScript now triggers in the same manner as other Multis and Items.
Expand Down
4 changes: 2 additions & 2 deletions pol-core/pol/polcfg.cpp
Expand Up @@ -98,6 +98,8 @@ void PolConfig::read_pol_config( bool initial_load )

Plib::systemstate.config.debug_port = elem.remove_ushort( "DebugPort", 0 );
Plib::systemstate.config.dap_debug_port = elem.remove_ushort( "DAPDebugPort", 0 );
Plib::systemstate.config.debug_password = elem.remove_string( "DebugPassword", "" );
Plib::systemstate.config.debug_local_only = elem.remove_bool( "DebugLocalOnly", true );

Plib::systemstate.config.account_save = elem.remove_int( "AccountDataSave", -1 );
if ( Plib::systemstate.config.account_save > 0 )
Expand Down Expand Up @@ -222,8 +224,6 @@ void PolConfig::read_pol_config( bool initial_load )
elem.remove_bool( "DisplayUnknownPackets", false );
Plib::systemstate.config.exp_los_checks_map = elem.remove_bool( "ExpLosChecksMap", true );
Plib::systemstate.config.enable_debug_log = elem.remove_bool( "EnableDebugLog", false );
Plib::systemstate.config.debug_password = elem.remove_string( "DebugPassword", "" );
Plib::systemstate.config.debug_local_only = elem.remove_bool( "DebugLocalOnly", true );

Plib::systemstate.config.log_traces_when_stuck =
elem.remove_bool( "ThreadStacktracesWhenStuck", false );
Expand Down
7 changes: 4 additions & 3 deletions pol-core/pol/polcfg.h
Expand Up @@ -30,7 +30,7 @@ struct PolConfig
std::string realm_data_path;
std::string pidfile_path;
std::atomic<bool> verbose;
unsigned short loglevel; // 0=nothing 10=lots
std::atomic<unsigned short> loglevel; // 0=nothing 10=lots
unsigned short select_timeout_usecs;
unsigned short loginserver_timeout_mins;
bool watch_rpm;
Expand Down Expand Up @@ -69,6 +69,7 @@ struct PolConfig
bool exp_los_checks_map;
bool enable_debug_log;

// Debugger properties must be only when initial_load is true in read_pol_config.
unsigned short debug_port;
unsigned short dap_debug_port;
std::string debug_password;
Expand All @@ -94,8 +95,8 @@ struct PolConfig
bool disable_nagle;
bool show_realm_info;
bool enforce_mount_objtype;
bool single_thread_decay;
bool thread_decay_statistics;
std::atomic<bool> single_thread_decay;
std::atomic<bool> thread_decay_statistics;

bool show_warning_gump;
bool show_warning_item;
Expand Down
7 changes: 4 additions & 3 deletions pol-core/pol/ssopt.h
Expand Up @@ -25,6 +25,7 @@
#ifndef SSOPT_H
#define SSOPT_H

#include <atomic>
#include <string>
#include <vector>

Expand All @@ -41,9 +42,9 @@ struct ServSpecOpt
{
bool allow_secure_trading_in_warmode;
unsigned int dblclick_wait;
bool decay_items;
unsigned int default_decay_time;
bool refresh_decay_after_boat_moves;
std::atomic<bool> decay_items;
std::atomic<unsigned int> default_decay_time;
std::atomic<bool> refresh_decay_after_boat_moves;
unsigned short default_doubleclick_range;
unsigned short default_accessible_range;
unsigned short default_light_level;
Expand Down
11 changes: 6 additions & 5 deletions testsuite/pol/scripts/tests.src
Expand Up @@ -6,6 +6,7 @@ use file;
include "testutil";

program tests()
ReloadConfiguration(); // A crude attempt to catch issues with thread-safety and pol config & ssopts.
var test_count:=CInt(GetEnvironmentVariable("POLCORE_TEST_RUN"));
syslog(
$"\n{CONSOLE_COLOR_CYAN}##########################\n"
Expand All @@ -29,7 +30,7 @@ program tests()
if (restartpkg)
testpkgs.append(restartpkg);
endif

var filter:=GetEnvironmentVariable("POLCORE_TEST_FILTER");
if (filter)
syslog("## using testfilter \""+filter+"\"\n",0,CONSOLE_COLOR_CYAN);
Expand All @@ -39,7 +40,7 @@ program tests()
if (filter and !pkg[1].find(filter))
continue;
endif

if (test_count==2 and pkg[1]!="testrestart")
continue;
endif
Expand Down Expand Up @@ -76,11 +77,11 @@ program tests()
if (script[2] == IGNORE_TEST)
continue;
endif

foreach func in (script[1].exported_functions)
var startms:=ReadMillisecondClock();
syslog(" Calling {}..".format(func),0,CONSOLE_COLOR_GREEN);
var res:=script[1].call(func);
var res:=script[1].call(func);
if (res != 1)
syslog(" failed: "+res.errortext,0,CONSOLE_COLOR_RED);
exitcode:=1;
Expand All @@ -98,7 +99,7 @@ program tests()
endif
syslog("..{}ms".format(ReadMillisecondClock()-pkgstartms),0,CONSOLE_COLOR_MAGENTA);
endforeach

var result:=$"{CONSOLE_COLOR_GREEN}success";
if (exitcode)
result:=$"{CONSOLE_COLOR_RED}failed ";
Expand Down

0 comments on commit b01a6a6

Please sign in to comment.