mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Clean up threading
* Rename everything. * Strip J prefix. * Change UpperCamelCase functions to lowerCamelCase. * Remove global (!) semaphore count mutex on OSX. * Remove semaphore count getter (unused, unsafe, depended on internal API functions on Windows, and used a hack on OSX). * Add `Atomic<type>`. * Make `Thread` handle thread names. * Add support for C++11 multi-threading. * Combine pthread and win32 sources. * Remove `ThreadStarted` (unused, unneeded). * Move some includes from the headers to the sources. * Move all of `Event` into its header (allows inlining with no new includes). * Make `Event` use `Semaphore` (except on Windows). * Move some porting functions into `Thread`. * Integrate logging with `Thread`. * Add threading test.
This commit is contained in:
parent
6a1047d8c1
commit
e4bff8be94
77 changed files with 1594 additions and 2046 deletions
|
@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "settings.h"
|
||||
#include "irrlichttypes_bloated.h"
|
||||
#include "exceptions.h"
|
||||
#include "jthread/jmutexautolock.h"
|
||||
#include "threading/mutex_auto_lock.h"
|
||||
#include "strfnd.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
@ -56,8 +56,8 @@ Settings & Settings::operator = (const Settings &other)
|
|||
if (&other == this)
|
||||
return *this;
|
||||
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
JMutexAutoLock lock2(other.m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock2(other.m_mutex);
|
||||
|
||||
clearNoLock();
|
||||
updateNoLock(other);
|
||||
|
@ -155,7 +155,7 @@ bool Settings::readConfigFile(const char *filename)
|
|||
|
||||
bool Settings::parseConfigLines(std::istream &is, const std::string &end)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
std::string line, name, value;
|
||||
|
||||
|
@ -194,7 +194,7 @@ bool Settings::parseConfigLines(std::istream &is, const std::string &end)
|
|||
|
||||
void Settings::writeLines(std::ostream &os, u32 tab_depth) const
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
for (std::map<std::string, SettingsEntry>::const_iterator
|
||||
it = m_settings.begin();
|
||||
|
@ -298,7 +298,7 @@ bool Settings::updateConfigObject(std::istream &is, std::ostream &os,
|
|||
|
||||
bool Settings::updateConfigFile(const char *filename)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
std::ifstream is(filename);
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
|
@ -379,7 +379,7 @@ bool Settings::parseCommandLine(int argc, char *argv[],
|
|||
|
||||
const SettingsEntry &Settings::getEntry(const std::string &name) const
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
std::map<std::string, SettingsEntry>::const_iterator n;
|
||||
if ((n = m_settings.find(name)) == m_settings.end()) {
|
||||
|
@ -562,7 +562,7 @@ bool Settings::getNoiseParamsFromGroup(const std::string &name,
|
|||
|
||||
bool Settings::exists(const std::string &name) const
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
return (m_settings.find(name) != m_settings.end() ||
|
||||
m_defaults.find(name) != m_defaults.end());
|
||||
|
@ -742,7 +742,7 @@ bool Settings::setEntry(const std::string &name, const void *data,
|
|||
return false;
|
||||
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
SettingsEntry &entry = set_default ? m_defaults[name] : m_settings[name];
|
||||
old_group = entry.group;
|
||||
|
@ -878,7 +878,7 @@ bool Settings::setNoiseParams(const std::string &name,
|
|||
|
||||
bool Settings::remove(const std::string &name)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
delete m_settings[name].group;
|
||||
return m_settings.erase(name);
|
||||
|
@ -887,13 +887,13 @@ bool Settings::remove(const std::string &name)
|
|||
|
||||
void Settings::clear()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
clearNoLock();
|
||||
}
|
||||
|
||||
void Settings::clearDefaults()
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
clearDefaultsNoLock();
|
||||
}
|
||||
|
||||
|
@ -902,7 +902,7 @@ void Settings::updateValue(const Settings &other, const std::string &name)
|
|||
if (&other == this)
|
||||
return;
|
||||
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
try {
|
||||
std::string val = other.get(name);
|
||||
|
@ -918,8 +918,8 @@ void Settings::update(const Settings &other)
|
|||
if (&other == this)
|
||||
return;
|
||||
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
JMutexAutoLock lock2(other.m_mutex);
|
||||
MutexAutoLock lock(m_mutex);
|
||||
MutexAutoLock lock2(other.m_mutex);
|
||||
|
||||
updateNoLock(other);
|
||||
}
|
||||
|
@ -982,13 +982,13 @@ void Settings::clearDefaultsNoLock()
|
|||
void Settings::registerChangedCallback(std::string name,
|
||||
setting_changed_callback cbf, void *userdata)
|
||||
{
|
||||
JMutexAutoLock lock(m_callbackMutex);
|
||||
MutexAutoLock lock(m_callbackMutex);
|
||||
m_callbacks[name].push_back(std::make_pair(cbf, userdata));
|
||||
}
|
||||
|
||||
void Settings::deregisterChangedCallback(std::string name, setting_changed_callback cbf, void *userdata)
|
||||
{
|
||||
JMutexAutoLock lock(m_callbackMutex);
|
||||
MutexAutoLock lock(m_callbackMutex);
|
||||
std::map<std::string, std::vector<std::pair<setting_changed_callback, void*> > >::iterator iterToVector = m_callbacks.find(name);
|
||||
if (iterToVector != m_callbacks.end())
|
||||
{
|
||||
|
@ -1004,7 +1004,7 @@ void Settings::deregisterChangedCallback(std::string name, setting_changed_callb
|
|||
|
||||
void Settings::doCallbacks(const std::string name)
|
||||
{
|
||||
JMutexAutoLock lock(m_callbackMutex);
|
||||
MutexAutoLock lock(m_callbackMutex);
|
||||
std::map<std::string, std::vector<std::pair<setting_changed_callback, void*> > >::iterator iterToVector = m_callbacks.find(name);
|
||||
if (iterToVector != m_callbacks.end())
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue