Welcome to mirror list, hosted at ThFree Co, Russian Federation.

threaded_queue.h « cygwin « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b330d96ac375179d0eccf8c9d69a0948b6bd59b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* threaded_queue.h

   Copyright 2001 Red Hat Inc.

   Written by Robert Collins <rbtcollins@hotmail.com>

   This file is part of Cygwin.

   This software is a copyrighted work licensed under the terms of the
   Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
   details. */

#ifndef _THREADED_QUEUE_
#define _THREADED_QUEUE_

/* a specific request */

class queue_request
{
  public:
    class queue_request *next;
    virtual void process ();
    queue_request();
};


typedef DWORD WINAPI threaded_queue_thread_function (LPVOID);
/* parameters for a request finding and submitting loop */

class queue_process_param
{
  public:
    bool start (threaded_queue_thread_function *, class threaded_queue *);
    void stop ();
    bool running;
    long int shutdown;
    class queue_process_param * next;
    class threaded_queue *queue;
    queue_process_param (bool ninterruptible);
    ~queue_process_param ();
    bool interruptible;
    HANDLE interrupt;
    HANDLE hThread;
    DWORD tid;
};

/* a queue to allocate requests from n submission loops to x worker threads */

class threaded_queue
{
  public:
    CRITICAL_SECTION queuelock;
    HANDLE event;
    bool active;
    queue_request * request;
    unsigned int initial_workers;
    unsigned int running;
    void create_workers ();
    void cleanup ();
    void add (queue_request *);
    void process_requests (queue_process_param *, threaded_queue_thread_function *);
    threaded_queue () : active (false), request (NULL), initial_workers (1), running (0), process_head (NULL) {};
  private:
    queue_request *process_head;
};

#endif /* _THREADED_QUEUE_ */