OSDN Git Service

2002-03-01 David O'Brien <obrien@FreeBSD.org>
[pf3gnuchains/pf3gnuchains3x.git] / winsup / cygwin / threaded_queue.h
1 /* threaded_queue.h
2
3    Copyright 2001 Red Hat Inc.
4
5    Written by Robert Collins <rbtcollins@hotmail.com>
6
7    This file is part of Cygwin.
8
9    This software is a copyrighted work licensed under the terms of the
10    Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
11    details. */
12
13 #ifndef _THREADED_QUEUE_
14 #define _THREADED_QUEUE_
15
16 /* a specific request */
17
18 class queue_request
19 {
20   public:
21     class queue_request *next;
22     virtual void process ();
23     queue_request();
24 };
25
26
27 typedef DWORD WINAPI threaded_queue_thread_function (LPVOID);
28 /* parameters for a request finding and submitting loop */
29
30 class queue_process_param
31 {
32   public:
33     bool start (threaded_queue_thread_function *, class threaded_queue *);
34     void stop ();
35     bool running;
36     long int shutdown;
37     class queue_process_param * next;
38     class threaded_queue *queue;
39     queue_process_param (bool ninterruptible);
40     ~queue_process_param ();
41     bool interruptible;
42     HANDLE interrupt;
43     HANDLE hThread;
44     DWORD tid;
45 };
46
47 /* a queue to allocate requests from n submission loops to x worker threads */
48
49 class threaded_queue
50 {
51   public:
52     CRITICAL_SECTION queuelock;
53     HANDLE event;
54     bool active;
55     queue_request * request;
56     unsigned int initial_workers;
57     unsigned int running;
58     void create_workers ();
59     void cleanup ();
60     void add (queue_request *);
61     void process_requests (queue_process_param *, threaded_queue_thread_function *);
62     threaded_queue () : active (false), request (NULL), initial_workers (1), running (0), process_head (NULL) {};
63   private:
64     queue_request *process_head;
65 };
66
67 #endif /* _THREADED_QUEUE_ */