| 1018 | |
| 1019 | |
| 1020 | static Lock* hash_get_lock(Lock* lock, USHORT* hash_slot, Lock*** prior) |
| 1021 | { |
| 1022 | /************************************** |
| 1023 | * |
| 1024 | * h a s h _ g e t _ l o c k |
| 1025 | * |
| 1026 | ************************************** |
| 1027 | * |
| 1028 | * Functional description |
| 1029 | * Return the first matching identical |
| 1030 | * lock to the passed lock. To minimize |
| 1031 | * code for searching through the hash |
| 1032 | * table, return hash_slot or prior lock |
| 1033 | * if requested. |
| 1034 | * |
| 1035 | **************************************/ |
| 1036 | fb_assert(LCK_CHECK_LOCK(lock)); |
| 1037 | |
| 1038 | Jrd::Attachment* const att = lock->getLockAttachment(); |
| 1039 | if (!att) |
| 1040 | return NULL; |
| 1041 | |
| 1042 | if (!att->att_compatibility_table) |
| 1043 | hash_allocate(lock); |
| 1044 | |
| 1045 | const USHORT hash_value = |
| 1046 | (USHORT) InternalHash::hash(lock->lck_length, lock->getKeyPtr(), LOCK_HASH_SIZE); |
| 1047 | |
| 1048 | if (hash_slot) |
| 1049 | *hash_slot = hash_value; |
| 1050 | |
| 1051 | // if no collisions found, we're done |
| 1052 | |
| 1053 | Lock* match = (*att->att_compatibility_table)[hash_value]; |
| 1054 | if (!match) |
| 1055 | return NULL; |
| 1056 | |
| 1057 | if (prior) |
| 1058 | *prior = & (*att->att_compatibility_table)[hash_value]; |
| 1059 | |
| 1060 | // look for an identical lock |
| 1061 | |
| 1062 | fb_assert(LCK_CHECK_LOCK(match)); |
| 1063 | for (Lock* collision = match; collision; collision = collision->lck_collision) |
| 1064 | { |
| 1065 | fb_assert(LCK_CHECK_LOCK(collision)); |
| 1066 | if (collision->lck_type == lock->lck_type && |
| 1067 | collision->lck_length == lock->lck_length) |
| 1068 | { |
| 1069 | // check that the keys are the same |
| 1070 | |
| 1071 | if (!memcmp(lock->getKeyPtr(), collision->getKeyPtr(), lock->lck_length)) |
| 1072 | return collision; |
| 1073 | } |
| 1074 | |
| 1075 | if (prior) |
| 1076 | *prior = &collision->lck_collision; |
| 1077 | } |
no test coverage detected