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

// $Id$

#ifndef TASK_H
#define TASK_H

#include "ace/Task.h"

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

#include "mld.h"

/*
   This is much like the Task we've used in the past for implementing a  thread
   pool.  This time, however, I've made the Task an element in a  singly-linked
   list.  As the svc() method finishes the process() on a  unit of work, it
   will enqueue that unit of work to the next_ Task if  there is one.  If the
   Task does not have a next_ Task, it will invoke the unit of work object's
   fini() method after invoking process().
 */
class Task : public ACE_Task < ACE_MT_SYNCH >
{
public:

  typedef ACE_Task < ACE_MT_SYNCH > inherited;

  // Construct ourselves and an optional number of subtasks
  // chained beyond us.
    Task (int sub_tasks = 0);
   ~Task (void);

  // Open the Task with the proper thread-pool size
  int open (int threads = 1);

  // Take Unit_Of_Work objects from the thread pool and invoke
  // their process() and/or fini() as appropriate.
  int svc (void);

  // Shut down the thread pool and it's associated subtasks
  int close (u_long flags = 0);

  // Wait for the pool and subtasks to close
  int wait (void);

protected:
    ACE_Barrier * barrier_;
  Task *next_;
    MLD;
};

#endif