From Beige Giraffe, 4 Years ago, written in Plain Text.
- view diff
Embed
  1. diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c
  2. index 3752a06b23..c41ce0e65e 100644
  3. --- a/src/switch_core_sqldb.c
  4. +++ b/src/switch_core_sqldb.c
  5. @@ -180,9 +180,10 @@ static switch_cache_db_handle_t *get_handle(const char *db_str, const char *user
  6.         switch_mutex_lock(sql_manager.dbh_mutex);
  7.  
  8.         for (dbh_ptr = sql_manager.handle_pool; dbh_ptr; dbh_ptr = dbh_ptr->next) {
  9. -               if (dbh_ptr->thread_hash == thread_hash && dbh_ptr->hash == hash && !dbh_ptr->use_count &&
  10. +               if (dbh_ptr->hash == hash && (dbh_ptr->thread_hash == thread_hash || !dbh_ptr->use_count) &&
  11.                         !switch_test_flag(dbh_ptr, CDF_PRUNE) && switch_mutex_trylock(dbh_ptr->mutex) == SWITCH_STATUS_SUCCESS) {
  12.                         r = dbh_ptr;
  13. +                       break;
  14.                 }
  15.         }
  16.  
  17. @@ -197,11 +198,13 @@ static switch_cache_db_handle_t *get_handle(const char *db_str, const char *user
  18.         }
  19.  
  20.         if (r) {
  21. +               if (!r->use_count) {
  22. +                       r->thread_hash = thread_hash;
  23. +               }
  24. +
  25.                 r->use_count++;
  26.                 r->total_used_count++;
  27.                 sql_manager.total_used_handles++;
  28. -               r->hash = switch_ci_hashfunc_default(db_str, &hlen);
  29. -               r->thread_hash = thread_hash;
  30.                 switch_set_string(r->last_user, user_str);
  31.         }
  32.  
  33. @@ -350,7 +353,7 @@ SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t
  34.  
  35.                 if ((*dbh)->use_count) {
  36.                         if (--(*dbh)->use_count == 0) {
  37. -                               (*dbh)->thread_hash = 1;
  38. +                               (*dbh)->thread_hash = 0;
  39.                         }
  40.                 }
  41.                 switch_mutex_unlock((*dbh)->mutex);