summaryrefslogtreecommitdiffstats
path: root/source/cRoot.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-10-26 15:07:39 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-10-26 15:07:39 +0200
commitbcc1450ba930d991e9569d05810aa4aada68869d (patch)
tree7971111b5db3664dd4bda3d56e938c4c5affea44 /source/cRoot.cpp
parentadded simple code for server side item durabilty on tool items that have durabilty. need to add block destroyed durability modifier. (diff)
downloadcuberite-bcc1450ba930d991e9569d05810aa4aada68869d.tar
cuberite-bcc1450ba930d991e9569d05810aa4aada68869d.tar.gz
cuberite-bcc1450ba930d991e9569d05810aa4aada68869d.tar.bz2
cuberite-bcc1450ba930d991e9569d05810aa4aada68869d.tar.lz
cuberite-bcc1450ba930d991e9569d05810aa4aada68869d.tar.xz
cuberite-bcc1450ba930d991e9569d05810aa4aada68869d.tar.zst
cuberite-bcc1450ba930d991e9569d05810aa4aada68869d.zip
Diffstat (limited to '')
-rw-r--r--source/cRoot.cpp42
1 files changed, 11 insertions, 31 deletions
diff --git a/source/cRoot.cpp b/source/cRoot.cpp
index 7f0012764..531d0c9f3 100644
--- a/source/cRoot.cpp
+++ b/source/cRoot.cpp
@@ -9,6 +9,7 @@
#include "cPluginManager.h"
#include "cMonsterConfig.h"
#include "cSleep.h"
+#include "cThread.h"
#include "../iniFile/iniFile.h"
@@ -34,7 +35,7 @@ cRoot::cRoot()
, m_Log( 0 )
, m_bStop( false )
, m_bRestart( false )
- , m_hInputThread( 0 )
+ , m_InputThread( 0 )
{
s_Root = this;
}
@@ -44,21 +45,16 @@ cRoot::~cRoot()
s_Root = 0;
}
-#ifdef _WIN32
-DWORD WINAPI cRoot_InputThread(LPVOID lpParam)
-#else
-void *cRoot_InputThread( void *lpParam )
-#endif
+void cRoot::InputThread(void* a_Params)
{
- cRoot* Root = (cRoot*)lpParam;
+ cRoot& self = *(cRoot*)a_Params;
- while( 1 )
+ while( !(self.m_bStop || self.m_bRestart) )
{
std::string Command;
std::getline(std::cin, Command);
- Root->ServerCommand( Command.c_str() );
+ self.ServerCommand( Command.c_str() );
}
- return 0;
}
void cRoot::Start()
@@ -66,19 +62,6 @@ void cRoot::Start()
if( m_Log ) delete m_Log, m_Log = 0;
m_Log = new cMCLogger();
-#ifdef _WIN32
- m_hInputThread = CreateThread(
- NULL, // default security
- 0, // default stack size
- cRoot_InputThread, // name of the thread function
- this, // thread parameters
- 0, // default startup flags
- NULL);
-#else
- m_hInputThread = new pthread_t;
- pthread_create( (pthread_t*)m_hInputThread, NULL, cRoot_InputThread, this );
-#endif
-
m_bStop = false;
while(!m_bStop)
{
@@ -118,11 +101,16 @@ void cRoot::Start()
m_Server->StartListenThread();
//cHeartBeat* HeartBeat = new cHeartBeat();
+ m_InputThread = new cThread( InputThread, this );
+ m_InputThread->Start( true );
+
while( !m_bStop && !m_bRestart ) // These are modified by external threads
{
cSleep::MilliSleep( 1000 );
}
+ delete m_InputThread; m_InputThread = 0;
+
// Deallocate stuffs
m_Server->Shutdown(); // This waits for threads to stop and d/c clients
delete m_PluginManager; m_PluginManager = 0; // This should be first
@@ -136,14 +124,6 @@ void cRoot::Start()
delete m_Server; m_Server = 0;
}
- // No other way to get it to exit
-#ifdef _WIN32
- TerminateThread( m_hInputThread, 0 );
-#else
- // TODO: pthread_kill
- delete (pthread_t*)m_hInputThread;
-#endif
-
delete m_Log; m_Log = 0;
}