summaryrefslogtreecommitdiff
path: root/docs/tutorials/012/task.h
blob: afeed1bbf1d35c7585686df411d8b1d6710694b4 (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

// $Id$

#ifndef TASK_H
#define TASK_H

#include "ace/Task.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

/*
  This is our basic thread-pool Task.  We have a choice of pool size
  on the open() and the usual svc() and close() methods.

  A new addition is the ACE_Barrier object.  This will allow the
  synchronization of our svc() methods so that they all start at the
  "same" time.  The normal case may allow one thread to start working
  earlier than others.  There's no real harm in it but you can get
  better "work by thread" statistics if they start out together.
*/
class Task : public ACE_Task < ACE_MT_SYNCH >
{
public:

    typedef ACE_Task < ACE_MT_SYNCH > inherited;

    Task (void);
    ~Task (void);

    /*
      I really wanted this to be called open() but that was already
      claimed by the Task framework.  start() will kick off our thread
      pool for us.
    */
    int start (int threads = 1);

    virtual int svc (void);

    virtual int close (u_long flags = 0);

protected:
    ACE_Barrier * barrier_;
};

#endif