aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/CMakeLists.txt3
-rw-r--r--src/shared/DelayExecutor.cpp114
-rw-r--r--src/shared/DelayExecutor.h33
-rw-r--r--src/shared/Util.cpp56
4 files changed, 149 insertions, 57 deletions
diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt
index de73967546b..5349a89f613 100644
--- a/src/shared/CMakeLists.txt
+++ b/src/shared/CMakeLists.txt
@@ -9,6 +9,8 @@ SET(shared_STAT_SRCS
ByteBuffer.h
Common.cpp
Common.h
+ DelayExecutor.cpp
+ DelayExecutor.h
Errors.h
Log.cpp
Log.h
@@ -21,7 +23,6 @@ SET(shared_STAT_SRCS
WorldPacket.h
SystemConfig.h
)
-add_definitions(-fopenmp)
add_library(shared STATIC ${shared_STAT_SRCS})
target_link_libraries(
shared
diff --git a/src/shared/DelayExecutor.cpp b/src/shared/DelayExecutor.cpp
new file mode 100644
index 00000000000..07a691d6357
--- /dev/null
+++ b/src/shared/DelayExecutor.cpp
@@ -0,0 +1,114 @@
+#include <ace/Singleton.h>
+#include <ace/Thread_Mutex.h>
+#include <ace/Log_Msg.h>
+
+#include "DelayExecutor.h"
+
+DelayExecutor*
+DelayExecutor::instance()
+{
+ return ACE_Singleton<DelayExecutor, ACE_Thread_Mutex>::instance();
+}
+
+DelayExecutor::DelayExecutor():
+activated_ (false),
+pre_svc_hook_ (0),
+post_svc_hook_ (0) {}
+
+DelayExecutor::~DelayExecutor()
+{
+ if (pre_svc_hook_)
+ delete pre_svc_hook_;
+
+ if (post_svc_hook_)
+ delete post_svc_hook_;
+
+ this->deactivate ();
+}
+
+int DelayExecutor::deactivate()
+{
+ if (!this->activated())
+ return -1;
+
+ this->activated(false);
+
+ this->queue_.queue()->deactivate();
+
+ this->wait();
+
+ return 0;
+}
+
+int DelayExecutor::svc (void)
+{
+ if (pre_svc_hook_)
+ pre_svc_hook_->call();
+
+ for (;;)
+ {
+ ACE_Method_Request* rq = this->queue_.dequeue();
+
+ if (!rq)
+ break;
+
+ rq->call();
+
+ delete rq;
+ }
+
+ if (post_svc_hook_)
+ post_svc_hook_->call();
+
+ return 0;
+}
+
+int DelayExecutor::activate(int num_threads, ACE_Method_Request* pre_svc_hook, ACE_Method_Request* post_svc_hook)
+{
+ if (this->activated())
+ return -1;
+
+ if (num_threads < 1)
+ return -1;
+
+ if (pre_svc_hook_)
+ delete pre_svc_hook_;
+
+ if (post_svc_hook_)
+ delete post_svc_hook_;
+
+ this->pre_svc_hook_ = pre_svc_hook;
+ this->post_svc_hook_ = post_svc_hook;
+
+ this->queue_.queue ()->activate ();
+
+ if (ACE_Task_Base::activate(THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED, num_threads) == -1)
+ return -1;
+
+ this->activated(true);
+
+ return true;
+}
+
+int DelayExecutor::execute(ACE_Method_Request* new_req)
+{
+ if (new_req == NULL)
+ return -1;
+
+ if (this->queue_.enqueue(new_req,(ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
+ {
+ delete new_req;
+ ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%t) %p\n"), ACE_TEXT("DelayExecutor::execute enqueue")), -1);
+ }
+ return 0;
+}
+
+bool DelayExecutor::activated()
+{
+ return this->activated_;
+}
+
+void DelayExecutor::activated(bool s)
+{
+ this->activated_ = s;
+}
diff --git a/src/shared/DelayExecutor.h b/src/shared/DelayExecutor.h
new file mode 100644
index 00000000000..7a160d5ec92
--- /dev/null
+++ b/src/shared/DelayExecutor.h
@@ -0,0 +1,33 @@
+#ifndef _M_DELAY_EXECUTOR_H
+#define _M_DELAY_EXECUTOR_H
+
+#include <ace/Task.h>
+#include <ace/Activation_Queue.h>
+#include <ace/Method_Request.h>
+
+class DelayExecutor : protected ACE_Task_Base
+{
+ public:
+ DelayExecutor();
+ virtual ~DelayExecutor();
+
+ static DelayExecutor* instance();
+
+ int execute(ACE_Method_Request* new_req);
+
+ int activate(int num_threads = 1, ACE_Method_Request* pre_svc_hook = 0, ACE_Method_Request* post_svc_hook = 0);
+
+ int deactivate();
+
+ bool activated();
+
+ virtual int svc(void);
+ private:
+ ACE_Activation_Queue queue_;
+ ACE_Method_Request* pre_svc_hook_;
+ ACE_Method_Request* post_svc_hook_;
+
+ void activated(bool s);
+ bool activated_;
+};
+#endif // _M_DELAY_EXECUTOR_H
diff --git a/src/shared/Util.cpp b/src/shared/Util.cpp
index 9846b48286c..c5384b6f32e 100644
--- a/src/shared/Util.cpp
+++ b/src/shared/Util.cpp
@@ -28,60 +28,6 @@
typedef ACE_TSS<MTRand> MTRandTSS;
static MTRandTSS mtRand;
-#ifdef MULTI_THREAD_MAP
-
-int32 irand (int32 min, int32 max)
-{
- int32 result;
-#pragma omp critical (mtrand)
-{
- result = int32 (mtRand->randInt (max - min)) + min;
-}
- return result;
-}
-
-uint32 urand (uint32 min, uint32 max)
-{
- uint32 result;
-#pragma omp critical (mtrand)
-{
- result = mtRand->randInt (max - min) + min;
-}
- return result;
-}
-
-int32 rand32 ()
-{
- int32 result;
-#pragma omp critical (mtrand)
-{
- result = mtRand->randInt ();
-}
- return result;
-}
-
-double rand_norm(void)
-{
- double result;
-#pragma omp critical (mtrand)
-{
- result = mtRand->randExc ();
-}
- return result;
-}
-
-double rand_chance (void)
-{
- double result;
-#pragma omp critical (mtrand)
-{
- result = mtRand->randExc (100.0);
-}
- return result;
-}
-
-#else
-
int32 irand (int32 min, int32 max)
{
return int32 (mtRand->randInt (max - min)) + min;
@@ -107,8 +53,6 @@ double rand_chance (void)
return mtRand->randExc (100.0);
}
-#endif
-
Tokens StrSplit(const std::string &src, const std::string &sep)
{
Tokens r;