/*
- * Copyright 2001-2009 Internet2
+ * Copyright 2001-2010 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* @file xmltooling/util/Threads.h
*
- * Thread and locking wrappers
+ * Thread and locking wrappers.
*/
#ifndef _xmltooling_threads_h
#define _xmltooling_threads_h
-#include <xmltooling/base.h>
#include <xmltooling/exceptions.h>
#include <signal.h>
class XMLTOOL_API Thread
{
MAKE_NONCOPYABLE(Thread);
- public:
+ protected:
Thread() {}
+ public:
virtual ~Thread() {}
/**
*
* @param start_routine the function to execute on the thread
* @param arg a parameter for the start routine
+ * @param stacksize size of stack to use, or 0 for default
* @return the created and running thread object
*/
- static Thread* create(void* (*start_routine)(void*), void* arg);
+ static Thread* create(void* (*start_routine)(void*), void* arg, size_t stacksize=0);
/**
* Exits a thread gracefully.
class XMLTOOL_API ThreadKey
{
MAKE_NONCOPYABLE(ThreadKey);
- public:
+ protected:
ThreadKey() {}
+ public:
virtual ~ThreadKey() {}
/**
/**
* Returns the value for a TLS key.
*
- * @return the value or NULL
+ * @return the value or nullptr
*/
virtual void* getData() const=0;
class XMLTOOL_API Mutex
{
MAKE_NONCOPYABLE(Mutex);
- public:
+ protected:
Mutex() {}
+ public:
virtual ~Mutex() {}
/**
class XMLTOOL_API RWLock
{
MAKE_NONCOPYABLE(RWLock);
- public:
+ protected:
RWLock() {}
+ public:
virtual ~RWLock() {}
/**
class XMLTOOL_API CondWait
{
MAKE_NONCOPYABLE(CondWait);
- public:
+ protected:
CondWait() {}
+ public:
virtual ~CondWait() {}
/**
* @param mtx mutex to lock
*/
Lock(Mutex* mtx) : mutex(mtx) {
- mutex->lock();
+ if (mutex)
+ mutex->lock();
}
/**
* Unlocks the wrapped mutex.
*/
~Lock() {
- mutex->unlock();
+ if (mutex)
+ mutex->unlock();
}
private:
* @param lockit true if the lock should be acquired here, false if already acquired
*/
SharedLock(RWLock* lock, bool lockit=true) : rwlock(lock) {
- if (lockit)
+ if (rwlock && lockit)
rwlock->rdlock();
}
* Unlocks the wrapped shared lock.
*/
~SharedLock() {
- rwlock->unlock();
+ if (rwlock)
+ rwlock->unlock();
}
private: