summaryrefslogtreecommitdiff
path: root/docs/tutorials/013/page05.html
blob: 48e9742f86463512eedded33a437f58e28aa2211 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!-- $Id$ -->
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="James CE Johnson">
   <TITLE>ACE Tutorial 013</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">

<CENTER><B><FONT SIZE=+2>ACE Tutorial 013</FONT></B></CENTER>

<CENTER><B><FONT SIZE=+2>Multiple thread pools</FONT></B></CENTER>


<P>
<HR WIDTH="100%">
<P>
On this page we have the code for the Data_Block and Message_Block
objects.  As you probably suspect from the header on the previous
page, the complicated part is in the construction and destruction of
the Data_Block.
<P>
<HR WIDTH="100%">
<PRE>

<font color=red>// $Id$</font>

<font color=blue>#include</font> "<font color=green>block.h</font>"

<font color=red>/*
   Construct a Dat_Block to contain a unit of work.  Note the careful
   construction of the baseclass to set the block type and the locking
   strategy.
 */</font>
<font color=#008888>Data_Block::Data_Block</font> (Unit_Of_Work * _data)
        : ACE_Data_Block (0, <font color=#008888>ACE_Message_Block::MB_DATA</font>, 0, 0, new Lock (), 0, 0)
         ,data_ (_data)
{
    ACE_DEBUG ((LM_DEBUG, "<font color=green>(%P|%t) 0x%x Data_Block ctor for 0x%x\n</font>", (void *) this, (void *) data_));
}

<font color=red>/*
   The Lock object created in the constructor is stored in the baseclass and
   available through the locking_strategy() method.  We can cast it's value to
   our Lock object and invoke the destroy() to indicate that we want it to go
   away when the lock is released.
 */</font>
<font color=#008888>Data_Block::~Data_Block</font> (void)
{
    ACE_DEBUG ((LM_DEBUG, "<font color=green>(%P|%t) 0x%x Data_Block dtor for 0x%x\n</font>", (void *) this, (void *) data_));
    ((Lock *) locking_strategy ())->destroy ();
    delete data_;
}

<font color=red>/*
   Return the data
 */</font>
Unit_Of_Work *<font color=#008888>Data_Block::data</font> (void)
{
    return this->data_;
}

Data_Block:: <font color=#008888>Lock::Lock</font> (void)
{
    ACE_DEBUG ((LM_DEBUG, "<font color=green>(%P|%t) 0x%x Lock ctor\n</font>", (void *) this));
}

Data_Block:: <font color=#008888>Lock::~Lock</font> (void)
{
    ACE_DEBUG ((LM_DEBUG, "<font color=green>(%P|%t) 0x%x Lock dtor\n</font>", (void *) this));
}

<font color=red>/*
   Delete ourselves to prevent any memory leak
 */</font>
int <font color=#008888>Data_Block::Lock</font>::destroy (void)
{
    delete this;
    return (0);
}

<font color=red>/*
   Create an baseclass unit of work when we instantiate a hangup message.
 */</font>
<font color=#008888>Message_Block::Message_Block</font> (void)
        :ACE_Message_Block (new Data_Block (new Unit_Of_Work ()))
{
    ACE_DEBUG ((LM_DEBUG, "<font color=green>(%P|%t) 0x%x Message_Block ctor for shutdown\n</font>", (void *) this));
    this->msg_type (MB_HANGUP);
}

<font color=red>/*
   Store the unit of work in a Data_Block and initialize the baseclass with
   that data.
 */</font>
<font color=#008888>Message_Block::Message_Block</font> (Unit_Of_Work * _data)
        :ACE_Message_Block (new Data_Block (_data))
{
    ACE_DEBUG ((LM_DEBUG, "<font color=green>(%P|%t) 0x%x Message_Block ctor for 0x%x\n</font>", (void *) this, (void *) _data));
}

<font color=#008888>Message_Block::~Message_Block</font> (void)
{
    ACE_DEBUG ((LM_DEBUG, "<font color=green>(%P|%t) 0x%x Message_Block dtor\n</font>", (void *) this));
}
</PRE>
<P><HR WIDTH="100%">
<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page06.html">Continue This Tutorial</A>]</CENTER>