diff options
| author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-11-22 18:41:30 +0900 |
|---|---|---|
| committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-11-22 20:55:03 +0900 |
| commit | 5bed6e4a4c916a97f8fe4d1b07f7eecf4d733b90 (patch) | |
| tree | f89cc49efc9ca1d0e1579ecb079ee7e7088ff8c8 /src/utilities/cameragui/mtqueue.h | |
| parent | 0bfbf616d9c1fd7abb1bd02732389ab35e5f8771 (diff) | |
| download | digikam-5bed6e4a.tar.gz digikam-5bed6e4a.zip | |
Rename 'digikam' folder to 'src'
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit ee0d99607c14cb63d3ebdb3a970b508949fa8219)
Diffstat (limited to 'src/utilities/cameragui/mtqueue.h')
| -rw-r--r-- | src/utilities/cameragui/mtqueue.h | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/utilities/cameragui/mtqueue.h b/src/utilities/cameragui/mtqueue.h new file mode 100644 index 00000000..0fb80e5c --- /dev/null +++ b/src/utilities/cameragui/mtqueue.h @@ -0,0 +1,116 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2004-09-30 + * Description : camera download multi-threading handler. + * + * Copyright (C) 2004 by Renchi Raju <renchi@pooh.tam.uiuc.edu> + + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ============================================================ */ + +#ifndef COMMAND_QUEUE_H +#define COMMAND_QUEUE_H + +// TQt includes. + +#include <tqptrqueue.h> +#include <tqmutex.h> + +namespace Digikam +{ + +template<class Type> class MTQueue +{ + +public: + + MTQueue() + { + queue_.setAutoDelete(true); + } + + ~MTQueue() + { + flush(); + } + + bool isEmpty() + { + mutex_.lock(); + bool empty = queue_.isEmpty(); + mutex_.unlock(); + return empty; + } + + void flush() + { + mutex_.lock(); + queue_.clear(); + mutex_.unlock(); + } + + void enqueue(Type * t) + { + mutex_.lock(); + queue_.enqueue(t); + mutex_.unlock(); + } + + Type * dequeue() + { + mutex_.lock(); + Type * i = queue_.dequeue(); + mutex_.unlock(); + return i; + } + + Type * head(bool lock=true) + { + if (lock) + mutex_.lock(); + Type * i = queue_.head(); + if (lock) + mutex_.unlock(); + return i; + } + + int count() + { + mutex_.lock(); + int c = queue_.count(); + mutex_.unlock(); + return c; + } + + void lock() + { + mutex_.lock(); + } + + void unlock() + { + mutex_.unlock(); + } + +private: + + TQPtrQueue<Type> queue_; + TQMutex mutex_; +}; + +} // namespace Digikam + +#endif // COMMAND_QUEUE_H |
