From 2ff2a18b61f5194b9a1d97a0ee6d0710a536a0e3 Mon Sep 17 00:00:00 2001 From: Darren Schreiber Date: Thu, 11 Jun 2009 03:42:01 +0000 Subject: [PATCH] Fix a deadlock in last commit git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13754 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_nibblebill/mod_nibblebill.c | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/mod/applications/mod_nibblebill/mod_nibblebill.c b/src/mod/applications/mod_nibblebill/mod_nibblebill.c index 9946bc203f..6bb296eebf 100644 --- a/src/mod/applications/mod_nibblebill/mod_nibblebill.c +++ b/src/mod/applications/mod_nibblebill/mod_nibblebill.c @@ -430,10 +430,6 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Comparing %f to hangup /* Not enough money - reroute call to nobal location */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Balance of %f fell below allowed amount of %f! (Account %s)\n", balance, globals.nobal_amt, billaccount); - /* IMPORTANT: Billing must be paused before the transfer occurs! This prevents infinite loops, since the transfer will result */ - /* in nibblebill checking the call again in the routing process for an allowed balance! */ - /* If you intend to give the user the option to re-up their balance, you must clear & resume billing once the balance is updated! */ - nibblebill_pause(session); transfer_call(session, globals.nobal_action); } @@ -503,22 +499,23 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Comparing %f to hangup /* Save this location, but only if the channel/session are not hungup (otherwise, we're done) */ if (channel && switch_channel_get_state(channel) != CS_HANGUP) { switch_channel_set_private(channel, "_nibble_data_", nibble_data); + + float balance; + + /* See if this person has enough money left to continue the call */ + balance = get_balance(billaccount); + if (balance <= globals.nobal_amt) { + /* Not enough money - reroute call to nobal location */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Balance of %f fell below allowed amount of %f! (Account %s)\n", balance, globals.nobal_amt, billaccount); + + /* IMPORTANT: Billing must be paused before the transfer occurs! This prevents infinite loops, since the transfer will result */ + /* in nibblebill checking the call again in the routing process for an allowed balance! */ + /* If you intend to give the user the option to re-up their balance, you must clear & resume billing once the balance is updated! */ + nibblebill_pause(session); + transfer_call(session, globals.nobal_action); + } } - float balance; - - /* See if this person has enough money left to continue the call */ - balance = get_balance(billaccount); - if (balance <= globals.nobal_amt) { - /* Not enough money - reroute call to nobal location */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Balance of %f fell below allowed amount of %f! (Account %s)\n", balance, globals.nobal_amt, billaccount); - - /* IMPORTANT: Billing must be paused before the transfer occurs! This prevents infinite loops, since the transfer will result */ - /* in nibblebill checking the call again in the routing process for an allowed balance! */ - /* If you intend to give the user the option to re-up their balance, you must clear & resume billing once the balance is updated! */ - nibblebill_pause(session); - transfer_call(session, globals.nobal_action); - } /* Done changing - release lock */ if (globals.mutex) { @@ -840,7 +837,7 @@ switch_state_handler_table_t nibble_state_handler = /* on_routing */ process_hangup, /* Need to add a check here for anything in their account before routing */ /* on_execute */ sched_billing, /* Turn on heartbeat for this session and do an initial account check */ /* on_hangup */ process_hangup, /* On hangup - most important place to go bill */ - /* on_exch_media */ NULL, + /* on_exch_media */ sched_billing, /* on_soft_exec */ NULL, /* on_consume_med */ NULL, /* on_hibernate */ NULL,