MCPcopy Create free account
hub / github.com/MariaDB/server / get_lock_data

Function get_lock_data

sql/lock.cc:818–912  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

816*/
817
818MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags)
819{
820 uint i,lock_count,table_count;
821 MYSQL_LOCK *sql_lock;
822 THR_LOCK_DATA **locks, **locks_buf;
823 TABLE **to, **table_buf;
824 DBUG_ENTER("get_lock_data");
825
826 DBUG_PRINT("info", ("count %d", count));
827
828 for (i=lock_count=table_count=0 ; i < count ; i++)
829 {
830 TABLE *t= table_ptr[i];
831
832 if ((likely(!t->s->tmp_table) ||
833 (t->s->tmp_table == TRANSACTIONAL_TMP_TABLE)) &&
834 (!(flags & GET_LOCK_SKIP_SEQUENCES) || t->s->sequence == 0))
835 {
836 lock_count+= t->file->lock_count();
837 table_count++;
838 }
839 }
840
841 /*
842 Allocating twice the number of pointers for lock data for use in
843 thr_multi_lock(). This function reorders the lock data, but cannot
844 update the table values. So the second part of the array is copied
845 from the first part immediately before calling thr_multi_lock().
846 */
847 size_t amount= sizeof(*sql_lock) +
848 sizeof(THR_LOCK_DATA*) * lock_count * 2 +
849 sizeof(table_ptr) * table_count;
850 if (!(sql_lock= (MYSQL_LOCK*) (flags & GET_LOCK_ON_THD ?
851 thd->alloc(amount) :
852 my_malloc(key_memory_MYSQL_LOCK, amount,
853 MYF(0)))))
854 DBUG_RETURN(0);
855 locks= locks_buf= sql_lock->locks= (THR_LOCK_DATA**) (sql_lock + 1);
856 to= table_buf= sql_lock->table= (TABLE**) (locks + lock_count * 2);
857 sql_lock->table_count= table_count;
858 sql_lock->flags= flags;
859
860 for (i=0 ; i < count ; i++)
861 {
862 TABLE *table= table_ptr[i];
863 enum thr_lock_type lock_type;
864 THR_LOCK_DATA **locks_start;
865
866 if ((table->s->tmp_table && table->s->tmp_table != TRANSACTIONAL_TMP_TABLE)
867 || (flags & GET_LOCK_SKIP_SEQUENCES && table->s->sequence != NULL))
868 continue;
869 lock_type= table->reginfo.lock_type;
870 DBUG_ASSERT(lock_type != TL_WRITE_DEFAULT && lock_type != TL_READ_DEFAULT);
871 locks_start= locks;
872 locks= table->file->store_lock(thd, locks,
873 (flags & GET_LOCK_ACTION_MASK) == GET_LOCK_UNLOCK ? TL_IGNORE :
874 lock_type);
875 if ((flags & GET_LOCK_ACTION_MASK) == GET_LOCK_STORE_LOCKS)

Callers 4

mysql_lock_tablesFunction · 0.85
mysql_unlock_some_tablesFunction · 0.85
mysql_ha_openFunction · 0.85

Calls 5

my_mallocFunction · 0.85
lock_countMethod · 0.45
allocMethod · 0.45
store_lockMethod · 0.45
c_ptrMethod · 0.45

Tested by

no test coverage detected