forked from oerkki/voxelands
jthread 1.3.1
This commit is contained in:
parent
73c34cb507
commit
19d9a7a32e
|
@ -1,6 +1,10 @@
|
|||
# Look for jthread, use our own if not found
|
||||
|
||||
FIND_PATH(JTHREAD_INCLUDE_DIR jthread.h)
|
||||
FIND_PACKAGE(PkgConfig)
|
||||
pkg_check_modules(PC_JTHREAD QUIET jthread)
|
||||
|
||||
FIND_PATH(JTHREAD_INCLUDE_DIR jthread.h
|
||||
HINTS ${PC_JTHREAD_INCLUDEDIR} ${PC_JTHREAD_INCLUDE_DIRS})
|
||||
|
||||
FIND_LIBRARY(JTHREAD_LIBRARY NAMES jthread)
|
||||
|
||||
|
@ -12,7 +16,7 @@ IF(JTHREAD_FOUND)
|
|||
MESSAGE(STATUS "Found system jthread header file in ${JTHREAD_INCLUDE_DIR}")
|
||||
MESSAGE(STATUS "Found system jthread library ${JTHREAD_LIBRARY}")
|
||||
ELSE(JTHREAD_FOUND)
|
||||
SET(JTHREAD_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/jthread)
|
||||
SET(JTHREAD_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/jthread")
|
||||
SET(JTHREAD_LIBRARY jthread)
|
||||
MESSAGE(STATUS "Using project jthread library")
|
||||
ENDIF(JTHREAD_FOUND)
|
||||
|
|
|
@ -26,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "common_irrlicht.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
// Player privileges. These form a bitmask stored in the privs field
|
||||
// of the player, and define things they're allowed to do. See also
|
||||
// the static methods Player::privsToString and stringToPrivs that
|
||||
|
|
|
@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "common_irrlicht.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
class BanManager
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -39,6 +39,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#else
|
||||
#endif
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
/*
|
||||
Debug output
|
||||
*/
|
||||
|
|
|
@ -1,9 +1,20 @@
|
|||
if( UNIX )
|
||||
set(jthread_SRCS pthread/jmutex.cpp pthread/jthread.cpp)
|
||||
set(jthread_platform_LIBS "")
|
||||
|
||||
set(JTHREAD_CONFIG_WIN32THREADS "// Using pthread based threads")
|
||||
set(JTHREAD_CONFIG_JMUTEXCRITICALSECTION "")
|
||||
else( UNIX )
|
||||
set(jthread_SRCS win32/jmutex.cpp win32/jthread.cpp)
|
||||
set(jthread_platform_LIBS "")
|
||||
|
||||
set(JTHREAD_CONFIG_WIN32THREADS "#define JTHREAD_CONFIG_WIN32THREADS")
|
||||
set(JTHREAD_WIN32_CRITICALSECTION OFF CACHE BOOL "If set to false, use standard mutex. If set to true, use a critical section object.")
|
||||
if (JTHREAD_WIN32_CRITICALSECTION)
|
||||
set(JTHREAD_CONFIG_JMUTEXCRITICALSECTION "#define JTHREAD_CONFIG_JMUTEXCRITICALSECTION")
|
||||
else (JTHREAD_WIN32_CRITICALSECTION)
|
||||
set(JTHREAD_CONFIG_JMUTEXCRITICALSECTION "// Using standard Win32 mutex")
|
||||
endif (JTHREAD_WIN32_CRITICALSECTION)
|
||||
endif( UNIX )
|
||||
|
||||
add_library(jthread ${jthread_SRCS})
|
||||
|
@ -14,3 +25,5 @@ target_link_libraries(
|
|||
)
|
||||
|
||||
|
||||
configure_file("${PROJECT_SOURCE_DIR}/jthread/jthreadconfig.h.in"
|
||||
"${PROJECT_BINARY_DIR}/jthread/jthreadconfig.h")
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
This file is a part of the JThread package, which contains some object-
|
||||
oriented thread wrappers for different thread implementations.
|
||||
|
||||
Copyright (c) 2000-2006 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
Copyright (c) 2000-2011 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
@ -25,27 +25,29 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifndef JMUTEX_H
|
||||
#ifndef JTHREAD_JMUTEX_H
|
||||
|
||||
#define JMUTEX_H
|
||||
#define JTHREAD_JMUTEX_H
|
||||
|
||||
#if (defined(WIN32) || defined(_WIN32_WCE))
|
||||
#include "jthreadconfig.h"
|
||||
#ifdef JTHREAD_CONFIG_WIN32THREADS
|
||||
#ifndef _WIN32_WCE
|
||||
#include <process.h>
|
||||
#endif // _WIN32_WCE
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
// CriticalSection is way faster than the alternative
|
||||
#define JMUTEX_CRITICALSECTION
|
||||
#else // using pthread
|
||||
#include <pthread.h>
|
||||
#endif // WIN32
|
||||
#endif // JTHREAD_CONFIG_WIN32THREADS
|
||||
|
||||
#define ERR_JMUTEX_ALREADYINIT -1
|
||||
#define ERR_JMUTEX_NOTINIT -2
|
||||
#define ERR_JMUTEX_CANTCREATEMUTEX -3
|
||||
|
||||
class JMutex
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
class JTHREAD_IMPORTEXPORT JMutex
|
||||
{
|
||||
public:
|
||||
JMutex();
|
||||
|
@ -55,16 +57,19 @@ public:
|
|||
int Unlock();
|
||||
bool IsInitialized() { return initialized; }
|
||||
private:
|
||||
#if (defined(WIN32) || defined(_WIN32_WCE))
|
||||
#ifdef JMUTEX_CRITICALSECTION
|
||||
#ifdef JTHREAD_CONFIG_WIN32THREADS
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
CRITICAL_SECTION mutex;
|
||||
#else // Use standard mutex
|
||||
HANDLE mutex;
|
||||
#endif // JMUTEX_CRITICALSECTION
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
#else // pthread mutex
|
||||
pthread_mutex_t mutex;
|
||||
#endif // WIN32
|
||||
#endif // JTHREAD_CONFIG_WIN32THREADS
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
#endif // JMUTEX_H
|
||||
} // end namespace
|
||||
|
||||
#endif // JTHREAD_JMUTEX_H
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
This file is a part of the JThread package, which contains some object-
|
||||
oriented thread wrappers for different thread implementations.
|
||||
|
||||
Copyright (c) 2000-2006 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
Copyright (c) 2000-2011 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
@ -25,13 +25,17 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifndef JMUTEXAUTOLOCK_H
|
||||
#ifndef JTHREAD_JMUTEXAUTOLOCK_H
|
||||
|
||||
#define JMUTEXAUTOLOCK_H
|
||||
#define JTHREAD_JMUTEXAUTOLOCK_H
|
||||
|
||||
#include "jthreadconfig.h"
|
||||
#include "jmutex.h"
|
||||
|
||||
class JMutexAutoLock
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
class JTHREAD_IMPORTEXPORT JMutexAutoLock
|
||||
{
|
||||
public:
|
||||
JMutexAutoLock(JMutex &m) : mutex(m) { mutex.Lock(); }
|
||||
|
@ -40,4 +44,7 @@ private:
|
|||
JMutex &mutex;
|
||||
};
|
||||
|
||||
#endif // JMUTEXAUTOLOCK_H
|
||||
} // end namespace
|
||||
|
||||
#endif // JTHREAD_JMUTEXAUTOLOCK_H
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
This file is a part of the JThread package, which contains some object-
|
||||
oriented thread wrappers for different thread implementations.
|
||||
|
||||
Copyright (c) 2000-2006 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
Copyright (c) 2000-2011 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
@ -25,10 +25,11 @@
|
|||
|
||||
*/
|
||||
|
||||
#ifndef JTHREAD_H
|
||||
#ifndef JTHREAD_JTHREAD_H
|
||||
|
||||
#define JTHREAD_H
|
||||
#define JTHREAD_JTHREAD_H
|
||||
|
||||
#include "jthreadconfig.h"
|
||||
#include "jmutex.h"
|
||||
|
||||
#define ERR_JTHREAD_CANTINITMUTEX -1
|
||||
|
@ -37,7 +38,10 @@
|
|||
#define ERR_JTHREAD_NOTRUNNING -4
|
||||
#define ERR_JTHREAD_ALREADYRUNNING -5
|
||||
|
||||
class JThread
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
class JTHREAD_IMPORTEXPORT JThread
|
||||
{
|
||||
public:
|
||||
JThread();
|
||||
|
@ -51,7 +55,7 @@ protected:
|
|||
void ThreadStarted();
|
||||
private:
|
||||
|
||||
#if (defined(WIN32) || defined(_WIN32_WCE))
|
||||
#ifdef JTHREAD_CONFIG_WIN32THREADS
|
||||
#ifdef _WIN32_WCE
|
||||
DWORD threadid;
|
||||
static DWORD WINAPI TheThread(void *param);
|
||||
|
@ -64,7 +68,7 @@ private:
|
|||
static void *TheThread(void *param);
|
||||
|
||||
pthread_t threadid;
|
||||
#endif // WIN32
|
||||
#endif // JTHREAD_CONFIG_WIN32THREADS
|
||||
void *retval;
|
||||
bool running;
|
||||
|
||||
|
@ -73,5 +77,7 @@ private:
|
|||
bool mutexinit;
|
||||
};
|
||||
|
||||
#endif // JTHREAD_H
|
||||
} // end namespace
|
||||
|
||||
#endif // JTHREAD_JTHREAD_H
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
|
||||
This file is a part of the JThread package, which contains some object-
|
||||
oriented thread wrappers for different thread implementations.
|
||||
|
||||
Copyright (c) 2000-2011 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef JTHREADCONFIG_H
|
||||
|
||||
#define JTHREADCONFIG_H
|
||||
|
||||
#define JTHREAD_IMPORT ${JTHREAD_IMPORT}
|
||||
#define JTHREAD_EXPORT ${JTHREAD_EXPORT}
|
||||
#ifdef JTHREAD_COMPILING
|
||||
#define JTHREAD_IMPORTEXPORT JTHREAD_EXPORT
|
||||
#else
|
||||
#define JTHREAD_IMPORTEXPORT JTHREAD_IMPORT
|
||||
#endif // JTHREAD_COMPILING
|
||||
|
||||
${JTHREAD_CONFIG_WIN32THREADS}
|
||||
|
||||
${JTHREAD_CONFIG_JMUTEXCRITICALSECTION}
|
||||
|
||||
#endif // JTHREADCONFIG_H
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
This file is a part of the JThread package, which contains some object-
|
||||
oriented thread wrappers for different thread implementations.
|
||||
|
||||
Copyright (c) 2000-2006 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
Copyright (c) 2000-2011 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
@ -27,6 +27,9 @@
|
|||
|
||||
#include "jmutex.h"
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
JMutex::JMutex()
|
||||
{
|
||||
initialized = false;
|
||||
|
@ -65,3 +68,6 @@ int JMutex::Unlock()
|
|||
pthread_mutex_unlock(&mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
This file is a part of the JThread package, which contains some object-
|
||||
oriented thread wrappers for different thread implementations.
|
||||
|
||||
Copyright (c) 2000-2006 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
Copyright (c) 2000-2011 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
@ -30,6 +30,9 @@
|
|||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
JThread::JThread()
|
||||
{
|
||||
retval = NULL;
|
||||
|
@ -178,3 +181,5 @@ void JThread::ThreadStarted()
|
|||
continuemutex2.Unlock();
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
This file is a part of the JThread package, which contains some object-
|
||||
oriented thread wrappers for different thread implementations.
|
||||
|
||||
Copyright (c) 2000-2006 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
Copyright (c) 2000-2011 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
@ -27,6 +27,9 @@
|
|||
|
||||
#include "jmutex.h"
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
JMutex::JMutex()
|
||||
{
|
||||
initialized = false;
|
||||
|
@ -35,24 +38,24 @@ JMutex::JMutex()
|
|||
JMutex::~JMutex()
|
||||
{
|
||||
if (initialized)
|
||||
#ifdef JMUTEX_CRITICALSECTION
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
DeleteCriticalSection(&mutex);
|
||||
#else
|
||||
CloseHandle(mutex);
|
||||
#endif // JMUTEX_CRITICALSECTION
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
}
|
||||
|
||||
int JMutex::Init()
|
||||
{
|
||||
if (initialized)
|
||||
return ERR_JMUTEX_ALREADYINIT;
|
||||
#ifdef JMUTEX_CRITICALSECTION
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
InitializeCriticalSection(&mutex);
|
||||
#else
|
||||
mutex = CreateMutex(NULL,FALSE,NULL);
|
||||
if (mutex == NULL)
|
||||
return ERR_JMUTEX_CANTCREATEMUTEX;
|
||||
#endif // JMUTEX_CRITICALSECTION
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
initialized = true;
|
||||
return 0;
|
||||
}
|
||||
|
@ -61,11 +64,11 @@ int JMutex::Lock()
|
|||
{
|
||||
if (!initialized)
|
||||
return ERR_JMUTEX_NOTINIT;
|
||||
#ifdef JMUTEX_CRITICALSECTION
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
EnterCriticalSection(&mutex);
|
||||
#else
|
||||
WaitForSingleObject(mutex,INFINITE);
|
||||
#endif // JMUTEX_CRITICALSECTION
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -73,11 +76,12 @@ int JMutex::Unlock()
|
|||
{
|
||||
if (!initialized)
|
||||
return ERR_JMUTEX_NOTINIT;
|
||||
#ifdef JMUTEX_CRITICALSECTION
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
LeaveCriticalSection(&mutex);
|
||||
#else
|
||||
ReleaseMutex(mutex);
|
||||
#endif // JMUTEX_CRITICALSECTION
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
This file is a part of the JThread package, which contains some object-
|
||||
oriented thread wrappers for different thread implementations.
|
||||
|
||||
Copyright (c) 2000-2006 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
Copyright (c) 2000-2011 Jori Liesenborgs (jori.liesenborgs@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
@ -26,11 +26,15 @@
|
|||
*/
|
||||
|
||||
#include "jthread.h"
|
||||
#include "jmutexautolock.h"
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
#include <process.h>
|
||||
#endif // _WIN32_WCE
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
JThread::JThread()
|
||||
{
|
||||
retval = NULL;
|
||||
|
@ -130,14 +134,13 @@ bool JThread::IsRunning()
|
|||
|
||||
void *JThread::GetReturnValue()
|
||||
{
|
||||
JMutexAutoLock autolock(runningmutex);
|
||||
void *val;
|
||||
|
||||
runningmutex.Lock();
|
||||
if (running)
|
||||
val = NULL;
|
||||
else
|
||||
val = retval;
|
||||
runningmutex.Unlock();
|
||||
return val;
|
||||
}
|
||||
|
||||
|
@ -175,3 +178,5 @@ void JThread::ThreadStarted()
|
|||
continuemutex2.Unlock();
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ extern "C" {
|
|||
#include "sqlite3.h"
|
||||
}
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
class MapSector;
|
||||
class ServerMapSector;
|
||||
class ClientMapSector;
|
||||
|
|
|
@ -50,6 +50,8 @@ struct ValueSpec
|
|||
const char *help;
|
||||
};
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -25,6 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "utility.h"
|
||||
#include <string>
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
/*
|
||||
tile.{h,cpp}: Texture handling stuff.
|
||||
*/
|
||||
|
|
|
@ -36,6 +36,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "exceptions.h"
|
||||
#include "porting.h"
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
extern const v3s16 g_6dirs[6];
|
||||
|
||||
extern const v3s16 g_26dirs[26];
|
||||
|
|
Loading…
Reference in New Issue