Skip to content
Permalink
Browse files

fixed shutdown conditions for threads

database prepared transactions closed to soon
recorded end time only once when stopping or quitting
stopped terminating thread early
added debug messages for threading conditions
  • Loading branch information...
Jake Fonseca
Jake Fonseca committed Oct 21, 2014
1 parent c6d1fa6 commit 0d9944e3de66decb44280bb5bd707fa551dc28a5
Showing with 32 additions and 9 deletions.
  1. +19 −3 lib/OCCPGameServer.rb
  2. +13 −6 lib/OCCPGameServer/main.rb
@@ -43,6 +43,8 @@ module OCCPGameServer

include LibXML

$appCore = nil;

# Takes an instance configuration file and returns an instance of the core application.
def self.instance_file_parser(instancefile)

@@ -490,15 +492,29 @@ def self.instance_file_parser(instancefile)


# Wait for Children to exit
userInterface.join
main.join

if userInterface.alive?
$log.debug "Waiting to shutdown UI."
userInterface.join
$log.debug "Shutdown UI complete."
end
if main.alive?
$log.debug "Waiting to shutdown main."
main.join
$log.debug "Shutdown main complete."
end

#Log final times
totalgametime = $appCore.endtime - $appCore.begintime
$log.info "Total game length: #{'%.2f' % totalgametime} sec"
$log.info "Total time paused: #{'%.2f' % (totalgametime - $appCore.gameclock.gametime)} sec"

#Log final scores
$appCore.scoreKeeper.get_names.each{ |scoreName|
$log.info("Score " + scoreName + ': ' + $appCore.scoreKeeper.get_score(scoreName).to_s)
}

#Cleanup and Close Files
$appCore.scoreKeeper.cleanup #close prepared transactions
$db.close

$log.info "GameServer shutdown complete"
@@ -126,11 +126,17 @@ def set_state(state)
team.INBOX << GMessage.new({:fromid=>'Main Thread',:signal=>'COMMAND', :msg=>{:command => 'STATE', :state=> STOP}})
}
@gameclock.pause
@endtime = Time.now
if @endtime == nil
@endtime = Time.now
end
when QUIT
@teams.each { |team|
team.INBOX << GMessage.new({:fromid=>'Main Thread',:signal=>'COMMAND', :msg=>{:command => 'STATE', :state=> STOP}})
}
@gameclock.pause
if @endtime == nil
@endtime = Time.now
end
exit_cleanup()

end
@@ -166,11 +172,9 @@ def exit_cleanup()
pid = spawn("ip netns list | grep occp_ | xargs -L 1 ip netns delete")
Process.wait pid

@scoreKeeper.cleanup

$log.debug 'Team thread cleanup complete'
$log.debug 'Team threads cleanup complete'

Thread.exit
#Thread.exit
end

# Entry point for the post-setup code
@@ -190,7 +194,7 @@ def run ()
@STATE = READY

#Poll the @INBOX waiting for tasks
while message = @INBOX.pop do
while @STATE != QUIT and message = @INBOX.pop do

case message.signal

@@ -252,9 +256,12 @@ def run ()

end #@INBOX Poll

$log.debug "Waiting for Team join"
#wait for all the teams to finish
@localteams.each { |team| team[:thr].join }

$log.debug "Team join complete"

end #def run

end #Class

0 comments on commit 0d9944e

Please sign in to comment.
You can’t perform that action at this time.