Fixed a bug in sdl threading use in upload_logs
dissallow_observers is forced on if side has controller=null
This commit is contained in:
parent
7acbc98933
commit
6be0e05732
4 changed files with 31 additions and 3 deletions
|
@ -40,6 +40,8 @@ Version 1.5.0+svn:
|
|||
* added option to do gracefull shut down for server
|
||||
* fixed multiplayer_connect to handle leave_game command from server
|
||||
* improved reloading of game configs after installing or removing addons
|
||||
* fixed threading bug in upload_logs
|
||||
* dissallow_observers is forced on if side has controller=null
|
||||
* Removed bug introduced in 1.5.0 that allowed use of :debug commands during
|
||||
network play
|
||||
* added some includes to fix compilation problems with Sun Studio 12
|
||||
|
|
|
@ -176,7 +176,10 @@ team::team_info::team_info(const config& cfg) :
|
|||
else if (control == "network")
|
||||
controller = NETWORK;
|
||||
else if (control == "null")
|
||||
{
|
||||
disallow_observers = true;
|
||||
controller = EMPTY;
|
||||
}
|
||||
else
|
||||
controller = AI;
|
||||
|
||||
|
|
|
@ -44,13 +44,27 @@
|
|||
#define TARGET_PORT 80
|
||||
|
||||
struct upload_log::thread_info upload_log::thread_;
|
||||
upload_log::manager* upload_log::manager_ = 0;
|
||||
|
||||
// On exit, kill the upload thread if it's still going.
|
||||
upload_log::manager::~manager()
|
||||
{
|
||||
upload_log::manager_ = 0;
|
||||
threading::thread *t = thread_.t;
|
||||
if (t)
|
||||
t->kill();
|
||||
t->join();
|
||||
}
|
||||
|
||||
void upload_log::manager::manage()
|
||||
{
|
||||
|
||||
// We have to wait for thread so it won't leak
|
||||
if (thread_.shutdown)
|
||||
{
|
||||
thread_.t->join();
|
||||
thread_.shutdown = false;
|
||||
thread_.t = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void send_string(TCPsocket sock, const std::string &str)
|
||||
|
@ -118,14 +132,17 @@ static int upload_logs(void *_ti)
|
|||
|
||||
if (sock)
|
||||
SDLNet_TCP_Close(sock);
|
||||
ti->t = NULL;
|
||||
ti->shutdown = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Currently only enabled when playing campaigns.
|
||||
upload_log::upload_log(bool enable) : game_(NULL), enabled_(enable)
|
||||
{
|
||||
filename_ = next_filename(get_upload_dir(), 100);
|
||||
if (upload_log::manager_)
|
||||
upload_log::manager_->manage();
|
||||
if (preferences::upload_log() && !thread_.t) {
|
||||
// Thread can outlive us; it uploads everything up to the
|
||||
// next filename, and unsets thread_.t when it's finished.
|
||||
|
@ -152,6 +169,9 @@ upload_log::~upload_log()
|
|||
write(*out, config_);
|
||||
delete out;
|
||||
|
||||
if (upload_log::manager_)
|
||||
upload_log::manager_->manage();
|
||||
|
||||
// Try to upload latest log before exit.
|
||||
if (preferences::upload_log() && !thread_.t) {
|
||||
thread_.lastfile = next_filename(get_upload_dir(), 1000);
|
||||
|
|
|
@ -26,8 +26,9 @@ struct upload_log
|
|||
{
|
||||
public:
|
||||
struct manager {
|
||||
manager() { };
|
||||
manager() {upload_log::manager_ = this;}
|
||||
~manager();
|
||||
void manage();
|
||||
};
|
||||
|
||||
// We only enable logging when playing campaigns.
|
||||
|
@ -47,6 +48,7 @@ public:
|
|||
// Argument passed to upload thread.
|
||||
struct thread_info {
|
||||
threading::thread *t;
|
||||
bool shutdown;
|
||||
std::string lastfile;
|
||||
};
|
||||
|
||||
|
@ -55,6 +57,7 @@ private:
|
|||
bool game_finished(config *game);
|
||||
|
||||
static struct thread_info thread_;
|
||||
static manager* manager_;
|
||||
friend struct manager;
|
||||
|
||||
config config_;
|
||||
|
|
Loading…
Add table
Reference in a new issue