STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Concurrency::source_link_manager< _LinkRegistry > Class Template Reference

The source_link_manager object manages messaging block network links to ISource blocks. More...

#include <agents.h>

Public Types

typedef _LinkRegistry type
 The type of link registry being managed by the source_link_manager object. More...
 
typedef _LinkRegistry::type _Block
 The type of the blocks being managed by the source_link_manager object. More...
 
typedef std::tr1::function< void(_Block *, bool)> _Callback_method
 The method signature for a callback method for this source_link_manager object. More...
 
typedef _Block_EType
 A type that represents a pointer to an element stored in the source_link_manager object. More...
 
typedef _EType const & const_reference
 A type that provides a reference to a const element stored in a source_link_manager object for reading and performing const operations. More...
 
typedef _EType const * const_pointer
 A type that provides a pointer to a const element in a source_link_manager object. More...
 
typedef _Source_link_iterator< _LinkRegistry > iterator
 A type that provides an iterator that can read or modify any element in the source_link_manager object. More...
 
typedef ::Concurrency::details::_ReentrantPPLLock _LockType
 A type that provides a reentrant lock for the source_link_manager object. More...
 
typedef _LockType::_Scoped_lock _LockHolder
 A type that provides a RAII scoped lock holder for a lock. More...
 

Public Member Functions

 source_link_manager ()
 Constructs a source_link_manager object. More...
 
 ~source_link_manager ()
 Destroys the source_link_manager object. More...
 
void register_target_block (_Inout_ ITarget< typename _Block::source_type > *_PTarget)
 Registers the target block that holds this source_link_manager object. More...
 
void set_bound (size_t _MaxLinks)
 Sets the maximum number of source links that can be added to this source_link_manager object. More...
 
void add (_EType _Link)
 Adds a source link to the source_link_manager object. More...
 
bool remove (_EType _Link)
 Removes a link from the source_link_manager object. More...
 
void reference ()
 Acquires a reference on the source_link_manager object. More...
 
void release ()
 Releases the reference on the source_link_manager object. More...
 
bool contains (_EType _Link)
 Searches the network_link_registry within this source_link_manager object for a specified block. More...
 
size_t count ()
 Counts the number of linked blocks in the source_link_manager object. More...
 
iterator begin ()
 Returns an iterator to the first element in the source_link_manager object. More...
 

Private Member Functions

void _To_array (::Concurrency::details::_Dynamic_array< _EType > &_Array)
 

Private Attributes

_LockType _M_lock
 
volatile long _M_iteratorCount
 
::Concurrency::details::_Dynamic_array< _EType_M_pendingRemove
 
_LinkRegistry _M_links
 
ITarget< typename _Block::source_type > *volatile _M_pLinkedTarget
 

Friends

class _Source_link_iterator< _LinkRegistry >
 

Detailed Description

template<class _LinkRegistry>
class Concurrency::source_link_manager< _LinkRegistry >

The source_link_manager object manages messaging block network links to ISource blocks.

Template Parameters
_LinkRegistryThe network link registry.

Currently, the source blocks are reference counted. This is a wrapper on a network_link_registry object that allows concurrent access to the links and provides the ability to reference the links through callbacks. Message blocks (target_blocks or propagator_blocks) should use this class for their source links.

See also
single_link_registry Class, multi_link_registry Class

Member Typedef Documentation

template<class _LinkRegistry>
typedef _LinkRegistry::type Concurrency::source_link_manager< _LinkRegistry >::_Block

The type of the blocks being managed by the source_link_manager object.

template<class _LinkRegistry>
typedef std::tr1::function<void(_Block *, bool)> Concurrency::source_link_manager< _LinkRegistry >::_Callback_method

The method signature for a callback method for this source_link_manager object.

template<class _LinkRegistry>
typedef _Block* Concurrency::source_link_manager< _LinkRegistry >::_EType

A type that represents a pointer to an element stored in the source_link_manager object.

template<class _LinkRegistry>
typedef _LockType::_Scoped_lock Concurrency::source_link_manager< _LinkRegistry >::_LockHolder

A type that provides a RAII scoped lock holder for a lock.

template<class _LinkRegistry>
typedef ::Concurrency::details::_ReentrantPPLLock Concurrency::source_link_manager< _LinkRegistry >::_LockType

A type that provides a reentrant lock for the source_link_manager object.

template<class _LinkRegistry>
typedef _EType const* Concurrency::source_link_manager< _LinkRegistry >::const_pointer

A type that provides a pointer to a const element in a source_link_manager object.

template<class _LinkRegistry>
typedef _EType const& Concurrency::source_link_manager< _LinkRegistry >::const_reference

A type that provides a reference to a const element stored in a source_link_manager object for reading and performing const operations.

template<class _LinkRegistry>
typedef _Source_link_iterator<_LinkRegistry> Concurrency::source_link_manager< _LinkRegistry >::iterator

A type that provides an iterator that can read or modify any element in the source_link_manager object.

template<class _LinkRegistry>
typedef _LinkRegistry Concurrency::source_link_manager< _LinkRegistry >::type

The type of link registry being managed by the source_link_manager object.

Constructor & Destructor Documentation

template<class _LinkRegistry>
Concurrency::source_link_manager< _LinkRegistry >::source_link_manager ( )
inline

Constructs a source_link_manager object.

1486  {
1487  }
#define NULL
Definition: crtdbg.h:30
template<class _LinkRegistry>
Concurrency::source_link_manager< _LinkRegistry >::~source_link_manager ( )
inline

Destroys the source_link_manager object.

1494  {
1496  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
size_t _Size() const
Definition: agents.h:353

Member Function Documentation

template<class _LinkRegistry>
void Concurrency::source_link_manager< _LinkRegistry >::_To_array ( ::Concurrency::details::_Dynamic_array< _EType > &  _Array)
inlineprivate
1709  {
1710  _LockHolder _Lock(_M_lock);
1711  _M_iteratorCount++;
1712 
1713  for(_LinkRegistry::iterator _Link = _M_links.begin(); *_Link != NULL; _Link++)
1714  {
1715  _Array._Push_back(*_Link);
1716  }
1717  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
void _Push_back(_Type const &_Element)
Definition: agents.h:318
#define NULL
Definition: crtdbg.h:30
template<class _LinkRegistry>
void Concurrency::source_link_manager< _LinkRegistry >::add ( _EType  _Link)
inline

Adds a source link to the source_link_manager object.

Parameters
_LinkA pointer to a block to be added.
1531  {
1532  if (_Link == NULL)
1533  {
1534  return;
1535  }
1536 
1537  {
1538  _LockHolder _Lock(_M_lock);
1539  _M_links.add(_Link);
1540 
1541  // We need to add the _Link first and then invoke the
1542  // callback because _Add could throw.
1543 
1544  // As soon as the above lock is released, remove would
1545  // find the link that was added and could unlink it before
1546  // we are able to invoke the notification below. Keeping an
1547  // active iterator would prevent that from happening.
1548  _M_iteratorCount++;
1549  }
1550 
1551  // Acquire a reference on this link by the target
1552  _Link->acquire_ref(_M_pLinkedTarget);
1553 
1554  // Release the active iterator
1555  release();
1556  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
#define NULL
Definition: crtdbg.h:30
template<class _LinkRegistry>
iterator Concurrency::source_link_manager< _LinkRegistry >::begin ( )
inline

Returns an iterator to the first element in the source_link_manager object.

The end state of the iterator is indicated by a NULL link.

Returns
An iterator addressing the first element in the source_link_manager object.
1700  {
1701  return (iterator(this, 0));
1702  }
template<class _LinkRegistry>
bool Concurrency::source_link_manager< _LinkRegistry >::contains ( _EType  _Link)
inline

Searches the network_link_registry within this source_link_manager object for a specified block.

Parameters
_LinkA pointer to a block that is to be searched for in the source_link_manager object.
Returns
true if the specified block was found, false otherwise.
1670  {
1671  _LockHolder _Lock(_M_lock);
1672  return _M_links.contains(_Link);
1673  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
template<class _LinkRegistry>
size_t Concurrency::source_link_manager< _LinkRegistry >::count ( )
inline

Counts the number of linked blocks in the source_link_manager object.

Returns
The number of linked blocks in the source_link_manager object.
1683  {
1684  _LockHolder _Lock(_M_lock);
1685  return _M_links.count();
1686  }
template<class _LinkRegistry>
void Concurrency::source_link_manager< _LinkRegistry >::reference ( )
inline

Acquires a reference on the source_link_manager object.

1618  {
1619  _LockHolder _Lock(_M_lock);
1620  _M_iteratorCount++;
1621  }
template<class _LinkRegistry>
void Concurrency::source_link_manager< _LinkRegistry >::register_target_block ( _Inout_ ITarget< typename _Block::source_type > *  _PTarget)
inline

Registers the target block that holds this source_link_manager object.

Parameters
_PTargetThe target block holding this source_link_manager object.
1506  {
1507  _M_pLinkedTarget = _PTarget;
1508  }
template<class _LinkRegistry>
void Concurrency::source_link_manager< _LinkRegistry >::release ( )
inline

Releases the reference on the source_link_manager object.

1628  {
1629  ITarget<typename _Block::source_type> * _LinkedTarget = _M_pLinkedTarget;
1631 
1632  {
1633  _LockHolder _Lock(_M_lock);
1635  _M_iteratorCount--;
1636 
1637  if (_M_iteratorCount == 0)
1638  {
1639  if (_M_pendingRemove._Size() > 0)
1640  {
1641  // Snap the pending remove list with the lock held
1642  _M_pendingRemove._Swap(_LinksToRemove);
1643  }
1644  }
1645  }
1646 
1647  // NOTE: touching "this" pointer is dangerous as soon as the above lock is released
1648 
1649  // Release the references
1650  size_t _Size = _LinksToRemove._Size();
1651 
1652  for (size_t _I=0; _I < _Size; _I++)
1653  {
1654  _LinksToRemove[_I]->release_ref(_LinkedTarget);
1655  }
1656  }
void _Swap(_Myt &_Right)
Definition: agents.h:361
#define _CONCRT_ASSERT(x)
Definition: concrt.h:137
size_t _Size() const
Definition: agents.h:353
_Check_return_ _In_ long _Size
Definition: io.h:325
template<class _LinkRegistry>
bool Concurrency::source_link_manager< _LinkRegistry >::remove ( _EType  _Link)
inline

Removes a link from the source_link_manager object.

Parameters
_LinkA pointer to a block to be removed, if found.
Returns
true if the link was found and removed, false otherwise.
1569  {
1570  bool _Removed = false;
1571  _EType _RemovedLink = NULL;
1572  ITarget<typename _Block::source_type> * _LinkedTarget = _M_pLinkedTarget;
1573 
1574  if (_Link == NULL)
1575  {
1576  return false;
1577  }
1578 
1579  {
1580  _LockHolder _Lock(_M_lock);
1581  _Removed = _M_links.remove(_Link);
1582 
1583  if (!_Removed)
1584  {
1585  // No change was made
1586  return _Removed;
1587  }
1588 
1589  if (_M_iteratorCount == 0)
1590  {
1591  // Set the removed link to indicate that
1592  // notification callback needs to be invoked.
1593  _RemovedLink = _Link;
1594  }
1595  else
1596  {
1597  // The iterator will complete the pending operation
1599  }
1600  }
1601 
1602  // NOTE: touching "this" pointer is dangerous as soon as the above lock is released
1603 
1604  // Release the reference for this link
1605  if (_RemovedLink != NULL)
1606  {
1607  _RemovedLink->release_ref(_LinkedTarget);
1608  }
1609 
1610  return _Removed;
1611  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const char *, const char *)
void _Push_back(_Type const &_Element)
Definition: agents.h:318
#define NULL
Definition: crtdbg.h:30
template<class _LinkRegistry>
void Concurrency::source_link_manager< _LinkRegistry >::set_bound ( size_t  _MaxLinks)
inline

Sets the maximum number of source links that can be added to this source_link_manager object.

Parameters
_MaxLinksThe maximum number of links.
1519  {
1520  _M_links.set_bound(_MaxLinks);
1521  }

Friends And Related Function Documentation

template<class _LinkRegistry>
friend class _Source_link_iterator< _LinkRegistry >
friend

Member Data Documentation

template<class _LinkRegistry>
volatile long Concurrency::source_link_manager< _LinkRegistry >::_M_iteratorCount
private
template<class _LinkRegistry>
_LinkRegistry Concurrency::source_link_manager< _LinkRegistry >::_M_links
private
template<class _LinkRegistry>
_LockType Concurrency::source_link_manager< _LinkRegistry >::_M_lock
private
template<class _LinkRegistry>
::Concurrency::details::_Dynamic_array<_EType> Concurrency::source_link_manager< _LinkRegistry >::_M_pendingRemove
private
template<class _LinkRegistry>
ITarget<typename _Block::source_type>* volatile Concurrency::source_link_manager< _LinkRegistry >::_M_pLinkedTarget
private

The documentation for this class was generated from the following file: