~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/locking/global.cc

  • Committer: Brian Aker
  • Date: 2010-11-23 07:02:38 UTC
  • mfrom: (1945.2.1 quick)
  • Revision ID: brian@tangent.org-20101123070238-1f31pgg7gvmytpr3
Refactor basic lock bits (ie, encapsulate!)

Show diffs side-by-side

added added

removed removed

Lines of Context:
654
654
  @param check_in_use           Do we need to check if table already in use by us
655
655
 
656
656
  @note
657
 
    One must have a lock on LOCK_open!
 
657
    One must have a lock on table::Cache::singleton().mutex()!
658
658
 
659
659
  @warning
660
660
    If you are going to update the table, you should use
750
750
  bool result= false;
751
751
 
752
752
#if 0
753
 
  assert(ownership of LOCK_open);
 
753
  assert(ownership of table::Cache::singleton().mutex());
754
754
#endif
755
755
 
756
756
  while (locked_named_table(table_list))
760
760
      result=1;
761
761
      break;
762
762
    }
763
 
    wait_for_condition(LOCK_open, COND_refresh);
764
 
    LOCK_open.lock(); /* Wait for a table to unlock and then lock it */
 
763
    wait_for_condition(table::Cache::singleton().mutex(), COND_refresh);
 
764
    table::Cache::singleton().mutex().lock(); /* Wait for a table to unlock and then lock it */
765
765
  }
766
766
  return result;
767
767
}
771
771
  Lock all tables in list with a name lock.
772
772
 
773
773
  REQUIREMENTS
774
 
  - One must have a lock on LOCK_open when calling this
 
774
  - One must have a lock on table::Cache::singleton().mutex() when calling this
775
775
 
776
776
  @param table_list             Names of tables to lock
777
777
 
817
817
  @param table_list Names of tables to lock.
818
818
 
819
819
  @note
820
 
    This function needs to be protected by LOCK_open. If we're
 
820
    This function needs to be protected by table::Cache::singleton().mutex(). If we're
821
821
    under LOCK TABLES, this function does not work as advertised. Namely,
822
822
    it does not exclude other threads from using this table and does not
823
823
    put an exclusive name lock on this table into the table cache.
856
856
                                (default 0, which will unlock all tables)
857
857
 
858
858
  @note
859
 
    One must have a lock on LOCK_open when calling this.
 
859
    One must have a lock on table::Cache::singleton().mutex() when calling this.
860
860
 
861
861
  @note
862
862
    This function will broadcast refresh signals to inform other threads
931
931
 
932
932
  access to them is protected with a mutex LOCK_global_read_lock
933
933
 
934
 
  (XXX: one should never take LOCK_open if LOCK_global_read_lock is
 
934
  (XXX: one should never take table::Cache::singleton().mutex() if LOCK_global_read_lock is
935
935
  taken, otherwise a deadlock may occur. Other mutexes could be a
936
936
  problem too - grep the code for global_read_lock if you want to use
937
 
  any other mutex here) Also one must not hold LOCK_open when calling
 
937
  any other mutex here) Also one must not hold table::Cache::singleton().mutex() when calling
938
938
  wait_if_global_read_lock(). When the thread with the global read lock
939
 
  tries to close its tables, it needs to take LOCK_open in
 
939
  tries to close its tables, it needs to take table::Cache::singleton().mutex() in
940
940
  close_thread_table().
941
941
 
942
942
  How blocking of threads by global read lock is achieved: that's
1058
1058
  bool result= 0, need_exit_cond;
1059
1059
 
1060
1060
  /*
1061
 
    Assert that we do not own LOCK_open. If we would own it, other
 
1061
    Assert that we do not own table::Cache::singleton().mutex(). If we would own it, other
1062
1062
    threads could not close their tables. This would make a pretty
1063
1063
    deadlock.
1064
1064
  */
1065
 
  safe_mutex_assert_not_owner(LOCK_open.native_handle());
 
1065
  safe_mutex_assert_not_owner(table::Cache::singleton().mutex().native_handle());
1066
1066
 
1067
1067
  LOCK_global_read_lock.lock();
1068
1068
  if ((need_exit_cond= must_wait(is_not_commit)))
1171
1171
    Due to a bug in a threading library it could happen that a signal
1172
1172
    did not reach its target. A condition for this was that the same
1173
1173
    condition variable was used with different mutexes in
1174
 
    pthread_cond_wait(). Some time ago we changed LOCK_open to
 
1174
    pthread_cond_wait(). Some time ago we changed table::Cache::singleton().mutex() to
1175
1175
    LOCK_global_read_lock in global read lock handling. So COND_refresh
1176
 
    was used with LOCK_open and LOCK_global_read_lock.
 
1176
    was used with table::Cache::singleton().mutex() and LOCK_global_read_lock.
1177
1177
 
1178
1178
    We did now also change from COND_refresh to COND_global_read_lock
1179
1179
    in global read lock handling. But now it is necessary to signal