11 changes: 6 additions & 5 deletions src/jthread/pthread/jsemaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,27 @@ You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <assert.h>
#include "jthread/jsemaphore.h"

JSemaphore::JSemaphore() {
sem_init(&m_semaphore,0,0);
assert(sem_init(&m_semaphore,0,0) == 0);
}

JSemaphore::~JSemaphore() {
sem_destroy(&m_semaphore);
assert(sem_destroy(&m_semaphore) == 0);
}

JSemaphore::JSemaphore(int initval) {
sem_init(&m_semaphore,0,initval);
assert(sem_init(&m_semaphore,0,initval) == 0);
}

void JSemaphore::Post() {
sem_post(&m_semaphore);
assert(sem_post(&m_semaphore) == 0);
}

void JSemaphore::Wait() {
sem_wait(&m_semaphore);
assert(sem_wait(&m_semaphore) == 0);
}

int JSemaphore::GetValue() {
Expand Down
21 changes: 0 additions & 21 deletions src/jthread/pthread/jthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
JThread::JThread()
{
retval = NULL;
mutexinit = false;
requeststop = false;
running = false;
}
Expand All @@ -53,26 +52,6 @@ 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)
{
Expand Down
43 changes: 43 additions & 0 deletions src/jthread/win32/jevent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
This file is a part of the JThread package, which contains some object-
oriented thread wrappers for different thread implementations.
Copyright (c) 2000-2006 Jori Liesenborgs (jori.liesenborgs@gmail.com)
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/jevent.h"

Event::Event() {
hEvent = CreateEvent(NULL, 0, 0, NULL);
}

Event::~Event() {
CloseHandle(hEvent);
}

void Event::wait() {
WaitForSingleObject(hEvent, INFINITE);
}

void Event::signal() {
SetEvent(hEvent);
}
20 changes: 4 additions & 16 deletions src/jthread/win32/jmutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
DEALINGS IN THE SOFTWARE.
*/

#include <assert.h>
#include "jthread/jmutex.h"

JMutex::JMutex()
Expand All @@ -33,31 +33,21 @@ JMutex::JMutex()
InitializeCriticalSection(&mutex);
#else
mutex = CreateMutex(NULL,FALSE,NULL);
if (mutex == NULL)
return ERR_JMUTEX_CANTCREATEMUTEX;
assert(mutex != NULL);
#endif // JMUTEX_CRITICALSECTION
initialized = true;
}

JMutex::~JMutex()
{
if (initialized)
#ifdef JMUTEX_CRITICALSECTION
DeleteCriticalSection(&mutex);
DeleteCriticalSection(&mutex);
#else
CloseHandle(mutex);
CloseHandle(mutex);
#endif // JMUTEX_CRITICALSECTION
}

int JMutex::Init()
{
return 0;
}

int JMutex::Lock()
{
if (!initialized)
return ERR_JMUTEX_NOTINIT;
#ifdef JMUTEX_CRITICALSECTION
EnterCriticalSection(&mutex);
#else
Expand All @@ -68,8 +58,6 @@ int JMutex::Lock()

int JMutex::Unlock()
{
if (!initialized)
return ERR_JMUTEX_NOTINIT;
#ifdef JMUTEX_CRITICALSECTION
LeaveCriticalSection(&mutex);
#else
Expand Down
20 changes: 0 additions & 20 deletions src/jthread/win32/jthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
JThread::JThread()
{
retval = NULL;
mutexinit = false;
requeststop = false;
running = false;
}
Expand All @@ -52,25 +51,6 @@ void JThread::Stop() {

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)
{
Expand Down
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif

#if USE_CURL
#include "curl.h"
#include "curl/curl.h"
#endif

/*
Expand Down Expand Up @@ -708,7 +708,6 @@ void SpeedTests()
TimeTaker timer("Testing mutex speed");

JMutex m;
m.Init();
u32 n = 0;
u32 i = 0;
do{
Expand Down
18 changes: 8 additions & 10 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ Map::Map(std::ostream &dout, IGameDef *gamedef):
m_gamedef(gamedef),
m_sector_cache(NULL)
{
/*m_sector_mutex.Init();
assert(m_sector_mutex.IsInitialized());*/
}

Map::~Map()
Expand Down Expand Up @@ -1681,7 +1679,7 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
v3s16 p0 = m_transforming_liquid.pop_front();
u16 total_level = 0;
// surrounding flowing liquid nodes
NodeNeighbor neighbors[7];
NodeNeighbor neighbors[7];
// current level of every block
s8 liquid_levels[7] = {-1, -1, -1, -1, -1, -1, -1};
// target levels
Expand Down Expand Up @@ -1782,8 +1780,8 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
liquid_levels[D_BOTTOM] == LIQUID_LEVEL_SOURCE &&
total_level >= LIQUID_LEVEL_SOURCE * can_liquid_same_level-
(can_liquid_same_level - relax) &&
can_liquid_same_level >= relax + 1) {
total_level = LIQUID_LEVEL_SOURCE * can_liquid_same_level;
can_liquid_same_level >= relax + 1) {
total_level = LIQUID_LEVEL_SOURCE * can_liquid_same_level;
}

// prevent lakes in air above unloaded blocks
Expand All @@ -1792,9 +1790,9 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
}

// calculate self level 5 blocks
u8 want_level =
u8 want_level =
total_level >= LIQUID_LEVEL_SOURCE * can_liquid_same_level
? LIQUID_LEVEL_SOURCE
? LIQUID_LEVEL_SOURCE
: total_level / can_liquid_same_level;
total_level -= want_level * can_liquid_same_level;

Expand Down Expand Up @@ -1852,7 +1850,7 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)

/*
if (total_level > 0) //|| flowed != volume)
infostream <<" AFTER level=" << (int)total_level
infostream <<" AFTER level=" << (int)total_level
//<< " flowed="<<flowed<< " volume=" << volume
<< " wantsame="<<(int)want_level<< " top="
<< (int)liquid_levels_want[D_TOP]<< " topwas="
Expand All @@ -1862,7 +1860,7 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)

//u8 changed = 0;
for (u16 i = 0; i < 7; i++) {
if (liquid_levels_want[i] < 0 || !neighbors[i].l)
if (liquid_levels_want[i] < 0 || !neighbors[i].l)
continue;
MapNode & n0 = neighbors[i].n;
p0 = neighbors[i].p;
Expand Down Expand Up @@ -1909,7 +1907,7 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
*/
/*
if (
new_node_content == n0.getContent()
new_node_content == n0.getContent()
&& (nodemgr->get(n0.getContent()).liquid_type != LIQUID_FLOWING ||
(n0.getLevel(nodemgr) == (u8)new_node_level
//&& ((n0.param2 & LIQUID_FLOW_DOWN_MASK) ==
Expand Down
1 change: 0 additions & 1 deletion src/mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
reallocate();

#ifndef SERVER
//mesh_mutex.Init();
mesh = NULL;
#endif
}
Expand Down
1 change: 0 additions & 1 deletion src/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Profiler
public:
Profiler()
{
m_mutex.Init();
}

void add(const std::string &name, float value)
Expand Down
1 change: 0 additions & 1 deletion src/quicktune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ static void makeMutex()
{
if(!g_mutex){
g_mutex = new JMutex();
g_mutex->Init();
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/script/cpp_api/s_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ class ModNameStorer

ScriptApiBase::ScriptApiBase()
{
m_luastackmutex.Init();

#ifdef SCRIPTAPI_LOCK_DEBUG
m_locked = false;
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/script/lua_api/l_async_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ AsyncEngine::AsyncEngine() :
m_initDone(false),
m_JobIdCounter(0)
{
assert(m_JobQueueMutex.Init() == 0);
assert(m_ResultQueueMutex.Init() == 0);
}

/******************************************************************************/
Expand Down
13 changes: 5 additions & 8 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,6 @@ 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_step_dtime = 0.0;

if(path_world == "")
Expand Down Expand Up @@ -722,7 +719,7 @@ Server::Server(
m_mods = modconf.getMods();
std::vector<ModSpec> unsatisfied_mods = modconf.getUnsatisfiedMods();
// complain about mods with unsatisfied dependencies
if(!modconf.isConsistent())
if(!modconf.isConsistent())
{
for(std::vector<ModSpec>::iterator it = unsatisfied_mods.begin();
it != unsatisfied_mods.end(); ++it)
Expand All @@ -741,10 +738,10 @@ Server::Server(
worldmt_settings.readConfigFile(worldmt.c_str());
std::vector<std::string> names = worldmt_settings.getNames();
std::set<std::string> load_mod_names;
for(std::vector<std::string>::iterator it = names.begin();
for(std::vector<std::string>::iterator it = names.begin();
it != names.end(); ++it)
{
std::string name = *it;
{
std::string name = *it;
if(name.compare(0,9,"load_mod_")==0 && worldmt_settings.getBool(name))
load_mod_names.insert(name.substr(9));
}
Expand All @@ -756,7 +753,7 @@ Server::Server(
it != unsatisfied_mods.end(); ++it)
load_mod_names.erase((*it).name);
if(!load_mod_names.empty())
{
{
errorstream << "The following mods could not be found:";
for(std::set<std::string>::iterator it = load_mod_names.begin();
it != load_mod_names.end(); ++it)
Expand Down
5 changes: 2 additions & 3 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class Settings
public:
Settings()
{
m_mutex.Init();
}

void writeLines(std::ostream &os)
Expand All @@ -77,7 +76,7 @@ class Settings
}
}

// return all keys used
// return all keys used
std::vector<std::string> getNames(){
std::vector<std::string> names;
for(std::map<std::string, std::string>::iterator
Expand All @@ -86,7 +85,7 @@ class Settings
{
names.push_back(i->first);
}
return names;
return names;
}

// remove a setting
Expand Down
2 changes: 0 additions & 2 deletions src/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,6 @@ ShaderSource::ShaderSource(IrrlichtDevice *device):

m_shader_callback = new ShaderCallback(this, "default");

m_shaderinfo_cache_mutex.Init();

m_main_thread = get_current_thread_id();

// Add a dummy ShaderInfo as the first index, named ""
Expand Down
2 changes: 0 additions & 2 deletions src/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,6 @@ TextureSource::TextureSource(IrrlichtDevice *device):
{
assert(m_device);

m_textureinfo_cache_mutex.Init();

m_main_thread = get_current_thread_id();

// Add a NULL TextureInfo as the first index, named ""
Expand Down
5 changes: 0 additions & 5 deletions src/util/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class MutexedMap
public:
MutexedMap()
{
m_mutex.Init();
assert(m_mutex.IsInitialized());
}

void set(const Key &name, const Value &value)
Expand Down Expand Up @@ -150,8 +148,6 @@ class MutexedIdGenerator
public:
MutexedIdGenerator()
{
m_mutex.Init();
assert(m_mutex.IsInitialized());
}

// Returns true if found
Expand Down Expand Up @@ -253,7 +249,6 @@ class MutexedQueue
public:
MutexedQueue()
{
m_mutex.Init();
}
bool empty()
{
Expand Down
2 changes: 0 additions & 2 deletions src/util/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MutexedVariable
MutexedVariable(T value):
m_value(value)
{
m_mutex.Init();
}

T get()
Expand Down Expand Up @@ -75,7 +74,6 @@ class SimpleThread : public JThread
JThread(),
run(true)
{
run_mutex.Init();
}

virtual ~SimpleThread()
Expand Down