Sophie

Sophie

distrib > Mandriva > 10.0-com > i586 > by-pkgid > 21280410b6ea906d791d7a12afae2579 > files > 201

libace5-doc-5.4-2mdk.i586.rpm

<!-- page05.html,v 1.10 2000/03/19 20:09:27 jcej Exp -->
<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>// page05.html,v 1.10 2000/03/19 20:09:27 jcej Exp</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>