aboutsummaryrefslogtreecommitdiff
path: root/src/game/MapUpdater.cpp
diff options
context:
space:
mode:
authorXTZGZoReX <none@none>2010-04-05 13:08:47 +0200
committerXTZGZoReX <none@none>2010-04-05 13:08:47 +0200
commit7c277c87d8dffe89deee84592e337974fe0ef96e (patch)
tree4a7f53267c567f4f6377305d31b8b76d0f940fd6 /src/game/MapUpdater.cpp
parenta795a1110c6b62df841b8a48d8e634ede255c486 (diff)
* Only call Database::ThreadStart()/ThreadEnd() once per thread.
* Some cleanups in MapUpdater/DelayExecutor. --HG-- branch : trunk
Diffstat (limited to 'src/game/MapUpdater.cpp')
-rw-r--r--src/game/MapUpdater.cpp105
1 files changed, 52 insertions, 53 deletions
diff --git a/src/game/MapUpdater.cpp b/src/game/MapUpdater.cpp
index 11af01d95e0..f9bb5e2bbbc 100644
--- a/src/game/MapUpdater.cpp
+++ b/src/game/MapUpdater.cpp
@@ -6,103 +6,102 @@
#include <ace/Guard_T.h>
#include <ace/Method_Request.h>
-//the reason this things are here is that i want to make
-//the netcode patch and the multithreaded maps independant
-//once they are merged 1 class should be used
class WDBThreadStartReq1 : public ACE_Method_Request
{
public:
- WDBThreadStartReq1(){}
- virtual int
- call (void)
- {
- WorldDatabase.ThreadStart();
- CharacterDatabase.ThreadStart();
- loginDatabase.ThreadStart();
- return 0;
- }
+ WDBThreadStartReq1()
+ {
+ }
+
+ virtual int call()
+ {
+ WorldDatabase.ThreadStart();
+ return 0;
+ }
};
class WDBThreadEndReq1 : public ACE_Method_Request
{
public:
- WDBThreadEndReq1(){}
- virtual int
- call (void)
- {
- WorldDatabase.ThreadEnd();
- CharacterDatabase.ThreadEnd();
- loginDatabase.ThreadEnd();
- return 0;
- }
+ WDBThreadEndReq1()
+ {
+ }
+
+ virtual int call()
+ {
+ WorldDatabase.ThreadEnd();
+ return 0;
+ }
};
class MapUpdateRequest : public ACE_Method_Request
{
- public:
+ private:
+
Map& m_map;
MapUpdater& m_updater;
ACE_UINT32 m_diff;
- MapUpdateRequest(Map& m, MapUpdater& u, ACE_UINT32 d) : m_map(m), m_updater(u), m_diff(d){}
- virtual int
- call (void)
- {
- m_map.Update (m_diff);
- m_updater.update_finished ();
- return 0;
- }
+ public:
+
+ MapUpdateRequest(Map& m, MapUpdater& u, ACE_UINT32 d)
+ : m_map(m), m_updater(u), m_diff(d)
+ {
+ }
+
+ virtual int call()
+ {
+ m_map.Update (m_diff);
+ m_updater.update_finished ();
+ return 0;
+ }
};
-MapUpdater::MapUpdater() :
-m_mutex(),
-m_condition(m_mutex),
-m_executor(),
-pedning_requests(0)
+MapUpdater::MapUpdater()
+ : m_mutex(), m_condition(m_mutex), m_executor(), pending_requests(0)
{
- return;
}
MapUpdater::~MapUpdater()
{
- this->deactivate();
+ deactivate();
}
int MapUpdater::activate(size_t num_threads)
{
- return this->m_executor.activate(static_cast<int> (num_threads), new WDBThreadStartReq1, new WDBThreadEndReq1);
+ return m_executor.activate((int)num_threads, new WDBThreadStartReq1, new WDBThreadEndReq1);
}
-int MapUpdater::deactivate(void)
+int MapUpdater::deactivate()
{
- this->wait();
+ wait();
- return this->m_executor.deactivate();
+ return m_executor.deactivate();
}
int MapUpdater::wait()
{
- ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, this->m_mutex, -1);
+ ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, m_mutex, -1);
- while(this->pedning_requests > 0)
- this->m_condition.wait();
+ while (pending_requests > 0)
+ m_condition.wait();
return 0;
}
int MapUpdater::schedule_update(Map& map, ACE_UINT32 diff)
{
- ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, this->m_mutex, -1);
+ ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, m_mutex, -1);
- ++this->pedning_requests;
+ ++pending_requests;
- if (this->m_executor.execute(new MapUpdateRequest(map, *this, diff)) == -1)
+ if (m_executor.execute(new MapUpdateRequest(map, *this, diff)) == -1)
{
ACE_DEBUG((LM_ERROR, ACE_TEXT("(%t) \n"), ACE_TEXT("Failed to schedule Map Update")));
- --this->pedning_requests;
+ --pending_requests;
return -1;
}
@@ -116,15 +115,15 @@ bool MapUpdater::activated()
void MapUpdater::update_finished()
{
- ACE_GUARD(ACE_Thread_Mutex, guard, this->m_mutex);
+ ACE_GUARD(ACE_Thread_Mutex, guard, m_mutex);
- if (this->pedning_requests == 0)
+ if (pending_requests == 0)
{
- ACE_ERROR((LM_ERROR,ACE_TEXT("(%t)\n"), ACE_TEXT("MapUpdater::update_finished BUG, report to devs")));
+ ACE_ERROR((LM_ERROR, ACE_TEXT("(%t)\n"), ACE_TEXT("MapUpdater::update_finished BUG, report to devs")));
return;
}
- --this->pedning_requests;
+ --pending_requests;
- this->m_condition.broadcast();
+ m_condition.broadcast();
}