~ubuntu-branches/ubuntu/edgy/digikam/edgy-proposed

« back to all changes in this revision

Viewing changes to digikam/mtqueue.h

  • Committer: Bazaar Package Importer
  • Author(s): Paul Telford
  • Date: 2004-09-23 17:21:39 UTC
  • Revision ID: james.westby@ubuntu.com-20040923172139-3b3ji0dvomon3lod
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef COMMAND_QUEUE_H
 
2
#define COMMAND_QUEUE_H
 
3
 
 
4
#include <qptrqueue.h>
 
5
#include <qmutex.h>
 
6
 
 
7
template<class Type> class MTQueue
 
8
{
 
9
 
 
10
public:
 
11
 
 
12
  MTQueue()
 
13
  {
 
14
      queue_.setAutoDelete(true);
 
15
  }
 
16
 
 
17
  ~MTQueue()
 
18
  {
 
19
    flush();
 
20
  }
 
21
 
 
22
  bool isEmpty()
 
23
  {
 
24
    mutex_.lock();
 
25
    bool empty = queue_.isEmpty();
 
26
    mutex_.unlock();
 
27
    return empty;
 
28
  }
 
29
 
 
30
  void flush()
 
31
  {
 
32
    mutex_.lock();
 
33
    queue_.clear();
 
34
    mutex_.unlock();
 
35
  }
 
36
 
 
37
  void enqueue(Type * t)
 
38
  {
 
39
    mutex_.lock();
 
40
    queue_.enqueue(t);
 
41
    mutex_.unlock();
 
42
  }
 
43
 
 
44
  Type * dequeue()
 
45
  {
 
46
    mutex_.lock();
 
47
    Type * i = queue_.dequeue();
 
48
    mutex_.unlock();
 
49
    return i;
 
50
  }
 
51
 
 
52
private:
 
53
 
 
54
  QPtrQueue<Type> queue_;
 
55
  QMutex mutex_;
 
56
 
 
57
};
 
58
 
 
59
#endif