From e3374832308457a77e08b734b7bd1503e6a6acd0 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Thu, 3 Apr 2008 00:48:20 +0200 Subject: [PATCH] Aquire locks in the Initializer. --- src/Initializer/Initializer.cpp | 51 ++++++++++++++++++++++++++--- src/Initializer/Initializer.mk | 5 ++- src/Initializer/Initializer.project | 64 +++++++++++++++++++------------------ 3 files changed, 84 insertions(+), 36 deletions(-) diff --git a/src/Initializer/Initializer.cpp b/src/Initializer/Initializer.cpp index e67977a..35428c0 100644 --- a/src/Initializer/Initializer.cpp +++ b/src/Initializer/Initializer.cpp @@ -32,11 +32,18 @@ bool Initializer::VerifyDatabaseVersion() bool equal = true; KeyValuePtr key(new KeyValue(db::TableImpls::Get()->VERSION->VERSIONID, 1)); - SavableManagerPtr manager = SavableManager::bykey(key); + SavableManagerPtr manager; + + try { + manager = SavableManager::bykey(key); + } catch(RowNotFoundException& e) { + Global::Get()->log("Could not retreive version info."); + return false; + } if(manager->getValue(db::TableImpls::Get()->VERSION->MAJOR)->getIntegerValue() != game::major) { - Global::Get()->logf("Major / Major mismatch.\n"); + Global::Get()->log("Major / Major mismatch.\n"); equal = false; } @@ -106,7 +113,9 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->VERSION); - + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable + ValuePtr value; KeysPtr keys(new Keys(db::TableImpls::Get()->VERSION)); @@ -126,6 +135,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->unlock(); } try @@ -136,6 +146,8 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->ACCOUNTS); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable KeysPtr keys(new Keys(db::TableImpls::Get()->ACCOUNTS)); keys->addKey(db::TableImpls::Get()->ACCOUNTS->ACCOUNTID, 1); @@ -148,6 +160,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->unlock(); } try @@ -158,6 +171,8 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->ROOMS); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable KeysPtr keys(new Keys(db::TableImpls::Get()->ROOMS)); keys->addKey(db::TableImpls::Get()->ROOMS->ROOMID, 1); @@ -176,6 +191,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->lock(); } try @@ -187,6 +203,8 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->RACES); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable KeysPtr keys(new Keys(db::TableImpls::Get()->RACES)); keys->addKey(db::TableImpls::Get()->RACES->RACEID, 1); @@ -196,6 +214,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->unlock(); } try @@ -206,6 +225,8 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->ENTITIES); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable KeysPtr keys(new Keys(db::TableImpls::Get()->ENTITIES)); keys->addKey(db::TableImpls::Get()->ENTITIES->ENTITYID, 1); @@ -224,6 +245,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->unlock(); } try @@ -249,6 +271,8 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->SECTORS); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable ValuePtr value = ValuePtr(new FieldValue(db::TableImpls::Get()->SECTORS->NAME, "grass")); manager->setValue(value); @@ -263,6 +287,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->unlock(); } try @@ -273,6 +298,8 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->CHANNELS); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable ValuePtr value = ValuePtr(new FieldValue(db::TableImpls::Get()->CHANNELS->NAME, "ooc")); manager->setValue(value); @@ -284,6 +311,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->unlock(); } try @@ -294,6 +322,8 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->GRANTGROUPS); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable ValuePtr value = ValuePtr(new FieldValue(db::TableImpls::Get()->GRANTGROUPS->NAME, "All")); manager->setValue(value); @@ -305,6 +335,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->unlock(); } try @@ -315,6 +346,8 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->GRANTGROUPS); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable ValuePtr value = ValuePtr(new FieldValue(db::TableImpls::Get()->GRANTGROUPS->NAME, "Admin")); manager->setValue(value); @@ -326,6 +359,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->unlock(); } try @@ -336,6 +370,8 @@ void Initializer::InitDatabase() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->GRANTGROUPS); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable ValuePtr value = ValuePtr(new FieldValue(db::TableImpls::Get()->GRANTGROUPS->NAME, "Builder")); manager->setValue(value); @@ -347,6 +383,7 @@ void Initializer::InitDatabase() manager->setValue(value); manager->save(); + manager->unlock(); } try @@ -405,7 +442,7 @@ void Initializer::InitColours() { "Light Magenta", "M", "1;35m" }, { "Light Cyan", "C", "1;36m" }, { "White", "W", "1;37m" }, - { "Gray", "L", "1;30m" }, + { "Light Gray", "L", "1;30m" }, }; int size = sizeof(colours) / sizeof(colours[0]); @@ -421,6 +458,8 @@ void Initializer::InitColours() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->COLOURS); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable ValuePtr value; @@ -437,6 +476,7 @@ void Initializer::InitColours() manager->setValue(value); manager->save(); + manager->unlock(); } } } @@ -468,6 +508,8 @@ void Initializer::InitCommands() catch(RowNotFoundException& e) { SavableManagerPtr manager = SavableManager::getnew(db::TableImpls::Get()->COMMANDS); + bool locked = manager->lock(); + Assert(locked); // we're the only one active, should always be lockable ValuePtr value; @@ -502,6 +544,7 @@ void Initializer::InitCommands() } manager->save(); + manager->unlock(); } } } diff --git a/src/Initializer/Initializer.mk b/src/Initializer/Initializer.mk index 33fa6bd..02f1089 100644 --- a/src/Initializer/Initializer.mk +++ b/src/Initializer/Initializer.mk @@ -39,12 +39,15 @@ Objects=$(IntermediateDirectory)/main$(ObjectSuffix) $(IntermediateDirectory)/In ## all: $(OutputFile) -$(OutputFile): makeDirStep $(Objects) +$(OutputFile): makeDirStep PrePreBuild $(Objects) $(LinkerName) $(OutputSwitch)$(OutputFile) $(Objects) $(LibPath) $(Libs) $(LinkOptions) makeDirStep: @test -d Intermediate || mkdir Intermediate +PrePreBuild: + + PreBuild: diff --git a/src/Initializer/Initializer.project b/src/Initializer/Initializer.project index 8ad6e41..ed7bb98 100644 --- a/src/Initializer/Initializer.project +++ b/src/Initializer/Initializer.project @@ -9,7 +9,7 @@ - + @@ -32,16 +32,18 @@ - - - - + + + + None - + - - + + + + @@ -65,16 +67,16 @@ - - - - + + + + None - + - - + + @@ -98,16 +100,16 @@ - - - - + + + + None - + - - + + @@ -123,24 +125,24 @@ - - - - - - + + + + + + - - + + - + -- 2.11.4.GIT