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

« back to all changes in this revision

Viewing changes to mpeglib/lib/decoder/commandPipe.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
  thread safe fifo queue for commands
 
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 __COMMAND_PIPE_H
 
15
#define __COMMAND_PIPE_H
 
16
 
 
17
 
 
18
 
 
19
#include "command.h"
 
20
 
 
21
/**
 
22
   This queue deals with the ugly deadlock problem.
 
23
   We insert all commands in a queue and the thread
 
24
   polls this queue for next commands.
 
25
*/
 
26
 
 
27
class CommandPipe {
 
28
 
 
29
  Command** commandArray;
 
30
  int entries;
 
31
  int readPos;
 
32
  int writePos;
 
33
 
 
34
  abs_thread_mutex_t pipeMut; 
 
35
  abs_thread_cond_t spaceCond;
 
36
  abs_thread_cond_t emptyCond;
 
37
  abs_thread_cond_t dataCond;
 
38
 
 
39
 public:
 
40
  CommandPipe();
 
41
  ~CommandPipe();
 
42
  
 
43
  // writer thread:
 
44
  void sendCommand(Command& cmd);
 
45
  void sendCommandNoWait(Command& cmd);
 
46
  
 
47
  void waitForEmptyQueue();
 
48
 
 
49
  // reader thread
 
50
  int hasCommand(Command* dest);
 
51
  void waitForCommand();
 
52
  
 
53
 
 
54
 
 
55
 
 
56
 private:
 
57
  void sendCommand(Command& cmd,int lWait);
 
58
 
 
59
  void lockCommandPipe();
 
60
  void unlockCommandPipe();
 
61
 
 
62
 
 
63
  // writer thread wait here
 
64
  void waitForSpace();
 
65
  void waitForEmpty();
 
66
  void waitForData();
 
67
  
 
68
  // reader thread signals this
 
69
  void signalSpace();
 
70
  void signalEmpty();
 
71
  void signalData();
 
72
 
 
73
 
 
74
  
 
75
 
 
76
};
 
77
 
 
78
#endif