~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/util/abstract/threadQueue.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  fifo waitqueue for threads.(Multi-in, single out)
 
3
  Copyright (C) 2000  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
#ifndef __THREADQUEUE_H
 
15
#define __THREADQUEUE_H
 
16
 
 
17
 
 
18
#include "abs_thread.h"
 
19
 
 
20
class  WaitThreadEntry {
 
21
 public:
 
22
  WaitThreadEntry();
 
23
  ~WaitThreadEntry();
 
24
 
 
25
  abs_thread_cond_t waitCond;
 
26
};
 
27
 
 
28
/**
 
29
   This class can be used as a general purpuse wrapper to
 
30
   make C++ classes thread safe.
 
31
   Mpeglib uses for every decoder a single thread which
 
32
   reads from the input and write to one output type (video/audio)
 
33
   To make the input and output classes thread safe you have
 
34
   two solutions. First you can try to do it in every class
 
35
   itsself, this is much work and needs understanding of
 
36
   threads or you can use this wrapper class.
 
37
   Normally you don't need two threads in one class, only
 
38
   for the audio/video sync this is necessary, but for
 
39
   the inputstream (file,http,..) this not necessary.
 
40
   For the output this is the same.
 
41
   This class offers two methods. waitForExclusiceAcess()
 
42
   and releaseExlusiveAcess. Internally the thread who
 
43
   calls waitFor.. in enqueued (if it does not get the exclusive
 
44
   access) the thread who have the exclusive access calls
 
45
   sometimes release.. with then pass the exclusive access
 
46
   to the next thread. 
 
47
   Why it is needed?
 
48
   Because we access the input/output streams from different
 
49
   threads. A user of mpeglib may want to set mpeg video
 
50
   in fullscreen mode, this means two threads call
 
51
   methods in the output classes including: closing windows,
 
52
   resizing windows ... now this is safley possible when
 
53
   the threadSafeInputStream / threadSafeoutputStream wrappers
 
54
   are used, which forward the calls to the real classes.
 
55
*/
 
56
 
 
57
class ThreadQueue {
 
58
 
 
59
  abs_thread_mutex_t queueMut; 
 
60
  int insertPos;
 
61
  int removePos;
 
62
  int size;
 
63
  WaitThreadEntry** waitThreadEntries;
 
64
 
 
65
 public:
 
66
  ThreadQueue();
 
67
  ~ThreadQueue();
 
68
 
 
69
  void waitForExclusiveAccess();
 
70
  void releaseExclusiveAccess();
 
71
 
 
72
};
 
73
 
 
74
#endif