fix deadlock problem

This commit is contained in:
zoujia 2023-05-19 17:23:49 +08:00
parent 369dcb62f5
commit edc7caaef8

View File

@ -300,17 +300,9 @@ SetupSecondBufferInTable(const SdPageKey *pk)
SdPageValue *pv;
bool found;
for(;;)
{
pv = (SdPageValue *)
hash_search(SecondBufferHash, pk, HASH_ENTER_NULL, &found);
if (pv)
{
break;
}
pg_usleep(100000L);
}
pv = (SdPageValue *)
hash_search(SecondBufferHash, pk, HASH_ENTER_NULL, &found);
return pv;
}
@ -367,10 +359,19 @@ ReceivePageFromDataBuffer(PageKey *pk, uint8_t *buffer)
uint32 newHash;
newHash = SecondBufferHashCode(sk);
partitionLock = SecondBufferMappingPartitionLock(newHash);
LWLockAcquire(partitionLock, LW_EXCLUSIVE);
SdPageValue *sdPageValue = SetupSecondBufferInTable(sk);
memcpy(sdPageValue->pagecontent, buffer,8192);
LWLockRelease(partitionLock);
SdPageValue *sdPageValue = NULL;
while (sdPageValue == NULL)
{
LWLockAcquire(partitionLock, LW_EXCLUSIVE);
sdPageValue = SetupSecondBufferInTable(sk);
if (sdPageValue == NULL)
{
LWLockRelease(partitionLock);
continue;
}
memcpy(sdPageValue->pagecontent, buffer,8192);
LWLockRelease(partitionLock);
}
srand((int)clock());
int index = rand()%SDNUM;