~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/lock.cc

  • Committer: Brian Aker
  • Date: 2010-11-08 17:40:41 UTC
  • mto: (1921.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 1916.
  • Revision ID: brian@tangent.org-20101108174041-owap774v8l5vvnl4
Push some functions behind classes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
  @{
106
106
*/
107
107
 
108
 
static DrizzleLock *get_lock_data(Session *session, Table **table,
109
 
                                  uint32_t count,
110
 
                                  bool should_lock, Table **write_locked);
111
108
static void print_lock_error(int error, const char *);
112
109
 
113
110
/*
186
183
 
187
184
  for (;;)
188
185
  {
189
 
    if (! (sql_lock= get_lock_data(this, tables, count, true,
 
186
    if (! (sql_lock= get_lock_data(tables, count, true,
190
187
                                   &write_lock_used)))
191
188
      break;
192
189
 
385
382
{
386
383
  DrizzleLock *sql_lock;
387
384
  Table *write_lock_used;
388
 
  if ((sql_lock= get_lock_data(this, table, count, false,
 
385
  if ((sql_lock= get_lock_data(table, count, false,
389
386
                               &write_lock_used)))
390
387
    mysql_unlock_tables(sql_lock);
391
388
}
483
480
  DrizzleLock *locked;
484
481
  Table *write_lock_used;
485
482
 
486
 
  if ((locked= get_lock_data(this, &table, 1, false,
 
483
  if ((locked= get_lock_data(&table, 1, false,
487
484
                             &write_lock_used)))
488
485
  {
489
486
    for (uint32_t x= 0; x < locked->lock_count; x++)
511
508
  Table *write_lock_used;
512
509
  bool result= false;
513
510
 
514
 
  if ((locked= get_lock_data(this, &table, 1, false,
 
511
  if ((locked= get_lock_data(&table, 1, false,
515
512
                             &write_lock_used)))
516
513
  {
517
514
    for (uint32_t i= 0; i < locked->lock_count; i++)
559
556
  @param write_lock_used   Store pointer to last table with WRITE_ALLOW_WRITE
560
557
*/
561
558
 
562
 
static DrizzleLock *get_lock_data(Session *session, Table **table_ptr, uint32_t count,
563
 
                                 bool should_lock, Table **write_lock_used)
 
559
DrizzleLock *Session::get_lock_data(Table **table_ptr, uint32_t count,
 
560
                                    bool should_lock, Table **write_lock_used)
564
561
{
565
562
  uint32_t lock_count;
566
563
  DrizzleLock *sql_lock;
616
613
      }
617
614
    }
618
615
    locks_start= locks;
619
 
    locks= table->cursor->store_lock(session, locks,
620
 
                                     should_lock == false ? TL_IGNORE : lock_type);
 
616
    locks= table->cursor->store_lock(this, locks, should_lock == false ? TL_IGNORE : lock_type);
621
617
    if (should_lock)
622
618
    {
623
619
      table->lock_position=   (uint32_t) (to - table_buf);
650
646
/**
651
647
  Put a not open table with an old refresh version in the table cache.
652
648
 
653
 
  @param session                        Thread handler
654
649
  @param table_list             Lock first table in this list
655
650
  @param check_in_use           Do we need to check if table already in use by us
656
651
 
674
669
    > 0  table locked, but someone is using it
675
670
*/
676
671
 
677
 
static int lock_table_name(Session *session, TableList *table_list)
 
672
int Session::lock_table_name(TableList *table_list)
678
673
{
679
674
  TableIdentifier identifier(table_list->getSchemaName(), table_list->getTableName());
680
675
  const TableIdentifier::Key &key(identifier.getKey());
694
689
        continue;
695
690
      }
696
691
 
697
 
      if (table->in_use == session)
 
692
      if (table->in_use == this)
698
693
      {
699
694
        table->getMutableShare()->resetVersion();                  // Ensure no one can use this
700
695
        table->locked_by_name= true;
704
699
  }
705
700
 
706
701
  table::Placeholder *table= NULL;
707
 
  if (!(table= session->table_cache_insert_placeholder(identifier)))
 
702
  if (!(table= table_cache_insert_placeholder(identifier)))
708
703
  {
709
704
    return -1;
710
705
  }
712
707
  table_list->table= reinterpret_cast<Table *>(table);
713
708
 
714
709
  /* Return 1 if table is in use */
715
 
  return(test(table::Cache::singleton().removeTable(session, identifier, RTFC_NO_FLAG)));
 
710
  return(test(table::Cache::singleton().removeTable(this, identifier, RTFC_NO_FLAG)));
716
711
}
717
712
 
718
713
 
719
 
void unlock_table_name(TableList *table_list)
 
714
void TableList::unlock_table_name()
720
715
{
721
 
  if (table_list->table)
 
716
  if (table)
722
717
  {
723
 
    table::remove_table(static_cast<table::Concurrent *>(table_list->table));
 
718
    table::remove_table(static_cast<table::Concurrent *>(table));
724
719
    broadcast_refresh();
725
720
  }
726
721
}
746
741
}
747
742
 
748
743
 
749
 
static bool wait_for_locked_table_names(Session *session, TableList *table_list)
 
744
bool Session::wait_for_locked_table_names(TableList *table_list)
750
745
{
751
746
  bool result= false;
752
747
 
756
751
 
757
752
  while (locked_named_table(table_list))
758
753
  {
759
 
    if (session->killed)
 
754
    if (killed)
760
755
    {
761
756
      result=1;
762
757
      break;
763
758
    }
764
 
    session->wait_for_condition(LOCK_open, COND_refresh);
 
759
    wait_for_condition(LOCK_open, COND_refresh);
765
760
    LOCK_open.lock(); /* Wait for a table to unlock and then lock it */
766
761
  }
767
762
  return result;
790
785
  for (lock_table= table_list; lock_table; lock_table= lock_table->next_local)
791
786
  {
792
787
    int got_lock;
793
 
    if ((got_lock= lock_table_name(this, lock_table)) < 0)
 
788
    if ((got_lock= lock_table_name(lock_table)) < 0)
794
789
      goto end;                                 // Fatal error
795
790
    if (got_lock)
796
791
      got_all_locks=0;                          // Someone is using table
797
792
  }
798
793
 
799
794
  /* If some table was in use, wait until we got the lock */
800
 
  if (!got_all_locks && wait_for_locked_table_names(this, table_list))
 
795
  if (!got_all_locks && wait_for_locked_table_names(table_list))
801
796
    goto end;
802
797
  return false;
803
798
 
804
799
end:
805
 
  unlock_table_names(table_list, lock_table);
 
800
  table_list->unlock_table_names(table_list);
806
801
 
807
802
  return true;
808
803
}
811
806
/**
812
807
  Unlock all tables in list with a name lock.
813
808
 
814
 
  @param session        Thread handle.
815
809
  @param table_list Names of tables to lock.
816
810
 
817
811
  @note
866
860
    1   Fatal error (end of memory ?)
867
861
*/
868
862
 
869
 
void unlock_table_names(TableList *table_list, TableList *last_table)
 
863
void TableList::unlock_table_names(TableList *last_table)
870
864
{
871
 
  for (TableList *table= table_list;
872
 
       table != last_table;
873
 
       table= table->next_local)
874
 
    unlock_table_name(table);
 
865
  for (TableList *table_iter= this;
 
866
       table_iter != last_table;
 
867
       table_iter= table_iter->next_local)
 
868
  {
 
869
    table_iter->unlock_table_name();
 
870
  }
 
871
 
875
872
  broadcast_refresh();
876
873
}
877
874