/*
- * Copyright 2001-2006 Internet2
+ * Copyright 2001-2007 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
/**
- * @file Threads.h
+ * @file xmltooling/util/Threads.h
*
* Thread and locking wrappers
*/
* @param return_val the return value for the thread
*/
static void exit(void* return_val);
-
+
+ /**
+ * Sleeps the current thread for the specified amount of time.
+ *
+ * @param seconds time to sleep
+ */
+ static void sleep(int seconds);
#ifndef WIN32
/**
* Masks all signals from a thread.
/**
* RAII wrapper for a shared lock.
*/
- class XMLTOOL_API ReadLock {
- MAKE_NONCOPYABLE(ReadLock);
+ class XMLTOOL_API SharedLock {
+ MAKE_NONCOPYABLE(SharedLock);
public:
/**
* Locks and wraps the designated shared lock.
*
- * @param lock lock to acquire
+ * @param lock lock to acquire
+ * @param lockit true if the lock should be acquired here, false if already acquired
*/
- ReadLock(RWLock* lock) : rwlock(lock) {
- rwlock->rdlock();
+ SharedLock(RWLock* lock, bool lockit=true) : rwlock(lock) {
+ if (lockit)
+ rwlock->rdlock();
}
/**
* Unlocks the wrapped shared lock.
*/
- ~ReadLock() {
+ ~SharedLock() {
rwlock->unlock();
}