JSONDB performance improvements, threading fix.
This commit is contained in:
@@ -46,7 +46,6 @@ class Thread
|
||||
{
|
||||
public:
|
||||
Thread()
|
||||
throw()
|
||||
{
|
||||
_th = NULL;
|
||||
_tid = 0;
|
||||
@@ -54,7 +53,6 @@ public:
|
||||
|
||||
template<typename C>
|
||||
static inline Thread start(C *instance)
|
||||
throw(std::runtime_error)
|
||||
{
|
||||
Thread t;
|
||||
t._th = CreateThread(NULL,0,&___zt_threadMain<C>,(LPVOID)instance,0,&t._tid);
|
||||
@@ -88,7 +86,7 @@ public:
|
||||
CancelSynchronousIo(t._th);
|
||||
}
|
||||
|
||||
inline operator bool() const throw() { return (_th != NULL); }
|
||||
inline operator bool() const { return (_th != NULL); }
|
||||
|
||||
private:
|
||||
HANDLE _th;
|
||||
@@ -123,33 +121,18 @@ class Thread
|
||||
{
|
||||
public:
|
||||
Thread()
|
||||
throw()
|
||||
{
|
||||
memset(&_tid,0,sizeof(_tid));
|
||||
pthread_attr_init(&_tattr);
|
||||
// This corrects for systems with abnormally small defaults (musl) and also
|
||||
// shrinks the stack on systems with large defaults to save a bit of memory.
|
||||
pthread_attr_setstacksize(&_tattr,ZT_THREAD_MIN_STACK_SIZE);
|
||||
_started = false;
|
||||
}
|
||||
|
||||
~Thread()
|
||||
{
|
||||
pthread_attr_destroy(&_tattr);
|
||||
memset(this,0,sizeof(Thread));
|
||||
}
|
||||
|
||||
Thread(const Thread &t)
|
||||
throw()
|
||||
{
|
||||
memcpy(&_tid,&(t._tid),sizeof(_tid));
|
||||
_started = t._started;
|
||||
memcpy(this,&t,sizeof(Thread));
|
||||
}
|
||||
|
||||
inline Thread &operator=(const Thread &t)
|
||||
throw()
|
||||
{
|
||||
memcpy(&_tid,&(t._tid),sizeof(_tid));
|
||||
_started = t._started;
|
||||
memcpy(this,&t,sizeof(Thread));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -163,12 +146,20 @@ public:
|
||||
*/
|
||||
template<typename C>
|
||||
static inline Thread start(C *instance)
|
||||
throw(std::runtime_error)
|
||||
{
|
||||
Thread t;
|
||||
t._started = true;
|
||||
if (pthread_create(&t._tid,&t._tattr,&___zt_threadMain<C>,instance))
|
||||
pthread_attr_t tattr;
|
||||
pthread_attr_init(&tattr);
|
||||
// This corrects for systems with abnormally small defaults (musl) and also
|
||||
// shrinks the stack on systems with large defaults to save a bit of memory.
|
||||
pthread_attr_setstacksize(&tattr,ZT_THREAD_MIN_STACK_SIZE);
|
||||
if (pthread_create(&t._tid,&tattr,&___zt_threadMain<C>,instance)) {
|
||||
pthread_attr_destroy(&tattr);
|
||||
throw std::runtime_error("pthread_create() failed, unable to create thread");
|
||||
} else {
|
||||
t._started = true;
|
||||
pthread_attr_destroy(&tattr);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -190,11 +181,10 @@ public:
|
||||
*/
|
||||
static inline void sleep(unsigned long ms) { usleep(ms * 1000); }
|
||||
|
||||
inline operator bool() const throw() { return (_started); }
|
||||
inline operator bool() const { return (_started); }
|
||||
|
||||
private:
|
||||
pthread_t _tid;
|
||||
pthread_attr_t _tattr;
|
||||
volatile bool _started;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user