Author: cazfi
Date: Tue Jan  6 21:38:24 2015
New Revision: 27561

URL: http://svn.gna.org/viewcvs/freeciv?rev=27561&view=rev
Log:
Do not queue messages for threaded AI player thread when it's not running.

See bug #23146

Modified:
    trunk/ai/threaded/taimsg.c
    trunk/ai/threaded/taiplayer.c
    trunk/ai/threaded/taiplayer.h

Modified: trunk/ai/threaded/taimsg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threaded/taimsg.c?rev=27561&r1=27560&r2=27561&view=diff
==============================================================================
--- trunk/ai/threaded/taimsg.c  (original)
+++ trunk/ai/threaded/taimsg.c  Tue Jan  6 21:38:24 2015
@@ -26,7 +26,14 @@
 void tai_send_msg(enum taimsgtype type, struct player *pplayer,
                   void *data)
 {
-  struct tai_msg *msg = fc_malloc(sizeof(*msg));
+  struct tai_msg *msg;
+
+  if (!tai_thread_running()) {
+    /* No player thread to send messages to */
+    return;
+  }
+
+  msg = fc_malloc(sizeof(*msg));
 
   msg->type = type;
   msg->plr = pplayer;

Modified: trunk/ai/threaded/taiplayer.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threaded/taiplayer.c?rev=27561&r1=27560&r2=27561&view=diff
==============================================================================
--- trunk/ai/threaded/taiplayer.c       (original)
+++ trunk/ai/threaded/taiplayer.c       Tue Jan  6 21:38:24 2015
@@ -262,7 +262,8 @@
 }
 
 /**************************************************************************
-  Send message to thread.
+  Send message to thread. Be sure that thread is running so that messages
+  are not just piling up to the list without anybody reading them.
 **************************************************************************/
 void tai_msg_to_thr(struct tai_msg *msg)
 {
@@ -281,3 +282,11 @@
   taireq_list_append(thrai.reqs_from.reqlist, req);
   taireq_list_release_mutex(thrai.reqs_from.reqlist);
 }
+
+/**************************************************************************
+  Return whether player thread is running
+**************************************************************************/
+bool tai_thread_running(void)
+{
+  return thrai.thread_running;
+}

Modified: trunk/ai/threaded/taiplayer.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threaded/taiplayer.h?rev=27561&r1=27560&r2=27561&view=diff
==============================================================================
--- trunk/ai/threaded/taiplayer.h       (original)
+++ trunk/ai/threaded/taiplayer.h       Tue Jan  6 21:38:24 2015
@@ -46,6 +46,8 @@
 
 void tai_init_threading(void);
 
+bool tai_thread_running(void);
+
 void tai_player_alloc(struct ai_type *ait, struct player *pplayer);
 void tai_player_free(struct ai_type *ait, struct player *pplayer);
 void tai_control_gained(struct ai_type *ait,struct player *pplayer);


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to