From 201f1e72325a0513c7f56d20b7d5163164d5c2cd Mon Sep 17 00:00:00 2001 From: luislavena Date: Thu, 17 Apr 2008 18:59:55 +0000 Subject: mongrel_service: updated ServiceFB library (pistoned). git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/branches/stable_1-2@1006 19e92222-5c0b-0410-8929-a290d50e31e9 --- .../mongrel_service/lib/ServiceFB/ServiceFB_Utils.bas | 17 +++++++++++++++-- .../mongrel_service/lib/ServiceFB/_utils_internals.bi | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/projects/mongrel_service/lib/ServiceFB/ServiceFB_Utils.bas b/projects/mongrel_service/lib/ServiceFB/ServiceFB_Utils.bas index c5150ea..c8a77a3 100644 --- a/projects/mongrel_service/lib/ServiceFB/ServiceFB_Utils.bas +++ b/projects/mongrel_service/lib/ServiceFB/ServiceFB_Utils.bas @@ -15,6 +15,8 @@ namespace svc namespace utils '# fb.svc.utils '# private (internals) for ServiceProcess.Console() dim shared _svc_stop_signal as any ptr + dim shared _svc_stop_mutex as any ptr + dim shared _svc_stopped as BOOL dim shared _svc_in_console as ServiceProcess ptr dim shared _svc_in_console_stop_flag as BOOL @@ -168,6 +170,7 @@ namespace utils '# fb.svc.utils '# create the signal used to stop the service thread. _svc_stop_signal = condcreate() + _svc_stop_mutex = mutexcreate() '# register the Console Handler SetConsoleCtrlHandler(@_console_handler, TRUE) @@ -189,6 +192,9 @@ namespace utils '# fb.svc.utils if not (service->onStart = 0) then '# create the thread working_thread = threadcreate(@ServiceProcess.call_onStart, service) + if (working_thread = 0) then + print "Failed to create working thread." + end if end if print "Service is in running state." @@ -197,7 +203,11 @@ namespace utils '# fb.svc.utils '# now that onStart is running, must monitor the stop_signal '# in case it arrives, the service state must change to exit the '# working thread. - condwait(_svc_stop_signal) + mutexlock(_svc_stop_mutex) + do while (_svc_stopped = FALSE) + condwait(_svc_stop_signal, _svc_stop_mutex) + loop + mutexunlock(_svc_stop_mutex) print "Stop signal received, stopping..." @@ -222,7 +232,7 @@ namespace utils '# fb.svc.utils '# now that service was stopped, destroy the references. conddestroy(_svc_stop_signal) - + mutexdestroy(_svc_stop_mutex) print "Done." end if else @@ -287,9 +297,12 @@ namespace utils '# fb.svc.utils '# now fire the signal _dprint("fire stop signal") + mutexlock(_svc_stop_mutex) condsignal(_svc_stop_signal) result = TRUE _svc_in_console_stop_flag = FALSE + _svc_stopped = TRUE + mutexunlock(_svc_stop_mutex) case else: _dprint("unsupported CTRL EVENT") diff --git a/projects/mongrel_service/lib/ServiceFB/_utils_internals.bi b/projects/mongrel_service/lib/ServiceFB/_utils_internals.bi index 67acc87..fab00f0 100644 --- a/projects/mongrel_service/lib/ServiceFB/_utils_internals.bi +++ b/projects/mongrel_service/lib/ServiceFB/_utils_internals.bi @@ -42,6 +42,8 @@ namespace utils '# fb.svc.utils '# will raise in case Ctrl+C / Ctrl+Break or other events are '# received. extern _svc_stop_signal as any ptr + extern _svc_stop_mutex as any ptr + extern _svc_stopped as BOOL extern _svc_in_console as ServiceProcess ptr extern _svc_in_console_stop_flag as BOOL end namespace '# fb.svc.utils -- cgit v1.2.3-24-ge0c7