forked from oerkki/voxelands
remove JMutex, and delete jthread from source tree
This commit is contained in:
parent
3abcae28f1
commit
5c594840bb
|
@ -81,7 +81,6 @@ else()
|
|||
set(CLIENT_PLATFORM_LIBS ${CLIENT_PLATFORM_LIBS} ${XXF86VM_LIBRARY})
|
||||
endif()
|
||||
|
||||
find_package(Jthread REQUIRED)
|
||||
find_package(Sqlite3 REQUIRED)
|
||||
|
||||
configure_file(
|
||||
|
@ -187,7 +186,6 @@ include_directories(
|
|||
${CMAKE_BUILD_TYPE}
|
||||
${PNG_INCLUDE_DIR}
|
||||
${GETTEXT_INCLUDE_DIR}
|
||||
${JTHREAD_INCLUDE_DIR}
|
||||
${SQLITE3_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
|
@ -205,7 +203,6 @@ if(BUILD_CLIENT)
|
|||
${PNG_LIBRARIES}
|
||||
${X11_LIBRARIES}
|
||||
${GETTEXT_LIBRARY}
|
||||
${JTHREAD_LIBRARY}
|
||||
${SQLITE3_LIBRARY}
|
||||
${PLATFORM_LIBS}
|
||||
${CLIENT_PLATFORM_LIBS}
|
||||
|
@ -217,7 +214,6 @@ if(BUILD_SERVER)
|
|||
target_link_libraries(
|
||||
${PROJECT_NAME}-server
|
||||
${ZLIB_LIBRARIES}
|
||||
${JTHREAD_LIBRARY}
|
||||
${SQLITE3_LIBRARY}
|
||||
${PLATFORM_LIBS}
|
||||
)
|
||||
|
@ -365,11 +361,6 @@ endif(USE_GETTEXT)
|
|||
|
||||
# Subdirectories
|
||||
|
||||
if (JTHREAD_FOUND)
|
||||
else (JTHREAD_FOUND)
|
||||
add_subdirectory(jthread)
|
||||
endif (JTHREAD_FOUND)
|
||||
|
||||
if (SQLITE3_FOUND)
|
||||
else (SQLITE3_FOUND)
|
||||
add_subdirectory(sqlite)
|
||||
|
|
23
src/auth.cpp
23
src/auth.cpp
|
@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "auth.h"
|
||||
#include <fstream>
|
||||
#include <jmutexautolock.h>
|
||||
//#include "main.h" // for g_settings
|
||||
#include <sstream>
|
||||
#include "strfnd.h"
|
||||
|
@ -84,7 +83,7 @@ AuthManager::AuthManager(const std::string &authfilepath):
|
|||
m_authfilepath(authfilepath),
|
||||
m_modified(false)
|
||||
{
|
||||
m_mutex.Init();
|
||||
m_mutex.init();
|
||||
|
||||
try{
|
||||
load();
|
||||
|
@ -103,7 +102,7 @@ AuthManager::~AuthManager()
|
|||
|
||||
void AuthManager::load()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
dstream<<"AuthManager: loading from "<<m_authfilepath<<std::endl;
|
||||
std::ifstream is(m_authfilepath.c_str(), std::ios::binary);
|
||||
|
@ -149,7 +148,7 @@ void AuthManager::load()
|
|||
|
||||
void AuthManager::save()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
dstream<<"AuthManager: saving to "<<m_authfilepath<<std::endl;
|
||||
std::ofstream os(m_authfilepath.c_str(), std::ios::binary);
|
||||
|
@ -175,7 +174,7 @@ void AuthManager::save()
|
|||
|
||||
bool AuthManager::exists(const std::string &username)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::map<std::string, AuthData>::Node *n;
|
||||
n = m_authdata.find(username);
|
||||
|
@ -186,7 +185,7 @@ bool AuthManager::exists(const std::string &username)
|
|||
|
||||
void AuthManager::set(const std::string &username, AuthData ad)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
m_authdata[username] = ad;
|
||||
|
||||
|
@ -195,7 +194,7 @@ void AuthManager::set(const std::string &username, AuthData ad)
|
|||
|
||||
void AuthManager::add(const std::string &username)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
m_authdata[username] = AuthData();
|
||||
|
||||
|
@ -204,7 +203,7 @@ void AuthManager::add(const std::string &username)
|
|||
|
||||
std::string AuthManager::getPassword(const std::string &username)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::map<std::string, AuthData>::Node *n;
|
||||
n = m_authdata.find(username);
|
||||
|
@ -217,7 +216,7 @@ std::string AuthManager::getPassword(const std::string &username)
|
|||
void AuthManager::setPassword(const std::string &username,
|
||||
const std::string &password)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::map<std::string, AuthData>::Node *n;
|
||||
n = m_authdata.find(username);
|
||||
|
@ -233,7 +232,7 @@ void AuthManager::setPassword(const std::string &username,
|
|||
|
||||
u64 AuthManager::getPrivs(const std::string &username)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::map<std::string, AuthData>::Node *n;
|
||||
n = m_authdata.find(username);
|
||||
|
@ -245,7 +244,7 @@ u64 AuthManager::getPrivs(const std::string &username)
|
|||
|
||||
void AuthManager::setPrivs(const std::string &username, u64 privs)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::map<std::string, AuthData>::Node *n;
|
||||
n = m_authdata.find(username);
|
||||
|
@ -261,7 +260,7 @@ void AuthManager::setPrivs(const std::string &username, u64 privs)
|
|||
|
||||
bool AuthManager::isModified()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
return m_modified;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,12 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define AUTH_HEADER
|
||||
|
||||
#include <string>
|
||||
#include <jthread.h>
|
||||
#include <jmutex.h>
|
||||
#include "common_irrlicht.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
using namespace jthread;
|
||||
#include "porting.h"
|
||||
#include "threads.h"
|
||||
|
||||
// Player privileges. These form a bitmask stored in the privs field
|
||||
// of the player, and define things they're allowed to do. See also
|
||||
|
@ -94,7 +92,7 @@ public:
|
|||
void setPrivs(const std::string &username, u64 privs);
|
||||
bool isModified();
|
||||
private:
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
std::string m_authfilepath;
|
||||
core::map<std::string, AuthData> m_authdata;
|
||||
bool m_modified;
|
||||
|
|
20
src/ban.cpp
20
src/ban.cpp
|
@ -19,17 +19,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "ban.h"
|
||||
#include <fstream>
|
||||
#include <jmutexautolock.h>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include "strfnd.h"
|
||||
#include "debug.h"
|
||||
#include "threads.h"
|
||||
|
||||
BanManager::BanManager(const std::string &banfilepath):
|
||||
m_banfilepath(banfilepath),
|
||||
m_modified(false)
|
||||
{
|
||||
m_mutex.Init();
|
||||
m_mutex.init();
|
||||
try{
|
||||
load();
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ BanManager::~BanManager()
|
|||
|
||||
void BanManager::load()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
dstream<<"BanManager: loading from "<<m_banfilepath<<std::endl;
|
||||
std::ifstream is(m_banfilepath.c_str(), std::ios::binary);
|
||||
if(is.good() == false)
|
||||
|
@ -74,7 +74,7 @@ void BanManager::load()
|
|||
|
||||
void BanManager::save()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
dstream<<"BanManager: saving to "<<m_banfilepath<<std::endl;
|
||||
std::ofstream os(m_banfilepath.c_str(), std::ios::binary);
|
||||
|
||||
|
@ -95,13 +95,13 @@ void BanManager::save()
|
|||
|
||||
bool BanManager::isIpBanned(const std::string &ip)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
return m_ips.find(ip) != m_ips.end();
|
||||
}
|
||||
|
||||
std::string BanManager::getBanDescription(const std::string &ip_or_name)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
std::string s = "";
|
||||
for(std::map<std::string, std::string>::iterator
|
||||
i = m_ips.begin();
|
||||
|
@ -117,7 +117,7 @@ std::string BanManager::getBanDescription(const std::string &ip_or_name)
|
|||
|
||||
std::string BanManager::getBanName(const std::string &ip)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
std::map<std::string, std::string>::iterator i = m_ips.find(ip);
|
||||
if(i == m_ips.end())
|
||||
return "";
|
||||
|
@ -126,14 +126,14 @@ std::string BanManager::getBanName(const std::string &ip)
|
|||
|
||||
void BanManager::add(const std::string &ip, const std::string &name)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
m_ips[ip] = name;
|
||||
m_modified = true;
|
||||
}
|
||||
|
||||
void BanManager::remove(const std::string &ip_or_name)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
//m_ips.erase(m_ips.find(ip));
|
||||
// Find out all ip-name pairs that match the ip or name
|
||||
std::set<std::string> ips_to_delete;
|
||||
|
@ -157,7 +157,7 @@ void BanManager::remove(const std::string &ip_or_name)
|
|||
|
||||
bool BanManager::isModified()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
return m_modified;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,12 +22,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <jthread.h>
|
||||
#include <jmutex.h>
|
||||
#include "common_irrlicht.h"
|
||||
#include "exceptions.h"
|
||||
|
||||
using namespace jthread;
|
||||
#include "porting.h"
|
||||
#include "threads.h"
|
||||
|
||||
class BanManager
|
||||
{
|
||||
|
@ -44,7 +42,7 @@ public:
|
|||
void remove(const std::string &ip_or_name);
|
||||
bool isModified();
|
||||
private:
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
std::string m_banfilepath;
|
||||
std::map<std::string, std::string> m_ips;
|
||||
bool m_modified;
|
||||
|
|
|
@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "utility.h"
|
||||
#include <iostream>
|
||||
#include "clientserver.h"
|
||||
#include "jmutexautolock.h"
|
||||
#include "main.h"
|
||||
#include <sstream>
|
||||
#include "porting.h"
|
||||
|
@ -32,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "profiler.h"
|
||||
#include "log.h"
|
||||
#include "http.h"
|
||||
#include "threads.h"
|
||||
|
||||
/*
|
||||
QueuedMeshUpdate
|
||||
|
@ -56,12 +56,12 @@ QueuedMeshUpdate::~QueuedMeshUpdate()
|
|||
|
||||
MeshUpdateQueue::MeshUpdateQueue()
|
||||
{
|
||||
m_mutex.Init();
|
||||
m_mutex.init();
|
||||
}
|
||||
|
||||
MeshUpdateQueue::~MeshUpdateQueue()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::list<QueuedMeshUpdate*>::Iterator i;
|
||||
for(i=m_queue.begin(); i!=m_queue.end(); i++)
|
||||
|
@ -80,7 +80,7 @@ void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_se
|
|||
|
||||
assert(data);
|
||||
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
/*
|
||||
Find if block is already in queue.
|
||||
|
@ -115,7 +115,7 @@ void MeshUpdateQueue::addBlock(v3s16 p, MeshMakeData *data, bool ack_block_to_se
|
|||
// Returns NULL if queue is empty
|
||||
QueuedMeshUpdate * MeshUpdateQueue::pop()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::list<QueuedMeshUpdate*>::Iterator i = m_queue.begin();
|
||||
if(i == m_queue.end())
|
||||
|
@ -217,7 +217,7 @@ Client::Client(
|
|||
Add local player
|
||||
*/
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
||||
Player *player = new LocalPlayer();
|
||||
|
||||
|
@ -233,7 +233,7 @@ Client::Client(
|
|||
Client::~Client()
|
||||
{
|
||||
{
|
||||
//JMutexAutoLock conlock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock conlock(m_con_mutex); //bulk comment-out
|
||||
m_con.Disconnect();
|
||||
}
|
||||
if (g_settings->getBool("enable_http"))
|
||||
|
@ -245,7 +245,7 @@ Client::~Client()
|
|||
void Client::connect(Address address)
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
m_con.SetTimeoutMs(0);
|
||||
m_con.Connect(address);
|
||||
if (g_settings->getBool("enable_http"))
|
||||
|
@ -254,7 +254,7 @@ void Client::connect(Address address)
|
|||
|
||||
bool Client::connectedAndInitialized()
|
||||
{
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
|
||||
if(m_con.Connected() == false)
|
||||
return false;
|
||||
|
@ -289,7 +289,7 @@ void Client::step(float dtime)
|
|||
{
|
||||
//TimeTaker timer("m_con_mutex + m_con.RunTimeouts()", m_device);
|
||||
// 0ms
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
m_con.RunTimeouts(dtime);
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ void Client::step(float dtime)
|
|||
//counter = 180.0;
|
||||
counter = 60.0;
|
||||
|
||||
//JMutexAutoLock lock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_env_mutex); //bulk comment-out
|
||||
|
||||
core::list<v3s16> deleted_blocks;
|
||||
|
||||
|
@ -358,7 +358,7 @@ void Client::step(float dtime)
|
|||
*/
|
||||
|
||||
// Env is locked so con can be locked.
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
|
||||
core::list<v3s16>::Iterator i = deleted_blocks.begin();
|
||||
core::list<v3s16> sendlist;
|
||||
|
@ -411,7 +411,7 @@ void Client::step(float dtime)
|
|||
{
|
||||
counter = 2.0;
|
||||
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
||||
Player *myplayer = m_env.getLocalPlayer();
|
||||
assert(myplayer != NULL);
|
||||
|
@ -516,7 +516,7 @@ void Client::step(float dtime)
|
|||
*/
|
||||
{
|
||||
// 0ms
|
||||
//JMutexAutoLock lock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_env_mutex); //bulk comment-out
|
||||
|
||||
// Control local player (0ms)
|
||||
LocalPlayer *player = m_env.getLocalPlayer();
|
||||
|
@ -563,7 +563,7 @@ void Client::step(float dtime)
|
|||
if(counter >= 10)
|
||||
{
|
||||
counter = 0.0;
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
// connectedAndInitialized() is true, peer exists.
|
||||
float avg_rtt = m_con.GetPeerAvgRTT(PEER_ID_SERVER);
|
||||
infostream<<"Client: avg_rtt="<<avg_rtt<<std::endl;
|
||||
|
@ -587,7 +587,7 @@ void Client::step(float dtime)
|
|||
Replace updated meshes
|
||||
*/
|
||||
{
|
||||
//JMutexAutoLock lock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_env_mutex); //bulk comment-out
|
||||
|
||||
//TimeTaker timer("** Processing mesh update result queue");
|
||||
// 0ms
|
||||
|
@ -672,7 +672,7 @@ void Client::Receive()
|
|||
u32 datasize;
|
||||
{
|
||||
//TimeTaker t1("con mutex and receive", m_device);
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
datasize = m_con.Receive(sender_peer_id, data);
|
||||
}
|
||||
//TimeTaker t1("ProcessData", m_device);
|
||||
|
@ -741,7 +741,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
v3f playerpos_f = intToFloat(playerpos_s16, BS) - v3f(0, BS/2, 0);
|
||||
|
||||
{ //envlock
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
||||
// Set player position
|
||||
Player *player = m_env.getLocalPlayer();
|
||||
|
@ -927,7 +927,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
<<std::endl;
|
||||
/*u16 our_peer_id;
|
||||
{
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
our_peer_id = m_con.GetPeerID();
|
||||
}
|
||||
// Cancel if we don't have a peer id
|
||||
|
@ -939,7 +939,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
}*/
|
||||
|
||||
{ //envlock
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
||||
u32 player_size = 2+12+12+4+4;
|
||||
|
||||
|
@ -993,7 +993,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
{
|
||||
u16 our_peer_id;
|
||||
{
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
our_peer_id = m_con.GetPeerID();
|
||||
}
|
||||
// Cancel if we don't have a peer id
|
||||
|
@ -1007,7 +1007,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
//infostream<<"Client: Server reports players:"<<std::endl;
|
||||
|
||||
{ //envlock
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
||||
u32 item_size = 2+PLAYERNAME_SIZE;
|
||||
u32 player_count = (datasize-2) / item_size;
|
||||
|
@ -1130,7 +1130,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
//infostream<<"Client received TOCLIENT_SECTORMETA"<<std::endl;
|
||||
|
||||
{ //envlock
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
||||
std::string datastring((char*)&data[2], datasize-2);
|
||||
std::istringstream is(datastring, std::ios_base::binary);
|
||||
|
@ -1165,7 +1165,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
|
||||
{ //envlock
|
||||
//TimeTaker t2("mutex locking", m_device);
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//t2.stop();
|
||||
|
||||
//TimeTaker t3("istringstream init", m_device);
|
||||
|
@ -1345,7 +1345,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
u16 id = readU16((u8*)buf);
|
||||
// Remove it
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
m_env.removeActiveObject(id);
|
||||
}
|
||||
}
|
||||
|
@ -1362,7 +1362,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
std::string data = deSerializeLongString(is);
|
||||
// Add it
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
m_env.addActiveObject(id, type, data);
|
||||
}
|
||||
}
|
||||
|
@ -1405,7 +1405,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
}
|
||||
// Pass on to the environment
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
m_env.processActiveObjectMessage(id, message);
|
||||
}
|
||||
}
|
||||
|
@ -1540,7 +1540,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
|
||||
void Client::Send(u16 channelnum, SharedBuffer<u8> data, bool reliable)
|
||||
{
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
m_con.Send(PEER_ID_SERVER, channelnum, data, reliable);
|
||||
}
|
||||
|
||||
|
@ -1794,7 +1794,7 @@ void Client::sendWantCookie()
|
|||
|
||||
void Client::sendPlayerPos()
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
||||
Player *myplayer = m_env.getLocalPlayer();
|
||||
if(myplayer == NULL)
|
||||
|
@ -1802,7 +1802,7 @@ void Client::sendPlayerPos()
|
|||
|
||||
u16 our_peer_id;
|
||||
{
|
||||
//JMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_con_mutex); //bulk comment-out
|
||||
our_peer_id = m_con.GetPeerID();
|
||||
}
|
||||
|
||||
|
@ -1863,7 +1863,7 @@ void Client::sendPlayerItem(u16 item)
|
|||
|
||||
void Client::removeNode(v3s16 p)
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
||||
core::map<v3s16, MapBlock*> modified_blocks;
|
||||
|
||||
|
@ -1888,7 +1888,7 @@ void Client::removeNode(v3s16 p)
|
|||
|
||||
void Client::addNode(v3s16 p, MapNode n)
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
|
||||
TimeTaker timer1("Client::addNode()");
|
||||
|
||||
|
@ -1927,7 +1927,7 @@ void Client::renderPostFx()
|
|||
|
||||
MapNode Client::getNode(v3s16 p)
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
return m_env.getMap().getNode(p);
|
||||
}
|
||||
|
||||
|
@ -1943,7 +1943,7 @@ LocalPlayer* Client::getLocalPlayer()
|
|||
|
||||
void Client::setPlayerControl(PlayerControl &control)
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
LocalPlayer *player = m_env.getLocalPlayer();
|
||||
assert(player != NULL);
|
||||
player->control = control;
|
||||
|
@ -1964,7 +1964,7 @@ void Client::selectPlayerItem(u16 item)
|
|||
bool Client::getLocalInventoryUpdated()
|
||||
{
|
||||
// m_inventory_updated is behind envlock
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
bool updated = m_inventory_updated;
|
||||
m_inventory_updated = false;
|
||||
return updated;
|
||||
|
@ -1973,7 +1973,7 @@ bool Client::getLocalInventoryUpdated()
|
|||
// Copies the inventory of the local player to parameter
|
||||
void Client::getLocalInventory(Inventory &dst)
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
Player *player = m_env.getLocalPlayer();
|
||||
assert(player != NULL);
|
||||
dst = player->inventory;
|
||||
|
@ -2096,8 +2096,8 @@ ClientActiveObject * Client::getSelectedActiveObject(
|
|||
|
||||
void Client::printDebugInfo(std::ostream &os)
|
||||
{
|
||||
//JMutexAutoLock lock1(m_fetchblock_mutex);
|
||||
/*JMutexAutoLock lock2(m_incoming_queue_mutex);
|
||||
//SimpleMutexAutoLock lock1(m_fetchblock_mutex);
|
||||
/*SimpleMutexAutoLock lock2(m_incoming_queue_mutex);
|
||||
|
||||
os<<"m_incoming_queue.getSize()="<<m_incoming_queue.getSize()
|
||||
//<<", m_fetchblock_history.size()="<<m_fetchblock_history.size()
|
||||
|
@ -2107,7 +2107,7 @@ void Client::printDebugInfo(std::ostream &os)
|
|||
|
||||
u32 Client::getDayNightRatio()
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
return m_env.getDayNightRatio();
|
||||
}
|
||||
|
||||
|
@ -2120,7 +2120,7 @@ u16 Client::getHP()
|
|||
|
||||
void Client::setTempMod(v3s16 p, NodeMod mod)
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
assert(m_env.getMap().mapType() == MAPTYPE_CLIENT);
|
||||
|
||||
core::map<v3s16, MapBlock*> affected_blocks;
|
||||
|
@ -2137,7 +2137,7 @@ void Client::setTempMod(v3s16 p, NodeMod mod)
|
|||
|
||||
void Client::clearTempMod(v3s16 p)
|
||||
{
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
assert(m_env.getMap().mapType() == MAPTYPE_CLIENT);
|
||||
|
||||
core::map<v3s16, MapBlock*> affected_blocks;
|
||||
|
|
|
@ -25,11 +25,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "connection.h"
|
||||
#include "environment.h"
|
||||
#include "common_irrlicht.h"
|
||||
#include "jmutex.h"
|
||||
#include <ostream>
|
||||
#include "clientobject.h"
|
||||
#include "particles.h"
|
||||
#include "utility.h" // For IntervalLimiter
|
||||
#include "threads.h"
|
||||
|
||||
struct MeshMakeData;
|
||||
|
||||
|
@ -72,13 +72,13 @@ public:
|
|||
|
||||
u32 size()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
return m_queue.size();
|
||||
}
|
||||
|
||||
private:
|
||||
core::list<QueuedMeshUpdate*> m_queue;
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
};
|
||||
|
||||
class MapBlockMesh;
|
||||
|
@ -287,7 +287,7 @@ public:
|
|||
return;
|
||||
}
|
||||
|
||||
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex); //bulk comment-out
|
||||
LocalPlayer *player = m_env.getLocalPlayer();
|
||||
assert(player != NULL);
|
||||
std::wstring name = narrow_to_wide(player->getName());
|
||||
|
|
|
@ -543,6 +543,7 @@ Connection::~Connection()
|
|||
|
||||
void * Connection::Thread()
|
||||
{
|
||||
printf("Connection::Thread()\n");
|
||||
log_register_thread("Connection");
|
||||
|
||||
dout_con<<"Connection thread started"<<std::endl;
|
||||
|
@ -565,6 +566,7 @@ void * Connection::Thread()
|
|||
runTimeouts(dtime);
|
||||
|
||||
while(m_command_queue.size() != 0){
|
||||
printf("m_command_queue.size() = %u\n",m_command_queue.size());
|
||||
ConnectionCommand c = m_command_queue.pop_front();
|
||||
processCommand(c);
|
||||
}
|
||||
|
@ -575,6 +577,7 @@ void * Connection::Thread()
|
|||
|
||||
END_DEBUG_EXCEPTION_HANDLER(derr_con);
|
||||
}
|
||||
printf("Connection::Thread() exit\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1563,7 +1566,7 @@ void Connection::Connect(Address address)
|
|||
|
||||
bool Connection::Connected()
|
||||
{
|
||||
JMutexAutoLock peerlock(m_peers_mutex);
|
||||
SimpleMutexAutoLock peerlock(m_peers_mutex);
|
||||
|
||||
if(m_peers.size() != 1)
|
||||
return false;
|
||||
|
@ -1640,13 +1643,13 @@ void Connection::RunTimeouts(float dtime)
|
|||
|
||||
Address Connection::GetPeerAddress(u16 peer_id)
|
||||
{
|
||||
JMutexAutoLock peerlock(m_peers_mutex);
|
||||
SimpleMutexAutoLock peerlock(m_peers_mutex);
|
||||
return getPeer(peer_id)->address;
|
||||
}
|
||||
|
||||
float Connection::GetPeerAvgRTT(u16 peer_id)
|
||||
{
|
||||
JMutexAutoLock peerlock(m_peers_mutex);
|
||||
SimpleMutexAutoLock peerlock(m_peers_mutex);
|
||||
return getPeer(peer_id)->avg_rtt;
|
||||
}
|
||||
|
||||
|
|
|
@ -609,7 +609,7 @@ private:
|
|||
u16 m_peer_id;
|
||||
|
||||
core::map<u16, Peer*> m_peers;
|
||||
JMutex m_peers_mutex;
|
||||
SimpleMutex m_peers_mutex;
|
||||
|
||||
// Backwards compatibility
|
||||
PeerHandler *m_bc_peerhandler;
|
||||
|
|
|
@ -115,16 +115,16 @@ void DebugStack::print(FILE *file, bool everything)
|
|||
|
||||
|
||||
core::map<threadid_t, DebugStack*> g_debug_stacks;
|
||||
JMutex g_debug_stacks_mutex;
|
||||
SimpleMutex g_debug_stacks_mutex;
|
||||
|
||||
void debug_stacks_init()
|
||||
{
|
||||
g_debug_stacks_mutex.Init();
|
||||
g_debug_stacks_mutex.init();
|
||||
}
|
||||
|
||||
void debug_stacks_print()
|
||||
{
|
||||
JMutexAutoLock lock(g_debug_stacks_mutex);
|
||||
SimpleMutexAutoLock lock(g_debug_stacks_mutex);
|
||||
|
||||
DEBUGPRINT("Debug stacks:\n");
|
||||
|
||||
|
@ -146,7 +146,7 @@ DebugStacker::DebugStacker(const char *text)
|
|||
{
|
||||
threadid_t threadid = get_current_thread_id();
|
||||
|
||||
JMutexAutoLock lock(g_debug_stacks_mutex);
|
||||
SimpleMutexAutoLock lock(g_debug_stacks_mutex);
|
||||
|
||||
core::map<threadid_t, DebugStack*>::Node *n;
|
||||
n = g_debug_stacks.find(threadid);
|
||||
|
@ -180,7 +180,7 @@ DebugStacker::DebugStacker(const char *text)
|
|||
|
||||
DebugStacker::~DebugStacker()
|
||||
{
|
||||
JMutexAutoLock lock(g_debug_stacks_mutex);
|
||||
SimpleMutexAutoLock lock(g_debug_stacks_mutex);
|
||||
|
||||
if(m_overflowed == true)
|
||||
return;
|
||||
|
|
|
@ -21,8 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define DEBUG_HEADER
|
||||
|
||||
#include <stdio.h>
|
||||
#include <jmutex.h>
|
||||
#include <jmutexautolock.h>
|
||||
#include <iostream>
|
||||
#include "common_irrlicht.h"
|
||||
#include "threads.h"
|
||||
|
@ -39,8 +37,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#else
|
||||
#endif
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
/*
|
||||
Debug output
|
||||
*/
|
||||
|
@ -129,7 +125,7 @@ extern Nullstream dummyout;
|
|||
Assert
|
||||
*/
|
||||
|
||||
__NORETURN extern void assert_fail(
|
||||
extern void assert_fail(
|
||||
const char *assertion, const char *file,
|
||||
unsigned int line, const char *function);
|
||||
|
||||
|
@ -159,7 +155,7 @@ struct DebugStack
|
|||
};
|
||||
|
||||
extern core::map<threadid_t, DebugStack*> g_debug_stacks;
|
||||
extern JMutex g_debug_stacks_mutex;
|
||||
extern SimpleMutex g_debug_stacks_mutex;
|
||||
|
||||
extern void debug_stacks_init();
|
||||
extern void debug_stacks_print();
|
||||
|
|
34
src/http.cpp
34
src/http.cpp
|
@ -561,7 +561,7 @@ HTTPClient::HTTPClient(Client *client):
|
|||
m_thread(this)
|
||||
{
|
||||
m_client = client;
|
||||
m_req_mutex.Init();
|
||||
m_req_mutex.init();
|
||||
}
|
||||
|
||||
/* destructor */
|
||||
|
@ -613,24 +613,24 @@ void HTTPClient::step()
|
|||
|
||||
std::vector<HTTPRequest> p;
|
||||
|
||||
m_req_mutex.Lock();
|
||||
m_req_mutex.lock();
|
||||
p.swap(m_requests);
|
||||
m_req_mutex.Unlock();
|
||||
m_req_mutex.unlock();
|
||||
|
||||
for (std::vector<HTTPRequest>::iterator i = p.begin(); i != p.end(); ++i) {
|
||||
HTTPRequest q = *i;
|
||||
m_socket = new TCPSocket();
|
||||
if (m_socket == NULL) {
|
||||
m_req_mutex.Lock();
|
||||
m_req_mutex.lock();
|
||||
m_requests.push_back(q);
|
||||
m_req_mutex.Unlock();
|
||||
m_req_mutex.unlock();
|
||||
continue;
|
||||
}
|
||||
if (m_socket->Connect(m_address) == false) {
|
||||
delete m_socket;
|
||||
m_req_mutex.Lock();
|
||||
m_req_mutex.lock();
|
||||
m_requests.push_back(q);
|
||||
m_req_mutex.Unlock();
|
||||
m_req_mutex.unlock();
|
||||
m_connection_failures++;
|
||||
/* assume the server has no http */
|
||||
if (m_connection_failures > 4) {
|
||||
|
@ -657,9 +657,9 @@ void HTTPClient::step()
|
|||
h = m_recv_headers.read(m_socket);
|
||||
if (h == -1 || m_recv_headers.getResponse() == 500) {
|
||||
delete m_socket;
|
||||
m_req_mutex.Lock();
|
||||
m_req_mutex.lock();
|
||||
m_requests.push_back(q);
|
||||
m_req_mutex.Unlock();
|
||||
m_req_mutex.unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -757,9 +757,9 @@ void HTTPClient::pushRequest(HTTPRequestType type, std::string &data)
|
|||
url += data + "/skin";
|
||||
HTTPRequest r(url);
|
||||
r.data = data;
|
||||
m_req_mutex.Lock();
|
||||
m_req_mutex.lock();
|
||||
m_requests.push_back(r);
|
||||
m_req_mutex.Unlock();
|
||||
m_req_mutex.unlock();
|
||||
break;
|
||||
}
|
||||
/*
|
||||
|
@ -795,9 +795,9 @@ void HTTPClient::pushRequest(HTTPRequestType type, std::string &data)
|
|||
url += data + "/skin/hash/" + buff;
|
||||
HTTPRequest r(url);
|
||||
r.data = data;
|
||||
m_req_mutex.Lock();
|
||||
m_req_mutex.lock();
|
||||
m_requests.push_back(r);
|
||||
m_req_mutex.Unlock();
|
||||
m_req_mutex.unlock();
|
||||
break;
|
||||
}
|
||||
/*
|
||||
|
@ -819,9 +819,9 @@ void HTTPClient::pushRequest(HTTPRequestType type, std::string &data)
|
|||
std::string url("/player/");
|
||||
url += data + "/skin";
|
||||
HTTPRequest r(url,ptex,data);
|
||||
m_req_mutex.Lock();
|
||||
m_req_mutex.lock();
|
||||
m_requests.push_back(r);
|
||||
m_req_mutex.Unlock();
|
||||
m_req_mutex.unlock();
|
||||
break;
|
||||
}
|
||||
default:;
|
||||
|
@ -834,9 +834,9 @@ void HTTPClient::pushRequest(std::string &url, std::string &data)
|
|||
if (m_thread.getRun() == false)
|
||||
return;
|
||||
HTTPRequest r(url,data);
|
||||
m_req_mutex.Lock();
|
||||
m_req_mutex.lock();
|
||||
m_requests.push_back(r);
|
||||
m_req_mutex.Unlock();
|
||||
m_req_mutex.unlock();
|
||||
}
|
||||
|
||||
/* send a http GET request to the server */
|
||||
|
|
|
@ -244,7 +244,7 @@ private:
|
|||
HTTPRequestHeaders m_send_headers;
|
||||
std::string m_cookie;
|
||||
std::vector<HTTPRequest> m_requests;
|
||||
JMutex m_req_mutex;
|
||||
SimpleMutex m_req_mutex;
|
||||
HTTPClientThread m_thread;
|
||||
Client *m_client;
|
||||
int m_connection_failures;
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
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})
|
||||
|
||||
target_link_libraries(
|
||||
jthread
|
||||
${jthread_platform_LIBS}
|
||||
)
|
||||
|
||||
|
||||
configure_file("${PROJECT_SOURCE_DIR}/jthread/jthreadconfig.h.in"
|
||||
"${PROJECT_BINARY_DIR}/jthread/jthreadconfig.h")
|
|
@ -1,20 +0,0 @@
|
|||
The license of JThread:
|
||||
|
||||
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.
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
|
||||
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 JTHREAD_JMUTEX_H
|
||||
|
||||
#define JTHREAD_JMUTEX_H
|
||||
|
||||
#include "jthreadconfig.h"
|
||||
#ifdef JTHREAD_CONFIG_WIN32THREADS
|
||||
#ifndef _WIN32_WCE
|
||||
#include <process.h>
|
||||
#endif // _WIN32_WCE
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#else // using pthread
|
||||
#include <pthread.h>
|
||||
#endif // JTHREAD_CONFIG_WIN32THREADS
|
||||
|
||||
#define ERR_JMUTEX_ALREADYINIT -1
|
||||
#define ERR_JMUTEX_NOTINIT -2
|
||||
#define ERR_JMUTEX_CANTCREATEMUTEX -3
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
class JTHREAD_IMPORTEXPORT JMutex
|
||||
{
|
||||
public:
|
||||
JMutex();
|
||||
~JMutex();
|
||||
int Init();
|
||||
int Lock();
|
||||
int Unlock();
|
||||
bool IsInitialized() { return initialized; }
|
||||
private:
|
||||
#ifdef JTHREAD_CONFIG_WIN32THREADS
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
CRITICAL_SECTION mutex;
|
||||
#else // Use standard mutex
|
||||
HANDLE mutex;
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
#else // pthread mutex
|
||||
pthread_mutex_t mutex;
|
||||
#endif // JTHREAD_CONFIG_WIN32THREADS
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // JTHREAD_JMUTEX_H
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
|
||||
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 JTHREAD_JMUTEXAUTOLOCK_H
|
||||
|
||||
#define JTHREAD_JMUTEXAUTOLOCK_H
|
||||
|
||||
#include "jthreadconfig.h"
|
||||
#include "jmutex.h"
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
class JTHREAD_IMPORTEXPORT JMutexAutoLock
|
||||
{
|
||||
public:
|
||||
JMutexAutoLock(JMutex &m) : mutex(m) { mutex.Lock(); }
|
||||
~JMutexAutoLock() { mutex.Unlock(); }
|
||||
private:
|
||||
JMutex &mutex;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // JTHREAD_JMUTEXAUTOLOCK_H
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
|
||||
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 JTHREAD_JTHREAD_H
|
||||
|
||||
#define JTHREAD_JTHREAD_H
|
||||
|
||||
#include "jthreadconfig.h"
|
||||
#include "jmutex.h"
|
||||
|
||||
#define ERR_JTHREAD_CANTINITMUTEX -1
|
||||
#define ERR_JTHREAD_CANTSTARTTHREAD -2
|
||||
#define ERR_JTHREAD_THREADFUNCNOTSET -3
|
||||
#define ERR_JTHREAD_NOTRUNNING -4
|
||||
#define ERR_JTHREAD_ALREADYRUNNING -5
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
class JTHREAD_IMPORTEXPORT JThread
|
||||
{
|
||||
public:
|
||||
JThread();
|
||||
virtual ~JThread();
|
||||
int Start();
|
||||
int Kill();
|
||||
virtual void *Thread() = 0;
|
||||
bool IsRunning();
|
||||
void *GetReturnValue();
|
||||
protected:
|
||||
void ThreadStarted();
|
||||
private:
|
||||
|
||||
#ifdef JTHREAD_CONFIG_WIN32THREADS
|
||||
#ifdef _WIN32_WCE
|
||||
DWORD threadid;
|
||||
static DWORD WINAPI TheThread(void *param);
|
||||
#else
|
||||
static UINT __stdcall TheThread(void *param);
|
||||
UINT threadid;
|
||||
#endif // _WIN32_WCE
|
||||
HANDLE threadhandle;
|
||||
#else // pthread type threads
|
||||
static void *TheThread(void *param);
|
||||
|
||||
pthread_t threadid;
|
||||
#endif // JTHREAD_CONFIG_WIN32THREADS
|
||||
void *retval;
|
||||
bool running;
|
||||
|
||||
JMutex runningmutex;
|
||||
JMutex continuemutex,continuemutex2;
|
||||
bool mutexinit;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // JTHREAD_JTHREAD_H
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
|
||||
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
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#include "jmutex.h"
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
JMutex::JMutex()
|
||||
{
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
JMutex::~JMutex()
|
||||
{
|
||||
if (initialized)
|
||||
pthread_mutex_destroy(&mutex);
|
||||
}
|
||||
|
||||
int JMutex::Init()
|
||||
{
|
||||
if (initialized)
|
||||
return ERR_JMUTEX_ALREADYINIT;
|
||||
|
||||
pthread_mutex_init(&mutex,NULL);
|
||||
initialized = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JMutex::Lock()
|
||||
{
|
||||
if (!initialized)
|
||||
return ERR_JMUTEX_NOTINIT;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JMutex::Unlock()
|
||||
{
|
||||
if (!initialized)
|
||||
return ERR_JMUTEX_NOTINIT;
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#include "jthread.h"
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
JThread::JThread()
|
||||
{
|
||||
retval = NULL;
|
||||
mutexinit = false;
|
||||
running = false;
|
||||
}
|
||||
|
||||
JThread::~JThread()
|
||||
{
|
||||
Kill();
|
||||
}
|
||||
|
||||
int JThread::Start()
|
||||
{
|
||||
int status;
|
||||
|
||||
if (!mutexinit)
|
||||
{
|
||||
if (!runningmutex.IsInitialized())
|
||||
{
|
||||
if (runningmutex.Init() < 0)
|
||||
return ERR_JTHREAD_CANTINITMUTEX;
|
||||
}
|
||||
if (!continuemutex.IsInitialized())
|
||||
{
|
||||
if (continuemutex.Init() < 0)
|
||||
return ERR_JTHREAD_CANTINITMUTEX;
|
||||
}
|
||||
if (!continuemutex2.IsInitialized())
|
||||
{
|
||||
if (continuemutex2.Init() < 0)
|
||||
return ERR_JTHREAD_CANTINITMUTEX;
|
||||
}
|
||||
mutexinit = true;
|
||||
}
|
||||
|
||||
runningmutex.Lock();
|
||||
if (running)
|
||||
{
|
||||
runningmutex.Unlock();
|
||||
return ERR_JTHREAD_ALREADYRUNNING;
|
||||
}
|
||||
runningmutex.Unlock();
|
||||
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
|
||||
|
||||
continuemutex.Lock();
|
||||
status = pthread_create(&threadid,&attr,TheThread,this);
|
||||
pthread_attr_destroy(&attr);
|
||||
if (status != 0)
|
||||
{
|
||||
continuemutex.Unlock();
|
||||
return ERR_JTHREAD_CANTSTARTTHREAD;
|
||||
}
|
||||
|
||||
/* Wait until 'running' is set */
|
||||
|
||||
runningmutex.Lock();
|
||||
while (!running)
|
||||
{
|
||||
runningmutex.Unlock();
|
||||
|
||||
struct timespec req,rem;
|
||||
|
||||
req.tv_sec = 0;
|
||||
req.tv_nsec = 1000000;
|
||||
nanosleep(&req,&rem);
|
||||
|
||||
runningmutex.Lock();
|
||||
}
|
||||
runningmutex.Unlock();
|
||||
|
||||
continuemutex.Unlock();
|
||||
|
||||
continuemutex2.Lock();
|
||||
continuemutex2.Unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JThread::Kill()
|
||||
{
|
||||
runningmutex.Lock();
|
||||
if (!running)
|
||||
{
|
||||
runningmutex.Unlock();
|
||||
return ERR_JTHREAD_NOTRUNNING;
|
||||
}
|
||||
pthread_cancel(threadid);
|
||||
running = false;
|
||||
runningmutex.Unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool JThread::IsRunning()
|
||||
{
|
||||
bool r;
|
||||
|
||||
runningmutex.Lock();
|
||||
r = running;
|
||||
runningmutex.Unlock();
|
||||
return r;
|
||||
}
|
||||
|
||||
void *JThread::GetReturnValue()
|
||||
{
|
||||
void *val;
|
||||
|
||||
runningmutex.Lock();
|
||||
if (running)
|
||||
val = NULL;
|
||||
else
|
||||
val = retval;
|
||||
runningmutex.Unlock();
|
||||
return val;
|
||||
}
|
||||
|
||||
void *JThread::TheThread(void *param)
|
||||
{
|
||||
JThread *jthread;
|
||||
void *ret;
|
||||
|
||||
jthread = (JThread *)param;
|
||||
|
||||
jthread->continuemutex2.Lock();
|
||||
jthread->runningmutex.Lock();
|
||||
jthread->running = true;
|
||||
jthread->runningmutex.Unlock();
|
||||
|
||||
jthread->continuemutex.Lock();
|
||||
jthread->continuemutex.Unlock();
|
||||
|
||||
ret = jthread->Thread();
|
||||
|
||||
jthread->runningmutex.Lock();
|
||||
jthread->running = false;
|
||||
jthread->retval = ret;
|
||||
jthread->runningmutex.Unlock();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void JThread::ThreadStarted()
|
||||
{
|
||||
continuemutex2.Unlock();
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#include "jmutex.h"
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
JMutex::JMutex()
|
||||
{
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
JMutex::~JMutex()
|
||||
{
|
||||
if (initialized)
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
DeleteCriticalSection(&mutex);
|
||||
#else
|
||||
CloseHandle(mutex);
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
}
|
||||
|
||||
int JMutex::Init()
|
||||
{
|
||||
if (initialized)
|
||||
return ERR_JMUTEX_ALREADYINIT;
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
InitializeCriticalSection(&mutex);
|
||||
#else
|
||||
mutex = CreateMutex(NULL,FALSE,NULL);
|
||||
if (mutex == NULL)
|
||||
return ERR_JMUTEX_CANTCREATEMUTEX;
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
initialized = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JMutex::Lock()
|
||||
{
|
||||
if (!initialized)
|
||||
return ERR_JMUTEX_NOTINIT;
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
EnterCriticalSection(&mutex);
|
||||
#else
|
||||
WaitForSingleObject(mutex,INFINITE);
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JMutex::Unlock()
|
||||
{
|
||||
if (!initialized)
|
||||
return ERR_JMUTEX_NOTINIT;
|
||||
#ifdef JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
LeaveCriticalSection(&mutex);
|
||||
#else
|
||||
ReleaseMutex(mutex);
|
||||
#endif // JTHREAD_CONFIG_JMUTEXCRITICALSECTION
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // end namespace
|
|
@ -1,182 +0,0 @@
|
|||
/*
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#include "jthread.h"
|
||||
#include "jmutexautolock.h"
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
#include <process.h>
|
||||
#endif // _WIN32_WCE
|
||||
|
||||
namespace jthread
|
||||
{
|
||||
|
||||
JThread::JThread()
|
||||
{
|
||||
retval = NULL;
|
||||
mutexinit = false;
|
||||
running = false;
|
||||
}
|
||||
|
||||
JThread::~JThread()
|
||||
{
|
||||
Kill();
|
||||
}
|
||||
|
||||
int JThread::Start()
|
||||
{
|
||||
if (!mutexinit)
|
||||
{
|
||||
if (!runningmutex.IsInitialized())
|
||||
{
|
||||
if (runningmutex.Init() < 0)
|
||||
return ERR_JTHREAD_CANTINITMUTEX;
|
||||
}
|
||||
if (!continuemutex.IsInitialized())
|
||||
{
|
||||
if (continuemutex.Init() < 0)
|
||||
return ERR_JTHREAD_CANTINITMUTEX;
|
||||
}
|
||||
if (!continuemutex2.IsInitialized())
|
||||
{
|
||||
if (continuemutex2.Init() < 0)
|
||||
return ERR_JTHREAD_CANTINITMUTEX;
|
||||
} mutexinit = true;
|
||||
}
|
||||
|
||||
runningmutex.Lock();
|
||||
if (running)
|
||||
{
|
||||
runningmutex.Unlock();
|
||||
return ERR_JTHREAD_ALREADYRUNNING;
|
||||
}
|
||||
runningmutex.Unlock();
|
||||
|
||||
continuemutex.Lock();
|
||||
#ifndef _WIN32_WCE
|
||||
threadhandle = (HANDLE)_beginthreadex(NULL,0,TheThread,this,0,&threadid);
|
||||
#else
|
||||
threadhandle = CreateThread(NULL,0,TheThread,this,0,&threadid);
|
||||
#endif // _WIN32_WCE
|
||||
if (threadhandle == NULL)
|
||||
{
|
||||
continuemutex.Unlock();
|
||||
return ERR_JTHREAD_CANTSTARTTHREAD;
|
||||
}
|
||||
|
||||
/* Wait until 'running' is set */
|
||||
|
||||
runningmutex.Lock();
|
||||
while (!running)
|
||||
{
|
||||
runningmutex.Unlock();
|
||||
Sleep(1);
|
||||
runningmutex.Lock();
|
||||
}
|
||||
runningmutex.Unlock();
|
||||
|
||||
continuemutex.Unlock();
|
||||
|
||||
continuemutex2.Lock();
|
||||
continuemutex2.Unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int JThread::Kill()
|
||||
{
|
||||
runningmutex.Lock();
|
||||
if (!running)
|
||||
{
|
||||
runningmutex.Unlock();
|
||||
return ERR_JTHREAD_NOTRUNNING;
|
||||
}
|
||||
TerminateThread(threadhandle,0);
|
||||
CloseHandle(threadhandle);
|
||||
running = false;
|
||||
runningmutex.Unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool JThread::IsRunning()
|
||||
{
|
||||
bool r;
|
||||
|
||||
runningmutex.Lock();
|
||||
r = running;
|
||||
runningmutex.Unlock();
|
||||
return r;
|
||||
}
|
||||
|
||||
void *JThread::GetReturnValue()
|
||||
{
|
||||
JMutexAutoLock autolock(runningmutex);
|
||||
void *val;
|
||||
|
||||
if (running)
|
||||
val = NULL;
|
||||
else
|
||||
val = retval;
|
||||
return val;
|
||||
}
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
UINT __stdcall JThread::TheThread(void *param)
|
||||
#else
|
||||
DWORD WINAPI JThread::TheThread(void *param)
|
||||
#endif // _WIN32_WCE
|
||||
{
|
||||
JThread *jthread;
|
||||
void *ret;
|
||||
|
||||
jthread = (JThread *)param;
|
||||
|
||||
jthread->continuemutex2.Lock();
|
||||
jthread->runningmutex.Lock();
|
||||
jthread->running = true;
|
||||
jthread->runningmutex.Unlock();
|
||||
|
||||
jthread->continuemutex.Lock();
|
||||
jthread->continuemutex.Unlock();
|
||||
|
||||
ret = jthread->Thread();
|
||||
|
||||
jthread->runningmutex.Lock();
|
||||
jthread->running = false;
|
||||
jthread->retval = ret;
|
||||
CloseHandle(jthread->threadhandle);
|
||||
jthread->runningmutex.Unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void JThread::ThreadStarted()
|
||||
{
|
||||
continuemutex2.Unlock();
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
|
@ -1013,15 +1013,15 @@ void SpeedTests()
|
|||
dstream<<"Around 5000/ms should do well here."<<std::endl;
|
||||
TimeTaker timer("Testing mutex speed");
|
||||
|
||||
JMutex m;
|
||||
m.Init();
|
||||
SimpleMutex m;
|
||||
m.init();
|
||||
u32 n = 0;
|
||||
u32 i = 0;
|
||||
do{
|
||||
n += 10000;
|
||||
for(; i<n; i++){
|
||||
m.Lock();
|
||||
m.Unlock();
|
||||
m.lock();
|
||||
m.unlock();
|
||||
}
|
||||
}
|
||||
// Do at least 10ms
|
||||
|
|
30
src/map.cpp
30
src/map.cpp
|
@ -2742,12 +2742,13 @@ std::string ServerMap::getSectorDir(v2s16 pos, int layout)
|
|||
default:
|
||||
assert(false);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
v2s16 ServerMap::getSectorPos(std::string dirname)
|
||||
{
|
||||
unsigned int x, y;
|
||||
int r;
|
||||
int r = 0;
|
||||
size_t spos = dirname.rfind(DIR_DELIM_C) + 1;
|
||||
assert(spos != std::string::npos);
|
||||
if(dirname.size() - spos == 8)
|
||||
|
@ -3503,8 +3504,7 @@ ClientMap::ClientMap(
|
|||
m_camera_direction(0,0,1),
|
||||
m_camera_fov(PI)
|
||||
{
|
||||
m_camera_mutex.Init();
|
||||
assert(m_camera_mutex.IsInitialized());
|
||||
m_camera_mutex.init();
|
||||
|
||||
m_box = core::aabbox3d<f32>(-BS*1000000,-BS*1000000,-BS*1000000,
|
||||
BS*1000000,BS*1000000,BS*1000000);
|
||||
|
@ -3512,7 +3512,7 @@ ClientMap::ClientMap(
|
|||
|
||||
ClientMap::~ClientMap()
|
||||
{
|
||||
/*JMutexAutoLock lock(mesh_mutex);
|
||||
/*SimpleMutexAutoLock lock(mesh_mutex);
|
||||
|
||||
if(mesh != NULL)
|
||||
{
|
||||
|
@ -3536,7 +3536,7 @@ MapSector * ClientMap::emergeSector(v2s16 p2d)
|
|||
ClientMapSector *sector = new ClientMapSector(this, p2d);
|
||||
|
||||
{
|
||||
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
|
||||
m_sectors.insert(p2d, sector);
|
||||
}
|
||||
|
||||
|
@ -3549,7 +3549,7 @@ void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is)
|
|||
DSTACK(__FUNCTION_NAME);
|
||||
ClientMapSector *sector = NULL;
|
||||
|
||||
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
|
||||
|
||||
core::map<v2s16, MapSector*>::Node *n = m_sectors.find(p2d);
|
||||
|
||||
|
@ -3562,7 +3562,7 @@ void ClientMap::deSerializeSector(v2s16 p2d, std::istream &is)
|
|||
{
|
||||
sector = new ClientMapSector(this, p2d);
|
||||
{
|
||||
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
|
||||
//SimpleMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
|
||||
m_sectors.insert(p2d, sector);
|
||||
}
|
||||
}
|
||||
|
@ -3646,12 +3646,12 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||
|
||||
//u32 daynight_ratio = m_client->getDayNightRatio();
|
||||
|
||||
m_camera_mutex.Lock();
|
||||
m_camera_mutex.lock();
|
||||
v3f camera_position = m_camera_position;
|
||||
v3f camera_direction = m_camera_direction;
|
||||
f32 camera_fov = m_camera_fov;
|
||||
v3s16 camera_offset = m_camera_offset;
|
||||
m_camera_mutex.Unlock();
|
||||
m_camera_mutex.unlock();
|
||||
|
||||
/*
|
||||
Get all blocks and draw all visible ones
|
||||
|
@ -3774,7 +3774,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||
bool mesh_expired = false;
|
||||
|
||||
{
|
||||
JMutexAutoLock lock(block->mesh_mutex);
|
||||
SimpleMutexAutoLock lock(block->mesh_mutex);
|
||||
|
||||
mesh_expired = block->getMeshExpired();
|
||||
|
||||
|
@ -3859,7 +3859,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||
Ignore if mesh doesn't exist
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock lock(block->mesh_mutex);
|
||||
SimpleMutexAutoLock lock(block->mesh_mutex);
|
||||
|
||||
MapBlockMesh *mesh = block->mesh;
|
||||
|
||||
|
@ -3923,7 +3923,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||
Draw the faces of the block
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock lock(block->mesh_mutex);
|
||||
SimpleMutexAutoLock lock(block->mesh_mutex);
|
||||
|
||||
MapBlockMesh *mesh = block->mesh;
|
||||
assert(mesh);
|
||||
|
@ -4001,9 +4001,9 @@ void ClientMap::renderPostFx()
|
|||
// Sadly ISceneManager has no "post effects" render pass, in that case we
|
||||
// could just register for that and handle it in renderMap().
|
||||
|
||||
m_camera_mutex.Lock();
|
||||
m_camera_mutex.lock();
|
||||
v3f camera_position = m_camera_position;
|
||||
m_camera_mutex.Unlock();
|
||||
m_camera_mutex.unlock();
|
||||
|
||||
MapNode n = getNodeNoEx(floatToInt(camera_position, BS));
|
||||
|
||||
|
@ -4140,7 +4140,7 @@ void ClientMap::expireMeshes(bool only_daynight_diffed)
|
|||
}
|
||||
|
||||
{
|
||||
JMutexAutoLock lock(block->mesh_mutex);
|
||||
SimpleMutexAutoLock lock(block->mesh_mutex);
|
||||
if(block->mesh != NULL)
|
||||
{
|
||||
/*block->mesh->drop();
|
||||
|
|
13
src/map.h
13
src/map.h
|
@ -20,9 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#ifndef MAP_HEADER
|
||||
#define MAP_HEADER
|
||||
|
||||
#include <jmutex.h>
|
||||
#include <jmutexautolock.h>
|
||||
#include <jthread.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -31,13 +28,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "mapblock_nodemod.h"
|
||||
#include "constants.h"
|
||||
#include "voxel.h"
|
||||
#include "porting.h"
|
||||
#include "threads.h"
|
||||
|
||||
extern "C" {
|
||||
#include "sqlite3.h"
|
||||
}
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
class MapSector;
|
||||
class ServerMapSector;
|
||||
class ClientMapSector;
|
||||
|
@ -531,7 +528,7 @@ public:
|
|||
|
||||
void updateCamera(v3f pos, v3f dir, f32 fov, v3s16 offset)
|
||||
{
|
||||
JMutexAutoLock lock(m_camera_mutex);
|
||||
SimpleMutexAutoLock lock(m_camera_mutex);
|
||||
m_camera_position = pos;
|
||||
m_camera_direction = dir;
|
||||
m_camera_fov = fov;
|
||||
|
@ -610,7 +607,7 @@ private:
|
|||
|
||||
// This is the master heightmap mesh
|
||||
//scene::SMesh *mesh;
|
||||
//JMutex mesh_mutex;
|
||||
//SimpleMutex mesh_mutex;
|
||||
|
||||
MapDrawControl &m_control;
|
||||
|
||||
|
@ -618,7 +615,7 @@ private:
|
|||
v3f m_camera_direction;
|
||||
f32 m_camera_fov;
|
||||
v3s16 m_camera_offset;
|
||||
JMutex m_camera_mutex;
|
||||
SimpleMutex m_camera_mutex;
|
||||
|
||||
core::map<v2s16, bool> m_last_drawn_sectors;
|
||||
};
|
||||
|
|
|
@ -47,9 +47,9 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, bool dummy):
|
|||
|
||||
#ifndef SERVER
|
||||
m_mesh_expired = false;
|
||||
mesh_mutex.Init();
|
||||
mesh_mutex.init();
|
||||
mesh = NULL;
|
||||
m_temp_mods_mutex.Init();
|
||||
m_temp_mods_mutex.init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ MapBlock::~MapBlock()
|
|||
{
|
||||
#ifndef SERVER
|
||||
{
|
||||
JMutexAutoLock lock(mesh_mutex);
|
||||
SimpleMutexAutoLock lock(mesh_mutex);
|
||||
|
||||
if(mesh)
|
||||
{
|
||||
|
@ -142,7 +142,7 @@ void MapBlock::updateMesh(u32 daynight_ratio, Environment *env, v3s16 camera_off
|
|||
DEBUG: If mesh has been generated, don't generate it again
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock meshlock(mesh_mutex);
|
||||
SimpleMutexAutoLock meshlock(mesh_mutex);
|
||||
if(mesh != NULL)
|
||||
return;
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ void MapBlock::updateMesh(u32 daynight_ratio, Environment *env, v3s16 camera_off
|
|||
|
||||
void MapBlock::replaceMesh(MapBlockMesh *mesh_new)
|
||||
{
|
||||
mesh_mutex.Lock();
|
||||
mesh_mutex.lock();
|
||||
|
||||
//scene::SMesh *mesh_old = mesh[daynight_i];
|
||||
//mesh[daynight_i] = mesh_new;
|
||||
|
@ -202,7 +202,7 @@ void MapBlock::replaceMesh(MapBlockMesh *mesh_new)
|
|||
delete mesh_old;
|
||||
}
|
||||
|
||||
mesh_mutex.Unlock();
|
||||
mesh_mutex.unlock();
|
||||
}
|
||||
|
||||
#endif // !SERVER
|
||||
|
|
|
@ -20,8 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#ifndef MAPBLOCK_HEADER
|
||||
#define MAPBLOCK_HEADER
|
||||
|
||||
#include <jmutex.h>
|
||||
#include <jmutexautolock.h>
|
||||
#include <exception>
|
||||
#include "debug.h"
|
||||
#include "common_irrlicht.h"
|
||||
|
@ -33,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "nodemetadata.h"
|
||||
#include "staticobject.h"
|
||||
#include "mapblock_nodemod.h"
|
||||
#include "threads.h"
|
||||
#ifndef SERVER
|
||||
#include "mapblock_mesh.h"
|
||||
#endif
|
||||
|
@ -436,32 +435,32 @@ public:
|
|||
<<", mod.type="<<mod.type
|
||||
<<", mod.param="<<mod.param
|
||||
<<std::endl;*/
|
||||
JMutexAutoLock lock(m_temp_mods_mutex);
|
||||
SimpleMutexAutoLock lock(m_temp_mods_mutex);
|
||||
|
||||
return m_temp_mods.set(p, mod);
|
||||
}
|
||||
// Returns true if there was one
|
||||
bool getTempMod(v3s16 p, NodeMod *mod)
|
||||
{
|
||||
JMutexAutoLock lock(m_temp_mods_mutex);
|
||||
SimpleMutexAutoLock lock(m_temp_mods_mutex);
|
||||
|
||||
return m_temp_mods.get(p, mod);
|
||||
}
|
||||
bool clearTempMod(v3s16 p)
|
||||
{
|
||||
JMutexAutoLock lock(m_temp_mods_mutex);
|
||||
SimpleMutexAutoLock lock(m_temp_mods_mutex);
|
||||
|
||||
return m_temp_mods.clear(p);
|
||||
}
|
||||
bool clearTempMods()
|
||||
{
|
||||
JMutexAutoLock lock(m_temp_mods_mutex);
|
||||
SimpleMutexAutoLock lock(m_temp_mods_mutex);
|
||||
|
||||
return m_temp_mods.clear();
|
||||
}
|
||||
void copyTempMods(NodeModMap &dst)
|
||||
{
|
||||
JMutexAutoLock lock(m_temp_mods_mutex);
|
||||
SimpleMutexAutoLock lock(m_temp_mods_mutex);
|
||||
m_temp_mods.copy(dst);
|
||||
}
|
||||
#endif
|
||||
|
@ -572,7 +571,7 @@ public:
|
|||
|
||||
#ifndef SERVER // Only on client
|
||||
MapBlockMesh *mesh;
|
||||
JMutex mesh_mutex;
|
||||
SimpleMutex mesh_mutex;
|
||||
#endif
|
||||
|
||||
NodeMetadataList m_node_metadata;
|
||||
|
@ -636,7 +635,7 @@ private:
|
|||
// Temporary modifications to nodes
|
||||
// These are only used when drawing
|
||||
NodeModMap m_temp_mods;
|
||||
JMutex m_temp_mods_mutex;
|
||||
SimpleMutex m_temp_mods_mutex;
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
|
@ -18,7 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
*/
|
||||
|
||||
#include "mapsector.h"
|
||||
#include "jmutexautolock.h"
|
||||
#include "client.h"
|
||||
#include "exceptions.h"
|
||||
#include "mapblock.h"
|
||||
|
|
|
@ -24,10 +24,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#ifndef MAPSECTOR_HEADER
|
||||
#define MAPSECTOR_HEADER
|
||||
|
||||
#include <jmutex.h>
|
||||
#include "common_irrlicht.h"
|
||||
#include "exceptions.h"
|
||||
#include <ostream>
|
||||
#include "porting.h"
|
||||
#include "threads.h"
|
||||
|
||||
class MapBlock;
|
||||
class Map;
|
||||
|
|
|
@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <string>
|
||||
// Included for u32 and such
|
||||
#include "common_irrlicht.h"
|
||||
#include "debug.h"
|
||||
#include "constants.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -45,6 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
# include <signal.h>
|
||||
# define sleep_ms(x) usleep(x*1000)
|
||||
#endif
|
||||
#include "debug.h"
|
||||
|
||||
namespace porting
|
||||
{
|
||||
|
|
|
@ -23,8 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "common_irrlicht.h"
|
||||
#include <string>
|
||||
#include "utility.h"
|
||||
#include <jmutex.h>
|
||||
#include <jmutexautolock.h>
|
||||
#include "threads.h"
|
||||
|
||||
/*
|
||||
Time profiler
|
||||
|
@ -35,12 +34,12 @@ class Profiler
|
|||
public:
|
||||
Profiler()
|
||||
{
|
||||
m_mutex.Init();
|
||||
m_mutex.init();
|
||||
}
|
||||
|
||||
void add(const std::string &name, float value)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
{
|
||||
/* No average shall have been used; mark add used as -2 */
|
||||
core::map<std::string, int>::Node *n = m_avgcounts.find(name);
|
||||
|
@ -63,7 +62,7 @@ public:
|
|||
|
||||
void avg(const std::string &name, float value)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
{
|
||||
core::map<std::string, int>::Node *n = m_avgcounts.find(name);
|
||||
if(n == NULL)
|
||||
|
@ -88,7 +87,7 @@ public:
|
|||
|
||||
void clear()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
for(core::map<std::string, float>::Iterator
|
||||
i = m_data.getIterator();
|
||||
i.atEnd() == false; i++)
|
||||
|
@ -105,8 +104,8 @@ public:
|
|||
|
||||
void printPage(std::ostream &o, u32 page, u32 pagecount)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
u32 minindex, maxindex;
|
||||
paging(m_data.size(), page, pagecount, minindex, maxindex);
|
||||
|
||||
|
@ -147,7 +146,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
core::map<std::string, float> m_data;
|
||||
core::map<std::string, int> m_avgcounts;
|
||||
};
|
||||
|
|
|
@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <iostream>
|
||||
#include "clientserver.h"
|
||||
#include "map.h"
|
||||
#include "jmutexautolock.h"
|
||||
#include "main.h"
|
||||
#include "constants.h"
|
||||
#include "voxel.h"
|
||||
|
@ -41,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "profiler.h"
|
||||
#include "log.h"
|
||||
#include "base64.h"
|
||||
#include "threads.h"
|
||||
|
||||
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
||||
|
||||
|
@ -73,6 +73,7 @@ private:
|
|||
|
||||
void * ServerThread::Thread()
|
||||
{
|
||||
printf("ServerThread::Thread()\n");
|
||||
log_register_thread("ServerThread");
|
||||
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
@ -103,12 +104,13 @@ void * ServerThread::Thread()
|
|||
|
||||
END_DEBUG_EXCEPTION_HANDLER(errorstream)
|
||||
|
||||
printf("ServerThread::Thread() exit\n");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void * EmergeThread::Thread()
|
||||
{
|
||||
printf("EmergeThread::Thread()\n");
|
||||
log_register_thread("EmergeThread");
|
||||
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
@ -197,7 +199,7 @@ printf("EmergeThread::Thread()\n");
|
|||
Fetch block from map or generate a single block
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock envlock(m_server->m_env_mutex);
|
||||
SimpleMutexAutoLock envlock(m_server->m_env_mutex);
|
||||
|
||||
// Load sector if it isn't loaded
|
||||
if(map.getSectorNoGenerateNoEx(p2d) == NULL)
|
||||
|
@ -264,7 +266,7 @@ printf("EmergeThread::Thread()\n");
|
|||
}
|
||||
|
||||
{//envlock
|
||||
JMutexAutoLock envlock(m_server->m_env_mutex);
|
||||
SimpleMutexAutoLock envlock(m_server->m_env_mutex);
|
||||
|
||||
if(got_block)
|
||||
{
|
||||
|
@ -309,7 +311,7 @@ printf("EmergeThread::Thread()\n");
|
|||
*/
|
||||
|
||||
// NOTE: Server's clients are also behind the connection mutex
|
||||
JMutexAutoLock lock(m_server->m_con_mutex);
|
||||
SimpleMutexAutoLock lock(m_server->m_con_mutex);
|
||||
|
||||
/*
|
||||
Add the originally fetched block to the modified list
|
||||
|
@ -968,9 +970,9 @@ Server::Server(
|
|||
m_emergethread_trigger_timer = 0.0;
|
||||
m_savemap_timer = 0.0;
|
||||
|
||||
m_env_mutex.Init();
|
||||
m_con_mutex.Init();
|
||||
m_step_dtime_mutex.Init();
|
||||
m_env_mutex.init();
|
||||
m_con_mutex.init();
|
||||
m_step_dtime_mutex.init();
|
||||
m_step_dtime = 0.0;
|
||||
|
||||
// Register us to receive map edit events
|
||||
|
@ -996,7 +998,7 @@ Server::~Server()
|
|||
Send shutdown message
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock conlock(m_con_mutex);
|
||||
SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
|
||||
std::wstring line = L"*** Server shutting down";
|
||||
|
||||
|
@ -1022,7 +1024,7 @@ Server::~Server()
|
|||
}
|
||||
|
||||
{
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
|
||||
/*
|
||||
Save players
|
||||
|
@ -1046,7 +1048,7 @@ Server::~Server()
|
|||
Delete clients
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock clientslock(m_con_mutex);
|
||||
SimpleMutexAutoLock clientslock(m_con_mutex);
|
||||
|
||||
for(core::map<u16, RemoteClient*>::Iterator
|
||||
i = m_clients.getIterator();
|
||||
|
@ -1056,7 +1058,7 @@ Server::~Server()
|
|||
// NOTE: These are removed by env destructor
|
||||
{
|
||||
u16 peer_id = i.getNode()->getKey();
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
m_env.removePlayer(peer_id);
|
||||
}*/
|
||||
|
||||
|
@ -1075,8 +1077,10 @@ void Server::start(unsigned short port)
|
|||
// Initialize connection
|
||||
m_con.SetTimeoutMs(30);
|
||||
m_con.Serve(port);
|
||||
if (!m_con.getRun())
|
||||
if (!m_con.getRun()) {
|
||||
printf("no con run\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Start thread
|
||||
m_thread.start();
|
||||
|
@ -1106,7 +1110,7 @@ bool Server::step(float dtime)
|
|||
if(dtime > 2.0)
|
||||
dtime = 2.0;
|
||||
{
|
||||
JMutexAutoLock lock(m_step_dtime_mutex);
|
||||
SimpleMutexAutoLock lock(m_step_dtime_mutex);
|
||||
m_step_dtime += dtime;
|
||||
}
|
||||
return true;
|
||||
|
@ -1120,7 +1124,7 @@ void Server::AsyncRunStep()
|
|||
|
||||
float dtime;
|
||||
{
|
||||
JMutexAutoLock lock1(m_step_dtime_mutex);
|
||||
SimpleMutexAutoLock lock1(m_step_dtime_mutex);
|
||||
dtime = m_step_dtime;
|
||||
}
|
||||
|
||||
|
@ -1139,7 +1143,7 @@ void Server::AsyncRunStep()
|
|||
//infostream<<"Server::AsyncRunStep(): dtime="<<dtime<<std::endl;
|
||||
|
||||
{
|
||||
JMutexAutoLock lock1(m_step_dtime_mutex);
|
||||
SimpleMutexAutoLock lock1(m_step_dtime_mutex);
|
||||
m_step_dtime -= dtime;
|
||||
}
|
||||
|
||||
|
@ -1152,7 +1156,7 @@ void Server::AsyncRunStep()
|
|||
|
||||
{
|
||||
// Process connection's timeouts
|
||||
JMutexAutoLock lock2(m_con_mutex);
|
||||
SimpleMutexAutoLock lock2(m_con_mutex);
|
||||
ScopeProfiler sp(g_profiler, "Server: connection timeout processing");
|
||||
m_con.RunTimeouts(dtime);
|
||||
}
|
||||
|
@ -1167,7 +1171,7 @@ void Server::AsyncRunStep()
|
|||
Update m_time_of_day and overall game time
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
|
||||
m_time_counter += dtime;
|
||||
f32 speed = g_settings->getFloat("time_speed") * 24000./(24.*3600);
|
||||
|
@ -1187,8 +1191,8 @@ void Server::AsyncRunStep()
|
|||
{
|
||||
m_time_of_day_send_timer = g_settings->getFloat("time_send_interval");
|
||||
|
||||
//JMutexAutoLock envlock(m_env_mutex);
|
||||
JMutexAutoLock conlock(m_con_mutex);
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
|
||||
for(core::map<u16, RemoteClient*>::Iterator
|
||||
i = m_clients.getIterator();
|
||||
|
@ -1206,7 +1210,7 @@ void Server::AsyncRunStep()
|
|||
}
|
||||
|
||||
{
|
||||
JMutexAutoLock lock(m_env_mutex);
|
||||
SimpleMutexAutoLock lock(m_env_mutex);
|
||||
// Step environment
|
||||
ScopeProfiler sp(g_profiler, "SEnv step");
|
||||
ScopeProfiler sp2(g_profiler, "SEnv step avg", SPT_AVG);
|
||||
|
@ -1216,7 +1220,7 @@ void Server::AsyncRunStep()
|
|||
const float map_timer_and_unload_dtime = 2.92;
|
||||
if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime))
|
||||
{
|
||||
JMutexAutoLock lock(m_env_mutex);
|
||||
SimpleMutexAutoLock lock(m_env_mutex);
|
||||
// Run Map's timers and unload unused data
|
||||
ScopeProfiler sp(g_profiler, "Server: map timer and unload");
|
||||
m_env.getMap().timerUpdate(map_timer_and_unload_dtime,
|
||||
|
@ -1235,7 +1239,7 @@ void Server::AsyncRunStep()
|
|||
{
|
||||
m_liquid_transform_timer -= 1.00;
|
||||
|
||||
JMutexAutoLock lock(m_env_mutex);
|
||||
SimpleMutexAutoLock lock(m_env_mutex);
|
||||
|
||||
ScopeProfiler sp(g_profiler, "Server: liquid transform");
|
||||
|
||||
|
@ -1262,7 +1266,7 @@ void Server::AsyncRunStep()
|
|||
Set the modified blocks unsent for all the clients
|
||||
*/
|
||||
|
||||
JMutexAutoLock lock2(m_con_mutex);
|
||||
SimpleMutexAutoLock lock2(m_con_mutex);
|
||||
|
||||
for(core::map<u16, RemoteClient*>::Iterator
|
||||
i = m_clients.getIterator();
|
||||
|
@ -1286,7 +1290,7 @@ void Server::AsyncRunStep()
|
|||
{
|
||||
counter = 0.0;
|
||||
|
||||
JMutexAutoLock lock2(m_con_mutex);
|
||||
SimpleMutexAutoLock lock2(m_con_mutex);
|
||||
|
||||
if(m_clients.size() != 0)
|
||||
infostream<<"Players:"<<std::endl;
|
||||
|
@ -1313,8 +1317,8 @@ void Server::AsyncRunStep()
|
|||
*/
|
||||
{
|
||||
//infostream<<"Server: Checking added and deleted active objects"<<std::endl;
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
JMutexAutoLock conlock(m_con_mutex);
|
||||
SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
|
||||
ScopeProfiler sp(g_profiler, "Server: checking added and deleted objs");
|
||||
|
||||
|
@ -1462,8 +1466,8 @@ void Server::AsyncRunStep()
|
|||
Send object messages
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
JMutexAutoLock conlock(m_con_mutex);
|
||||
SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
|
||||
//ScopeProfiler sp(g_profiler, "Server: sending object messages");
|
||||
|
||||
|
@ -1702,8 +1706,8 @@ void Server::AsyncRunStep()
|
|||
counter += dtime;
|
||||
if(counter >= g_settings->getFloat("objectdata_interval"))
|
||||
{
|
||||
JMutexAutoLock lock1(m_env_mutex);
|
||||
JMutexAutoLock lock2(m_con_mutex);
|
||||
SimpleMutexAutoLock lock1(m_env_mutex);
|
||||
SimpleMutexAutoLock lock2(m_con_mutex);
|
||||
|
||||
//ScopeProfiler sp(g_profiler, "Server: sending player positions");
|
||||
|
||||
|
@ -1747,7 +1751,7 @@ void Server::AsyncRunStep()
|
|||
m_banmanager.save();
|
||||
|
||||
// Map
|
||||
JMutexAutoLock lock(m_env_mutex);
|
||||
SimpleMutexAutoLock lock(m_env_mutex);
|
||||
|
||||
/*// Unload unused data (delete from memory)
|
||||
m_env.getMap().unloadUnusedData(
|
||||
|
@ -1783,7 +1787,7 @@ void Server::Receive()
|
|||
u32 datasize;
|
||||
try{
|
||||
{
|
||||
JMutexAutoLock conlock(m_con_mutex);
|
||||
SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
datasize = m_con.Receive(peer_id, data);
|
||||
}
|
||||
|
||||
|
@ -1806,7 +1810,7 @@ void Server::Receive()
|
|||
// The peer has been disconnected.
|
||||
// Find the associated player and remove it.
|
||||
|
||||
/*JMutexAutoLock envlock(m_env_mutex);
|
||||
/*SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
|
||||
infostream<<"ServerThread: peer_id="<<peer_id
|
||||
<<" has apparently closed connection. "
|
||||
|
@ -1820,8 +1824,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
// Environment is locked first.
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
JMutexAutoLock conlock(m_con_mutex);
|
||||
SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
|
||||
try{
|
||||
Address address = m_con.GetPeerAddress(peer_id);
|
||||
|
@ -2777,7 +2781,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
SendPlayerAnim(player,PLAYERANIM_STAND);
|
||||
#if 0
|
||||
RemoteClient *client = getClient(peer_id);
|
||||
JMutexAutoLock digmutex(client->m_dig_mutex);
|
||||
SimpleMutexAutoLock digmutex(client->m_dig_mutex);
|
||||
client->m_dig_tool_item = -1;
|
||||
#endif
|
||||
}
|
||||
|
@ -4500,8 +4504,8 @@ void Server::inventoryModified(InventoryContext *c, std::string id)
|
|||
core::list<PlayerInfo> Server::getPlayerInfo()
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
JMutexAutoLock conlock(m_con_mutex);
|
||||
SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
|
||||
core::list<PlayerInfo> list;
|
||||
|
||||
|
@ -4646,7 +4650,7 @@ void Server::SendPlayerInfos()
|
|||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
||||
//JMutexAutoLock envlock(m_env_mutex);
|
||||
//SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
|
||||
// Get connected players
|
||||
core::list<Player*> players = m_env.getPlayers(true);
|
||||
|
@ -4673,7 +4677,7 @@ void Server::SendPlayerInfos()
|
|||
start += 2+PLAYERNAME_SIZE;
|
||||
}
|
||||
|
||||
//JMutexAutoLock conlock(m_con_mutex);
|
||||
//SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
|
||||
// Send as reliable
|
||||
m_con.SendToAll(0, data, true);
|
||||
|
@ -5040,8 +5044,8 @@ void Server::SendBlocks(float dtime)
|
|||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
JMutexAutoLock conlock(m_con_mutex);
|
||||
SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
|
||||
//TimeTaker timer("Server::SendBlocks");
|
||||
|
||||
|
@ -5193,7 +5197,7 @@ void Server::UpdateCrafting(u16 peer_id)
|
|||
RemoteClient* Server::getClient(u16 peer_id)
|
||||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
//JMutexAutoLock lock(m_con_mutex);
|
||||
//SimpleMutexAutoLock lock(m_con_mutex);
|
||||
core::map<u16, RemoteClient*>::Node *n;
|
||||
n = m_clients.find(peer_id);
|
||||
// A client should exist for all peers
|
||||
|
@ -5414,8 +5418,8 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id
|
|||
|
||||
void Server::handlePeerChange(PeerChange &c)
|
||||
{
|
||||
JMutexAutoLock envlock(m_env_mutex);
|
||||
JMutexAutoLock conlock(m_con_mutex);
|
||||
SimpleMutexAutoLock envlock(m_env_mutex);
|
||||
SimpleMutexAutoLock conlock(m_con_mutex);
|
||||
|
||||
if(c.type == PEER_ADDED)
|
||||
{
|
||||
|
|
22
src/server.h
22
src/server.h
|
@ -54,12 +54,12 @@ class BlockEmergeQueue
|
|||
public:
|
||||
BlockEmergeQueue()
|
||||
{
|
||||
m_mutex.Init();
|
||||
m_mutex.init();
|
||||
}
|
||||
|
||||
~BlockEmergeQueue()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::list<QueuedBlockEmerge*>::Iterator i;
|
||||
for(i=m_queue.begin(); i!=m_queue.end(); i++)
|
||||
|
@ -76,7 +76,7 @@ public:
|
|||
{
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
if(peer_id != 0)
|
||||
{
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
// Returns NULL if queue is empty
|
||||
QueuedBlockEmerge * pop()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::list<QueuedBlockEmerge*>::Iterator i = m_queue.begin();
|
||||
if(i == m_queue.end())
|
||||
|
@ -122,13 +122,13 @@ public:
|
|||
|
||||
u32 size()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
return m_queue.size();
|
||||
}
|
||||
|
||||
u32 peerItemCount(u16 peer_id)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
u32 count = 0;
|
||||
|
||||
|
@ -145,7 +145,7 @@ public:
|
|||
|
||||
private:
|
||||
core::list<QueuedBlockEmerge*> m_queue;
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
};
|
||||
|
||||
class Server;
|
||||
|
@ -304,7 +304,7 @@ public:
|
|||
// Time from last placing or removing blocks
|
||||
float m_time_from_building;
|
||||
|
||||
/*JMutex m_dig_mutex;
|
||||
/*SimpleMutex m_dig_mutex;
|
||||
float m_dig_time_remaining;
|
||||
// -1 = not digging
|
||||
s16 m_dig_tool_item;
|
||||
|
@ -604,11 +604,11 @@ private:
|
|||
|
||||
// Environment
|
||||
ServerEnvironment m_env;
|
||||
JMutex m_env_mutex;
|
||||
SimpleMutex m_env_mutex;
|
||||
|
||||
// Connection
|
||||
con::Connection m_con;
|
||||
JMutex m_con_mutex;
|
||||
SimpleMutex m_con_mutex;
|
||||
// Connected clients (behind the con mutex)
|
||||
core::map<u16, RemoteClient*> m_clients;
|
||||
|
||||
|
@ -625,7 +625,7 @@ private:
|
|||
// A buffer for time steps
|
||||
// step() increments and AsyncRunStep() run by m_thread reads it.
|
||||
float m_step_dtime;
|
||||
JMutex m_step_dtime_mutex;
|
||||
SimpleMutex m_step_dtime_mutex;
|
||||
|
||||
// The server mainly operates in this thread
|
||||
ServerThread m_thread;
|
||||
|
|
|
@ -52,7 +52,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <time.h>
|
||||
#include <jmutexautolock.h>
|
||||
#include <locale.h>
|
||||
#include "common_irrlicht.h"
|
||||
#include "debug.h"
|
||||
|
@ -78,6 +77,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "content_craftitem.h"
|
||||
#include "content_toolitem.h"
|
||||
#include "http.h"
|
||||
#include "threads.h"
|
||||
|
||||
/*
|
||||
Settings.
|
||||
|
|
|
@ -22,9 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "common_irrlicht.h"
|
||||
#include <string>
|
||||
#include <jthread.h>
|
||||
#include <jmutex.h>
|
||||
#include <jmutexautolock.h>
|
||||
#include "strfnd.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
@ -32,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "debug.h"
|
||||
#include "utility.h"
|
||||
#include "log.h"
|
||||
#include "threads.h"
|
||||
|
||||
enum ValueType
|
||||
{
|
||||
|
@ -50,19 +48,17 @@ struct ValueSpec
|
|||
const char *help;
|
||||
};
|
||||
|
||||
using namespace jthread;
|
||||
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
Settings()
|
||||
{
|
||||
m_mutex.Init();
|
||||
m_mutex.init();
|
||||
}
|
||||
|
||||
void writeLines(std::ostream &os)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
for(core::map<std::string, std::string>::Iterator
|
||||
i = m_settings.getIterator();
|
||||
|
@ -76,7 +72,7 @@ public:
|
|||
|
||||
bool parseConfigLine(const std::string &line)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
std::string trimmedline = trim(line);
|
||||
|
||||
|
@ -176,7 +172,7 @@ public:
|
|||
core::list<std::string> &dst,
|
||||
core::map<std::string, bool> &updated)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
if(is.eof())
|
||||
return false;
|
||||
|
@ -260,7 +256,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
// Write stuff back
|
||||
{
|
||||
|
@ -368,14 +364,14 @@ public:
|
|||
|
||||
void set(std::string name, std::string value)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
m_settings[name] = value;
|
||||
}
|
||||
|
||||
void set(std::string name, const char *value)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
m_settings[name] = value;
|
||||
}
|
||||
|
@ -383,21 +379,21 @@ public:
|
|||
|
||||
void setDefault(std::string name, std::string value)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
m_defaults[name] = value;
|
||||
}
|
||||
|
||||
bool exists(std::string name)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
return (m_settings.find(name) || m_defaults.find(name));
|
||||
}
|
||||
|
||||
std::string get(std::string name)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
core::map<std::string, std::string>::Node *n;
|
||||
n = m_settings.find(name);
|
||||
|
@ -560,7 +556,7 @@ public:
|
|||
|
||||
void clear()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
m_settings.clear();
|
||||
m_defaults.clear();
|
||||
|
@ -568,7 +564,7 @@ public:
|
|||
|
||||
void updateValue(Settings &other, const std::string &name)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
if(&other == this)
|
||||
return;
|
||||
|
@ -584,8 +580,8 @@ public:
|
|||
|
||||
void update(Settings &other)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
JMutexAutoLock lock2(other.m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock2(other.m_mutex);
|
||||
|
||||
if(&other == this)
|
||||
return;
|
||||
|
@ -609,8 +605,8 @@ public:
|
|||
|
||||
Settings & operator+=(Settings &other)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
JMutexAutoLock lock2(other.m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock2(other.m_mutex);
|
||||
|
||||
if(&other == this)
|
||||
return *this;
|
||||
|
@ -637,8 +633,8 @@ public:
|
|||
|
||||
Settings & operator=(Settings &other)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
JMutexAutoLock lock2(other.m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock2(other.m_mutex);
|
||||
|
||||
if(&other == this)
|
||||
return *this;
|
||||
|
@ -653,7 +649,7 @@ private:
|
|||
core::map<std::string, std::string> m_settings;
|
||||
core::map<std::string, std::string> m_defaults;
|
||||
// All methods that access m_settings/m_defaults directly should lock this.
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
226
src/threads.h
226
src/threads.h
|
@ -20,8 +20,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#ifndef THREADS_HEADER
|
||||
#define THREADS_HEADER
|
||||
|
||||
#include <jmutex.h>
|
||||
|
||||
#if (defined(WIN32) || defined(_WIN32_WCE))
|
||||
typedef DWORD threadid_t;
|
||||
#define __NORETURN __declspec(noreturn)
|
||||
|
@ -32,6 +30,10 @@ typedef pthread_t threadid_t;
|
|||
#define __FUNCTION_NAME __PRETTY_FUNCTION__
|
||||
#endif
|
||||
|
||||
class SimpleMutex;
|
||||
class SimpleThread;
|
||||
|
||||
#include "porting.h"
|
||||
inline threadid_t get_current_thread_id()
|
||||
{
|
||||
#if (defined(WIN32) || defined(_WIN32_WCE))
|
||||
|
@ -41,5 +43,225 @@ inline threadid_t get_current_thread_id()
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
A simple mutex implementation
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
class SimpleMutex
|
||||
{
|
||||
CRITICAL_SECTION mut;
|
||||
|
||||
public:
|
||||
|
||||
SimpleMutex()
|
||||
{
|
||||
InitializeCriticalSection(&mut);
|
||||
}
|
||||
|
||||
~SimpleMutex()
|
||||
{
|
||||
unlock();
|
||||
DeleteCriticalSection(&mut);
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
InitializeCriticalSection(&mut);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
EnterCriticalSection(&mut);
|
||||
}
|
||||
|
||||
bool trylock()
|
||||
{
|
||||
if (!TryEnterCriticalSection(&mut))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
LeaveCriticalSection(&mut);
|
||||
}
|
||||
};
|
||||
#else
|
||||
class SimpleMutex
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutex_t mut;
|
||||
|
||||
public:
|
||||
|
||||
SimpleMutex()
|
||||
{
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&mut, &attr);
|
||||
}
|
||||
|
||||
~SimpleMutex()
|
||||
{
|
||||
unlock();
|
||||
pthread_mutex_destroy(&mut);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&mut, &attr);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
pthread_mutex_lock(&mut);
|
||||
}
|
||||
|
||||
int trylock()
|
||||
{
|
||||
if (pthread_mutex_trylock(&mut))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
pthread_mutex_unlock(&mut);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
class SimpleMutexAutoLock
|
||||
{
|
||||
SimpleMutex &mutex;
|
||||
|
||||
public:
|
||||
SimpleMutexAutoLock(SimpleMutex &m):
|
||||
mutex(m)
|
||||
{
|
||||
mutex.lock();
|
||||
}
|
||||
|
||||
~SimpleMutexAutoLock()
|
||||
{
|
||||
mutex.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
A base class for simple background thread implementation
|
||||
*/
|
||||
class SimpleThread
|
||||
{
|
||||
bool run;
|
||||
SimpleMutex run_mutex;
|
||||
#ifdef _WIN32
|
||||
HANDLE thread;
|
||||
#else
|
||||
pthread_t thread;
|
||||
pthread_attr_t attr;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
SimpleThread():
|
||||
run(false),
|
||||
run_mutex()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~SimpleThread()
|
||||
{
|
||||
kill();
|
||||
}
|
||||
|
||||
virtual void * Thread() = 0;
|
||||
|
||||
bool getRun()
|
||||
{
|
||||
run_mutex.lock();
|
||||
bool r = run;
|
||||
run_mutex.unlock();
|
||||
return r;
|
||||
}
|
||||
void setRun(bool a_run)
|
||||
{
|
||||
run_mutex.lock();
|
||||
run = a_run;
|
||||
run_mutex.unlock();
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
if (getRun()) {
|
||||
#ifdef _WIN32
|
||||
ResumeThread(thread);
|
||||
#else
|
||||
pthread_kill(thread,SIGCONT);
|
||||
#endif
|
||||
}else{
|
||||
setRun(true);
|
||||
#ifdef _WIN32
|
||||
thread = CreateThread(NULL, 0, &runThread, this, 0, NULL);
|
||||
#else
|
||||
pthread_create(&thread, &attr, &runThread, this);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void wait()
|
||||
{
|
||||
if (getRun()) {
|
||||
#ifdef _WIN32
|
||||
WaitForSingleObject(thread, 2000);
|
||||
CloseHandle(thread);
|
||||
#else
|
||||
pthread_join(thread,NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
setRun(false);
|
||||
wait();
|
||||
}
|
||||
|
||||
void kill()
|
||||
{
|
||||
if (getRun()) {
|
||||
setRun(false);
|
||||
#ifdef _WIN32
|
||||
TerminateThread(thread,0);
|
||||
CloseHandle(thread);
|
||||
#else
|
||||
pthread_kill(thread,SIGKILL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static void *runThread(void* data)
|
||||
{
|
||||
SimpleThread *t = (SimpleThread*)data;
|
||||
void *r = t->Thread();
|
||||
t->setRun(false);
|
||||
#ifdef _WIN32
|
||||
ExitThread(0);
|
||||
CloseHandle(t->thread);
|
||||
#else
|
||||
pthread_exit(r);
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
16
src/tile.cpp
16
src/tile.cpp
|
@ -41,7 +41,7 @@ TextureSource::TextureSource(IrrlichtDevice *device):
|
|||
{
|
||||
assert(m_device);
|
||||
|
||||
m_atlaspointer_cache_mutex.Init();
|
||||
m_atlaspointer_cache_mutex.init();
|
||||
|
||||
m_main_thread = get_current_thread_id();
|
||||
|
||||
|
@ -93,7 +93,7 @@ u32 TextureSource::getTextureId(const std::string &name)
|
|||
/*
|
||||
See if texture already exists
|
||||
*/
|
||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
SimpleMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
core::map<std::string, u32>::Node *n;
|
||||
n = m_name_to_id.find(name);
|
||||
if(n != NULL)
|
||||
|
@ -192,7 +192,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||
See if texture already exists
|
||||
*/
|
||||
{
|
||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
SimpleMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
|
||||
core::map<std::string, u32>::Node *n;
|
||||
n = m_name_to_id.find(name);
|
||||
|
@ -260,7 +260,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||
// If a base image was found, copy it to baseimg
|
||||
if(base_image_id != 0)
|
||||
{
|
||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
SimpleMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
|
||||
SourceAtlasPointer ap = m_atlaspointer_cache[base_image_id];
|
||||
|
||||
|
@ -326,7 +326,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||
Add texture to caches (add NULL textures too)
|
||||
*/
|
||||
|
||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
SimpleMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
|
||||
u32 id = m_atlaspointer_cache.size();
|
||||
AtlasPointer ap(id);
|
||||
|
@ -349,7 +349,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||
|
||||
std::string TextureSource::getTextureName(u32 id)
|
||||
{
|
||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
SimpleMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
|
||||
if(id >= m_atlaspointer_cache.size())
|
||||
{
|
||||
|
@ -365,7 +365,7 @@ std::string TextureSource::getTextureName(u32 id)
|
|||
|
||||
AtlasPointer TextureSource::getTexture(u32 id)
|
||||
{
|
||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
SimpleMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
|
||||
if(id >= m_atlaspointer_cache.size())
|
||||
return AtlasPointer(0, NULL);
|
||||
|
@ -382,7 +382,7 @@ void TextureSource::buildMainAtlas()
|
|||
video::IVideoDriver* driver = m_device->getVideoDriver();
|
||||
assert(driver);
|
||||
|
||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
SimpleMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||
|
||||
// Create an image of the right size
|
||||
core::dimension2d<u32> atlas_dim(4096,4096);
|
||||
|
|
|
@ -25,8 +25,6 @@ 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.
|
||||
*/
|
||||
|
@ -248,7 +246,7 @@ private:
|
|||
// Maps a texture name to an index in the former.
|
||||
core::map<std::string, u32> m_name_to_id;
|
||||
// The two former containers are behind this mutex
|
||||
JMutex m_atlaspointer_cache_mutex;
|
||||
SimpleMutex m_atlaspointer_cache_mutex;
|
||||
|
||||
// Main texture atlas. This is filled at startup and is then not touched.
|
||||
video::IImage *m_main_atlas_image;
|
||||
|
|
256
src/utility.h
256
src/utility.h
|
@ -25,9 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <jthread.h>
|
||||
#include <jmutex.h>
|
||||
#include <jmutexautolock.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "common_irrlicht.h"
|
||||
|
@ -35,8 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "strfnd.h"
|
||||
#include "exceptions.h"
|
||||
#include "porting.h"
|
||||
|
||||
using namespace jthread;
|
||||
#include "threads.h"
|
||||
|
||||
extern const v3s16 g_6dirs[6];
|
||||
|
||||
|
@ -545,32 +541,32 @@ public:
|
|||
MutexedVariable(T value):
|
||||
m_value(value)
|
||||
{
|
||||
m_mutex.Init();
|
||||
m_mutex.init();
|
||||
}
|
||||
|
||||
T get()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void set(T value)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
// You'll want to grab this in a SharedPtr
|
||||
JMutexAutoLock * getLock()
|
||||
SimpleMutex *getLock()
|
||||
{
|
||||
return new JMutexAutoLock(m_mutex);
|
||||
return new SimpleMutexAutoLock(m_mutex);
|
||||
}
|
||||
|
||||
// You pretty surely want to grab the lock when accessing this
|
||||
T m_value;
|
||||
|
||||
private:
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -972,197 +968,6 @@ inline void str_replace_char(std::string & str, char from, char to)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
A simple mutex implementation
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
class SimpleMutex
|
||||
{
|
||||
CRITICAL_SECTION mut;
|
||||
|
||||
public:
|
||||
|
||||
SimpleMutex()
|
||||
{
|
||||
InitializeCriticalSection(&mut);
|
||||
}
|
||||
|
||||
~SimpleMutex()
|
||||
{
|
||||
unlock();
|
||||
DeleteCriticalSection(&mut);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
EnterCriticalSection(&mut);
|
||||
}
|
||||
|
||||
bool trylock()
|
||||
{
|
||||
if (!TryEnterCriticalSection(&mut))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
LeaveCriticalSection(&mut);
|
||||
}
|
||||
};
|
||||
#else
|
||||
class SimpleMutex
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutex_t mut;
|
||||
|
||||
public:
|
||||
|
||||
SimpleMutex()
|
||||
{
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&mut, &attr);
|
||||
}
|
||||
|
||||
~SimpleMutex()
|
||||
{
|
||||
unlock();
|
||||
pthread_mutex_destroy(&mut);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
pthread_mutex_lock(&mut);
|
||||
}
|
||||
|
||||
int trylock()
|
||||
{
|
||||
if (pthread_mutex_trylock(&mut))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
pthread_mutex_unlock(&mut);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
A base class for simple background thread implementation
|
||||
*/
|
||||
class SimpleThread
|
||||
{
|
||||
bool run;
|
||||
SimpleMutex run_mutex;
|
||||
#ifdef _WIN32
|
||||
HANDLE thread;
|
||||
#else
|
||||
pthread_t thread;
|
||||
pthread_attr_t attr;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
SimpleThread():
|
||||
run(false),
|
||||
run_mutex()
|
||||
{
|
||||
#ifndef _WIN32
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~SimpleThread()
|
||||
{
|
||||
kill();
|
||||
}
|
||||
|
||||
virtual void * Thread() = 0;
|
||||
|
||||
bool getRun()
|
||||
{
|
||||
run_mutex.lock();
|
||||
bool r = run;
|
||||
run_mutex.unlock();
|
||||
return r;
|
||||
}
|
||||
void setRun(bool a_run)
|
||||
{
|
||||
run_mutex.lock();
|
||||
run = a_run;
|
||||
run_mutex.unlock();
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
if (getRun()) {
|
||||
#ifdef _WIN32
|
||||
ResumeThread(thread);
|
||||
#else
|
||||
pthread_kill(thread,SIGCONT);
|
||||
#endif
|
||||
}else{
|
||||
setRun(true);
|
||||
#ifdef _WIN32
|
||||
thread = CreateThread(NULL, 0, &runThread, this, 0, NULL);
|
||||
#else
|
||||
pthread_create(&thread, &attr, &runThread, this);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void wait()
|
||||
{
|
||||
if (getRun()) {
|
||||
#ifdef _WIN32
|
||||
WaitForSingleObject(thread, 2000);
|
||||
CloseHandle(thread);
|
||||
#else
|
||||
pthread_join(thread,NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
setRun(false);
|
||||
wait();
|
||||
}
|
||||
|
||||
void kill()
|
||||
{
|
||||
if (getRun()) {
|
||||
setRun(false);
|
||||
#ifdef _WIN32
|
||||
TerminateThread(thread,0);
|
||||
CloseHandle(thread);
|
||||
#else
|
||||
pthread_kill(thread,SIGKILL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static void *runThread(void* data)
|
||||
{
|
||||
SimpleThread *t = (SimpleThread*)data;
|
||||
void *r = t->Thread();
|
||||
t->setRun(false);
|
||||
#ifdef _WIN32
|
||||
ExitThread(0);
|
||||
CloseHandle(t->thread);
|
||||
#else
|
||||
pthread_exit(r);
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
FIFO queue (well, actually a FILO also)
|
||||
*/
|
||||
|
@ -1215,16 +1020,16 @@ class MutexedQueue
|
|||
public:
|
||||
MutexedQueue()
|
||||
{
|
||||
m_mutex.Init();
|
||||
m_mutex.init();
|
||||
}
|
||||
u32 size()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
return m_list.size();
|
||||
}
|
||||
void push_back(T t)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
m_list.push_back(t);
|
||||
}
|
||||
T pop_front(u32 wait_time_max_ms=0)
|
||||
|
@ -1234,7 +1039,7 @@ public:
|
|||
for(;;)
|
||||
{
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
if(m_list.size() > 0)
|
||||
{
|
||||
|
@ -1244,7 +1049,7 @@ public:
|
|||
return t;
|
||||
}
|
||||
|
||||
if(wait_time_ms >= wait_time_max_ms)
|
||||
if (wait_time_ms >= wait_time_max_ms)
|
||||
throw ItemNotFoundException("MutexedQueue: queue is empty");
|
||||
}
|
||||
|
||||
|
@ -1260,7 +1065,7 @@ public:
|
|||
for(;;)
|
||||
{
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
if(m_list.size() > 0)
|
||||
{
|
||||
|
@ -1280,7 +1085,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
JMutex & getMutex()
|
||||
SimpleMutex & getMutex()
|
||||
{
|
||||
return m_mutex;
|
||||
}
|
||||
|
@ -1291,7 +1096,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
core::list<T> m_list;
|
||||
};
|
||||
|
||||
|
@ -1360,7 +1165,7 @@ public:
|
|||
void add(Key key, Caller caller, CallerData callerdata,
|
||||
ResultQueue<Key, T, Caller, CallerData> *dest)
|
||||
{
|
||||
JMutexAutoLock lock(m_queue.getMutex());
|
||||
SimpleMutexAutoLock lock(m_queue.getMutex());
|
||||
|
||||
/*
|
||||
If the caller is already on the list, only update CallerData
|
||||
|
@ -1487,28 +1292,26 @@ class MutexedMap
|
|||
public:
|
||||
MutexedMap()
|
||||
{
|
||||
m_mutex.Init();
|
||||
assert(m_mutex.IsInitialized());
|
||||
m_mutex.init();
|
||||
}
|
||||
|
||||
void set(const Key &name, const Value &value)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
m_values[name] = value;
|
||||
}
|
||||
|
||||
bool get(const Key &name, Value *result)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock lock(m_mutex);
|
||||
|
||||
typename core::map<Key, Value>::Node *n;
|
||||
n = m_values.find(name);
|
||||
|
||||
if(n == NULL)
|
||||
if (n == NULL)
|
||||
return false;
|
||||
|
||||
if(result != NULL)
|
||||
if (result != NULL)
|
||||
*result = n->getValue();
|
||||
|
||||
return true;
|
||||
|
@ -1516,7 +1319,7 @@ public:
|
|||
|
||||
private:
|
||||
core::map<Key, Value> m_values;
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -1538,17 +1341,16 @@ class MutexedIdGenerator
|
|||
public:
|
||||
MutexedIdGenerator()
|
||||
{
|
||||
m_mutex.Init();
|
||||
assert(m_mutex.IsInitialized());
|
||||
m_mutex.init();
|
||||
}
|
||||
|
||||
// Returns true if found
|
||||
bool getValue(u32 id, T &value)
|
||||
{
|
||||
if(id == 0)
|
||||
if (id == 0)
|
||||
return false;
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
if(m_id_to_value.size() < id)
|
||||
SimpleMutexAutoLock(m_mutex);
|
||||
if (m_id_to_value.size() < id)
|
||||
return false;
|
||||
value = m_id_to_value[id-1];
|
||||
return true;
|
||||
|
@ -1558,10 +1360,10 @@ public:
|
|||
// Otherwise generates an id for the value.
|
||||
u32 getId(const T &value)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
SimpleMutexAutoLock(m_mutex);
|
||||
typename core::map<T, u32>::Node *n;
|
||||
n = m_value_to_id.find(value);
|
||||
if(n != NULL)
|
||||
if (n != NULL)
|
||||
return n->getValue();
|
||||
m_id_to_value.push_back(value);
|
||||
u32 new_id = m_id_to_value.size();
|
||||
|
@ -1570,7 +1372,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
JMutex m_mutex;
|
||||
SimpleMutex m_mutex;
|
||||
// Values are stored here at id-1 position (id 1 = [0])
|
||||
core::array<T> m_id_to_value;
|
||||
core::map<T, u32> m_value_to_id;
|
||||
|
|
Loading…
Reference in New Issue