Misc. minor fixes
This commit is contained in:
parent
e6f0178e83
commit
8eb272cea3
|
@ -88,15 +88,14 @@ public:
|
|||
} else if (event.EventType == irr::EET_LOG_TEXT_EVENT) {
|
||||
static const enum LogMessageLevel irr_loglev_conv[] = {
|
||||
LMT_VERBOSE, // ELL_DEBUG
|
||||
LMT_INFO, // ELL_INFORMATION
|
||||
LMT_ACTION, // ELL_WARNING
|
||||
LMT_ERROR, // ELL_ERROR
|
||||
LMT_ERROR, // ELL_NONE
|
||||
LMT_INFO, // ELL_INFORMATION
|
||||
LMT_ACTION, // ELL_WARNING
|
||||
LMT_ERROR, // ELL_ERROR
|
||||
LMT_ERROR, // ELL_NONE
|
||||
};
|
||||
assert(event.LogEvent.Level < sizeof(irr_loglev_conv));
|
||||
assert(event.LogEvent.Level < ARRLEN(irr_loglev_conv));
|
||||
log_printline(irr_loglev_conv[event.LogEvent.Level],
|
||||
std::string("Irrlicht: ")
|
||||
+ (const char*) event.LogEvent.Text);
|
||||
std::string("Irrlicht: ") + (const char *)event.LogEvent.Text);
|
||||
return true;
|
||||
}
|
||||
/* always return false in order to continue processing events */
|
||||
|
|
|
@ -57,7 +57,7 @@ static const char *modified_reason_strings[] = {
|
|||
"deactivateFarObjects: Static data moved in",
|
||||
"deactivateFarObjects: Static data moved out",
|
||||
"deactivateFarObjects: Static data changed considerably",
|
||||
"finishBlockMake: expireDayNightDiff"
|
||||
"finishBlockMake: expireDayNightDiff",
|
||||
"unknown",
|
||||
};
|
||||
|
||||
|
|
|
@ -105,11 +105,7 @@ public:
|
|||
MinimapData *data;
|
||||
|
||||
protected:
|
||||
const char *getName()
|
||||
{
|
||||
return "MinimapUpdateThread";
|
||||
}
|
||||
|
||||
const char *getName() { return "MinimapUpdateThread"; }
|
||||
virtual void doUpdate();
|
||||
|
||||
private:
|
||||
|
|
|
@ -138,7 +138,7 @@ void PcgRandom::bytes(void *out, size_t len)
|
|||
*outb = r & 0xFF;
|
||||
outb++;
|
||||
bytes_left--;
|
||||
r >>= 8;
|
||||
r >>= CHAR_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,13 +28,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "log.h"
|
||||
|
||||
template<typename T>
|
||||
class MutexedVariable
|
||||
{
|
||||
class MutexedVariable {
|
||||
public:
|
||||
MutexedVariable(T value):
|
||||
m_value(value)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
T get()
|
||||
{
|
||||
|
@ -47,13 +45,13 @@ public:
|
|||
JMutexAutoLock lock(m_mutex);
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
|
||||
// You'll want to grab this in a SharedPtr
|
||||
JMutexAutoLock * getLock()
|
||||
JMutexAutoLock *getLock()
|
||||
{
|
||||
return new JMutexAutoLock(m_mutex);
|
||||
}
|
||||
|
||||
|
||||
// You pretty surely want to grab the lock when accessing this
|
||||
T m_value;
|
||||
|
||||
|
@ -65,8 +63,7 @@ private:
|
|||
A single worker thread - multiple client threads queue framework.
|
||||
*/
|
||||
template<typename Key, typename T, typename Caller, typename CallerData>
|
||||
class GetResult
|
||||
{
|
||||
class GetResult {
|
||||
public:
|
||||
Key key;
|
||||
T item;
|
||||
|
@ -74,34 +71,27 @@ public:
|
|||
};
|
||||
|
||||
template<typename Key, typename T, typename Caller, typename CallerData>
|
||||
class ResultQueue: public MutexedQueue< GetResult<Key, T, Caller, CallerData> >
|
||||
{
|
||||
class ResultQueue : public MutexedQueue<GetResult<Key, T, Caller, CallerData> > {
|
||||
};
|
||||
|
||||
template<typename Caller, typename Data, typename Key, typename T>
|
||||
class CallerInfo
|
||||
{
|
||||
class CallerInfo {
|
||||
public:
|
||||
Caller caller;
|
||||
Data data;
|
||||
ResultQueue< Key, T, Caller, Data>* dest;
|
||||
ResultQueue<Key, T, Caller, Data> *dest;
|
||||
};
|
||||
|
||||
template<typename Key, typename T, typename Caller, typename CallerData>
|
||||
class GetRequest
|
||||
{
|
||||
class GetRequest {
|
||||
public:
|
||||
GetRequest()
|
||||
{
|
||||
}
|
||||
GetRequest(Key a_key)
|
||||
{
|
||||
GetRequest() {}
|
||||
~GetRequest() {}
|
||||
|
||||
GetRequest(Key a_key) {
|
||||
key = a_key;
|
||||
}
|
||||
~GetRequest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Key key;
|
||||
std::list<CallerInfo<Caller, CallerData, Key, T> > callers;
|
||||
};
|
||||
|
@ -114,8 +104,7 @@ public:
|
|||
* @param CallerData data passed back to caller
|
||||
*/
|
||||
template<typename Key, typename T, typename Caller, typename CallerData>
|
||||
class RequestQueue
|
||||
{
|
||||
class RequestQueue {
|
||||
public:
|
||||
bool empty()
|
||||
{
|
||||
|
@ -123,40 +112,36 @@ public:
|
|||
}
|
||||
|
||||
void add(Key key, Caller caller, CallerData callerdata,
|
||||
ResultQueue<Key, T, Caller, CallerData> *dest)
|
||||
ResultQueue<Key, T, Caller, CallerData> *dest)
|
||||
{
|
||||
typename std::deque<GetRequest<Key, T, Caller, CallerData> >::iterator i;
|
||||
typename std::list<CallerInfo<Caller, CallerData, Key, T> >::iterator j;
|
||||
|
||||
{
|
||||
JMutexAutoLock lock(m_queue.getMutex());
|
||||
|
||||
/*
|
||||
If the caller is already on the list, only update CallerData
|
||||
*/
|
||||
for(typename std::deque< GetRequest<Key, T, Caller, CallerData> >::iterator
|
||||
i = m_queue.getQueue().begin();
|
||||
i != m_queue.getQueue().end(); ++i)
|
||||
{
|
||||
for (i = m_queue.getQueue().begin(); i != m_queue.getQueue().end(); ++i) {
|
||||
GetRequest<Key, T, Caller, CallerData> &request = *i;
|
||||
if (request.key != key)
|
||||
continue;
|
||||
|
||||
if(request.key == key)
|
||||
{
|
||||
for(typename std::list< CallerInfo<Caller, CallerData, Key, T> >::iterator
|
||||
i = request.callers.begin();
|
||||
i != request.callers.end(); ++i)
|
||||
{
|
||||
CallerInfo<Caller, CallerData, Key, T> &ca = *i;
|
||||
if(ca.caller == caller)
|
||||
{
|
||||
ca.data = callerdata;
|
||||
return;
|
||||
}
|
||||
for (j = request.callers.begin(); j != request.callers.end(); ++j) {
|
||||
CallerInfo<Caller, CallerData, Key, T> &ca = *j;
|
||||
if (ca.caller == caller) {
|
||||
ca.data = callerdata;
|
||||
return;
|
||||
}
|
||||
CallerInfo<Caller, CallerData, Key, T> ca;
|
||||
ca.caller = caller;
|
||||
ca.data = callerdata;
|
||||
ca.dest = dest;
|
||||
request.callers.push_back(ca);
|
||||
return;
|
||||
}
|
||||
|
||||
CallerInfo<Caller, CallerData, Key, T> ca;
|
||||
ca.caller = caller;
|
||||
ca.data = callerdata;
|
||||
ca.dest = dest;
|
||||
request.callers.push_back(ca);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +156,7 @@ public:
|
|||
ca.data = callerdata;
|
||||
ca.dest = dest;
|
||||
request.callers.push_back(ca);
|
||||
|
||||
|
||||
m_queue.push_back(request);
|
||||
}
|
||||
|
||||
|
@ -185,13 +170,11 @@ public:
|
|||
return m_queue.pop_frontNoEx();
|
||||
}
|
||||
|
||||
void pushResult(GetRequest<Key, T, Caller, CallerData> req,
|
||||
T res) {
|
||||
|
||||
for(typename std::list< CallerInfo<Caller, CallerData, Key, T> >::iterator
|
||||
void pushResult(GetRequest<Key, T, Caller, CallerData> req, T res)
|
||||
{
|
||||
for (typename std::list<CallerInfo<Caller, CallerData, Key, T> >::iterator
|
||||
i = req.callers.begin();
|
||||
i != req.callers.end(); ++i)
|
||||
{
|
||||
i != req.callers.end(); ++i) {
|
||||
CallerInfo<Caller, CallerData, Key, T> &ca = *i;
|
||||
|
||||
GetResult<Key,T,Caller,CallerData> result;
|
||||
|
@ -206,24 +189,13 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
MutexedQueue< GetRequest<Key, T, Caller, CallerData> > m_queue;
|
||||
MutexedQueue<GetRequest<Key, T, Caller, CallerData> > m_queue;
|
||||
};
|
||||
|
||||
class UpdateThread : public JThread
|
||||
{
|
||||
private:
|
||||
JSemaphore m_update_sem;
|
||||
|
||||
protected:
|
||||
virtual void doUpdate() = 0;
|
||||
virtual const char *getName() = 0;
|
||||
|
||||
class UpdateThread : public JThread {
|
||||
public:
|
||||
UpdateThread()
|
||||
{
|
||||
}
|
||||
~UpdateThread()
|
||||
{}
|
||||
UpdateThread() {}
|
||||
virtual ~UpdateThread() {}
|
||||
|
||||
void deferUpdate()
|
||||
{
|
||||
|
@ -243,30 +215,36 @@ public:
|
|||
ThreadStarted();
|
||||
|
||||
const char *thread_name = getName();
|
||||
|
||||
log_register_thread(thread_name);
|
||||
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
|
||||
BEGIN_DEBUG_EXCEPTION_HANDLER
|
||||
|
||||
porting::setThreadName(thread_name);
|
||||
|
||||
while (!StopRequested()) {
|
||||
DSTACK(__FUNCTION_NAME);
|
||||
BEGIN_DEBUG_EXCEPTION_HANDLER
|
||||
|
||||
while (!StopRequested()) {
|
||||
m_update_sem.Wait();
|
||||
|
||||
// Empty the queue, just in case doUpdate() is expensive
|
||||
while (m_update_sem.GetValue()) m_update_sem.Wait();
|
||||
while (m_update_sem.GetValue())
|
||||
m_update_sem.Wait();
|
||||
|
||||
if (StopRequested()) break;
|
||||
if (StopRequested())
|
||||
break;
|
||||
|
||||
doUpdate();
|
||||
}
|
||||
|
||||
END_DEBUG_EXCEPTION_HANDLER(errorstream)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void doUpdate() = 0;
|
||||
virtual const char *getName() = 0;
|
||||
|
||||
private:
|
||||
JSemaphore m_update_sem;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue