Browse Source

Make pyVault::AddChronicleEntry a blocking operation to avoid a race

condition
Adam Johnson 12 years ago
parent
commit
f45679a54f
  1. 5
      Sources/Plasma/FeatureLib/pfPython/pyVault.cpp
  2. 32
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp
  3. 2
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h

5
Sources/Plasma/FeatureLib/pfPython/pyVault.cpp

@ -364,7 +364,10 @@ void pyVault::AddChronicleEntry( const char * name, UInt32 type, const char * va
wchar * wEntryName = StrDupToUnicode(name);
wchar * wEntryValue = StrDupToUnicode(value);
VaultAddChronicleEntry(wEntryName, type, wEntryValue);
// FIXME: We should ideally not block, but for now, the Python assumes that when
// we return, the chronicle exists and can be found with findChronicleEntry.
// Maybe we should insert a dummy into the tree? (currently hard)
VaultAddChronicleEntryAndWait(wEntryName, type, wEntryValue);
FREE(wEntryName);
FREE(wEntryValue);

32
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp

@ -3438,38 +3438,6 @@ bool VaultHasChronicleEntry (const wchar entryName[], int entryType) {
return false;
}
//============================================================================
void VaultAddChronicleEntry (const wchar entryName[], int entryType, const wchar entryValue[]) {
// Sometimes we try to create chrons in StartUp.
// This is bad...
if (GetPlayerNode() == nil)
return;
if (RelVaultNode* rvnChrn = VaultFindChronicleEntryIncRef(entryName, entryType)) {
VaultChronicleNode chrnNode(rvnChrn);
chrnNode.SetEntryValue(entryValue);
rvnChrn->DecRef();
} else {
NetVaultNode* templateNode = NEWZERO(NetVaultNode);
templateNode->IncRef();
templateNode->SetNodeType(plVault::kNodeType_Chronicle);
VaultChronicleNode chrnNode(templateNode);
chrnNode.SetEntryName(entryName);
chrnNode.SetEntryType(entryType);
chrnNode.SetEntryValue(entryValue);
VaultCreateNode(templateNode, (FVaultCreateNodeCallback)(_VaultAddChronicleEntryCB), nil, nil);
templateNode->DecRef();
}
}
void _VaultAddChronicleEntryCB(ENetError result, void* state, void * param, RelVaultNode* node) {
if (result == kNetSuccess) {
RelVaultNode* rvnFldr = GetChildFolderNode(GetPlayerNode(), plVault::kChronicleFolder, 1);
if (rvnFldr != nil)
VaultAddChildNode(rvnFldr->nodeId, node->nodeId, 0, nil, nil);
}
}
//============================================================================
void VaultAddChronicleEntryAndWait (
const wchar entryName[],

2
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h

@ -356,8 +356,6 @@ bool VaultUnregisterVisitAgeAndWait (const plAgeInfoStruct * info);
RelVaultNode * VaultFindChronicleEntryIncRef (const wchar entryName[], int entryType = -1);
bool VaultHasChronicleEntry (const wchar entryName[], int entryType = -1);
// if entry of same name and type already exists, value is updated
void VaultAddChronicleEntry (const wchar entryName[], int entryType, const wchar entryValue[]);
void _VaultAddChronicleEntryCB(ENetError result, void* state, void * param, RelVaultNode* node);
void VaultAddChronicleEntryAndWait (
const wchar entryName[],
int entryType,

Loading…
Cancel
Save