~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/locking/global.cc

  • Committer: Lee Bieber
  • Date: 2011-04-14 02:59:01 UTC
  • mfrom: (2275.3.4 cache)
  • mto: This revision was merged to the branch mainline in revision 2278.
  • Revision ID: kalebral@gmail.com-20110414025901-o0oici0e4ngtqz91
Merge Olaf - Refactor Thread

Show diffs side-by-side

added added

removed removed

Lines of Context:
600
600
  @param check_in_use           Do we need to check if table already in use by us
601
601
 
602
602
  @note
603
 
    One must have a lock on table::Cache::singleton().mutex()!
 
603
    One must have a lock on table::Cache::mutex()!
604
604
 
605
605
  @warning
606
606
    If you are going to update the table, you should use
657
657
  table_list->table= reinterpret_cast<Table *>(table);
658
658
 
659
659
  /* Return 1 if table is in use */
660
 
  return(test(table::Cache::singleton().removeTable(*this, identifier, RTFC_NO_FLAG)));
 
660
  return(test(table::Cache::removeTable(*this, identifier, RTFC_NO_FLAG)));
661
661
}
662
662
 
663
663
 
681
681
      Table *save_next= table->getNext();
682
682
      bool result;
683
683
      table->setNext(NULL);
684
 
      result= table::Cache::singleton().areTablesUsed(table_list->table, 0);
 
684
      result= table::Cache::areTablesUsed(table_list->table, 0);
685
685
      table->setNext(save_next);
686
686
      if (result)
687
687
        return 1;
696
696
  bool result= false;
697
697
 
698
698
#if 0
699
 
  assert(ownership of table::Cache::singleton().mutex());
 
699
  assert(ownership of table::Cache::mutex());
700
700
#endif
701
701
 
702
702
  while (locked_named_table(table_list))
706
706
      result=1;
707
707
      break;
708
708
    }
709
 
    wait_for_condition(table::Cache::singleton().mutex(), COND_refresh);
710
 
    table::Cache::singleton().mutex().lock(); /* Wait for a table to unlock and then lock it */
 
709
    wait_for_condition(table::Cache::mutex(), COND_refresh);
 
710
    table::Cache::mutex().lock(); /* Wait for a table to unlock and then lock it */
711
711
  }
712
712
  return result;
713
713
}
717
717
  Lock all tables in list with a name lock.
718
718
 
719
719
  REQUIREMENTS
720
 
  - One must have a lock on table::Cache::singleton().mutex() when calling this
 
720
  - One must have a lock on table::Cache::mutex() when calling this
721
721
 
722
722
  @param table_list             Names of tables to lock
723
723
 
763
763
  @param table_list Names of tables to lock.
764
764
 
765
765
  @note
766
 
    This function needs to be protected by table::Cache::singleton().mutex(). If we're
 
766
    This function needs to be protected by table::Cache::mutex(). If we're
767
767
    under LOCK TABLES, this function does not work as advertised. Namely,
768
768
    it does not exclude other threads from using this table and does not
769
769
    put an exclusive name lock on this table into the table cache.
802
802
                                (default 0, which will unlock all tables)
803
803
 
804
804
  @note
805
 
    One must have a lock on table::Cache::singleton().mutex() when calling this.
 
805
    One must have a lock on table::Cache::mutex() when calling this.
806
806
 
807
807
  @note
808
808
    This function will broadcast refresh signals to inform other threads
877
877
 
878
878
  access to them is protected with a mutex LOCK_global_read_lock
879
879
 
880
 
  (XXX: one should never take table::Cache::singleton().mutex() if LOCK_global_read_lock is
 
880
  (XXX: one should never take table::Cache::mutex() if LOCK_global_read_lock is
881
881
  taken, otherwise a deadlock may occur. Other mutexes could be a
882
882
  problem too - grep the code for global_read_lock if you want to use
883
 
  any other mutex here) Also one must not hold table::Cache::singleton().mutex() when calling
 
883
  any other mutex here) Also one must not hold table::Cache::mutex() when calling
884
884
  wait_if_global_read_lock(). When the thread with the global read lock
885
 
  tries to close its tables, it needs to take table::Cache::singleton().mutex() in
 
885
  tries to close its tables, it needs to take table::Cache::mutex() in
886
886
  close_thread_table().
887
887
 
888
888
  How blocking of threads by global read lock is achieved: that's
946
946
                            "Waiting to get readlock");
947
947
 
948
948
    waiting_for_read_lock++;
949
 
    boost_unique_lock_t scopedLock(LOCK_global_read_lock, boost::adopt_lock_t());
 
949
    boost::mutex::scoped_lock scopedLock(LOCK_global_read_lock, boost::adopt_lock_t());
950
950
    while (protect_against_global_read_lock && not getKilled())
951
951
      COND_global_read_lock.wait(scopedLock);
952
952
    waiting_for_read_lock--;
981
981
    return;
982
982
 
983
983
  {
984
 
    boost_unique_lock_t scopedLock(LOCK_global_read_lock);
 
984
    boost::mutex::scoped_lock scopedLock(LOCK_global_read_lock);
985
985
    tmp= --global_read_lock;
986
986
    if (isGlobalReadLock() == Session::MADE_GLOBAL_READ_LOCK_BLOCK_COMMIT)
987
987
      --global_read_lock_blocks_commit;
1007
1007
  bool result= 0, need_exit_cond;
1008
1008
 
1009
1009
  /*
1010
 
    Assert that we do not own table::Cache::singleton().mutex(). If we would own it, other
 
1010
    Assert that we do not own table::Cache::mutex(). If we would own it, other
1011
1011
    threads could not close their tables. This would make a pretty
1012
1012
    deadlock.
1013
1013
  */
1014
 
  safe_mutex_assert_not_owner(table::Cache::singleton().mutex().native_handle());
 
1014
  safe_mutex_assert_not_owner(table::Cache::mutex().native_handle());
1015
1015
 
1016
1016
  LOCK_global_read_lock.lock();
1017
1017
  if ((need_exit_cond= must_wait(is_not_commit)))
1035
1035
    while (must_wait(is_not_commit) && not getKilled() &&
1036
1036
           (!abort_on_refresh || open_tables.version == g_refresh_version))
1037
1037
    {
1038
 
      boost_unique_lock_t scoped(LOCK_global_read_lock, boost::adopt_lock_t());
 
1038
      boost::mutex::scoped_lock scoped(LOCK_global_read_lock, boost::adopt_lock_t());
1039
1039
      COND_global_read_lock.wait(scoped);
1040
1040
      scoped.release();
1041
1041
    }
1096
1096
                          "Waiting for all running commits to finish");
1097
1097
  while (protect_against_global_read_lock && not getKilled())
1098
1098
  {
1099
 
    boost_unique_lock_t scopedLock(LOCK_global_read_lock, boost::adopt_lock_t());
 
1099
    boost::mutex::scoped_lock scopedLock(LOCK_global_read_lock, boost::adopt_lock_t());
1100
1100
    COND_global_read_lock.wait(scopedLock);
1101
1101
    scopedLock.release();
1102
1102
  }
1121
1121
    Due to a bug in a threading library it could happen that a signal
1122
1122
    did not reach its target. A condition for this was that the same
1123
1123
    condition variable was used with different mutexes in
1124
 
    pthread_cond_wait(). Some time ago we changed table::Cache::singleton().mutex() to
 
1124
    pthread_cond_wait(). Some time ago we changed table::Cache::mutex() to
1125
1125
    LOCK_global_read_lock in global read lock handling. So COND_refresh
1126
 
    was used with table::Cache::singleton().mutex() and LOCK_global_read_lock.
 
1126
    was used with table::Cache::mutex() and LOCK_global_read_lock.
1127
1127
 
1128
1128
    We did now also change from COND_refresh to COND_global_read_lock
1129
1129
    in global read lock handling. But now it is necessary to signal