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::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::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.

1487  {
1488  }
#define NULL
Definition: corecrt.h:158
template<class _LinkRegistry>
Concurrency::source_link_manager< _LinkRegistry >::~source_link_manager ( )
inline

Destroys the source_link_manager object.

1495  {
1497  }
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
size_t _Size() const
Definition: agents.h:354

Member Function Documentation

template<class _LinkRegistry>
void Concurrency::source_link_manager< _LinkRegistry >::_To_array ( ::Concurrency::details::_Dynamic_array< _EType > &  _Array)
inlineprivate
1710  {
1711  _LockHolder _Lock(_M_lock);
1712  _M_iteratorCount++;
1713 
1714  for(auto _Link = _M_links.begin(); *_Link != NULL; ++_Link)
1715  {
1716  _Array._Push_back(*_Link);
1717  }
1718  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
void _Push_back(_Type const &_Element)
Definition: agents.h:319
#define NULL
Definition: corecrt.h:158
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.
1532  {
1533  if (_Link == NULL)
1534  {
1535  return;
1536  }
1537 
1538  {
1539  _LockHolder _Lock(_M_lock);
1540  _M_links.add(_Link);
1541 
1542  // We need to add the _Link first and then invoke the
1543  // callback because _Add could throw.
1544 
1545  // As soon as the above lock is released, remove would
1546  // find the link that was added and could unlink it before
1547  // we are able to invoke the notification below. Keeping an
1548  // active iterator would prevent that from happening.
1549  _M_iteratorCount++;
1550  }
1551 
1552  // Acquire a reference on this link by the target
1553  _Link->acquire_ref(_M_pLinkedTarget);
1554 
1555  // Release the active iterator
1556  release();
1557  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
#define NULL
Definition: corecrt.h:158
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.
1701  {
1702  return (iterator(this, 0));
1703  }
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.
1671  {
1672  _LockHolder _Lock(_M_lock);
1673  return _M_links.contains(_Link);
1674  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
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.
1684  {
1685  _LockHolder _Lock(_M_lock);
1686  return _M_links.count();
1687  }
template<class _LinkRegistry>
void Concurrency::source_link_manager< _LinkRegistry >::reference ( )
inline

Acquires a reference on the source_link_manager object.

1619  {
1620  _LockHolder _Lock(_M_lock);
1621  _M_iteratorCount++;
1622  }
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.
1507  {
1508  _M_pLinkedTarget = _PTarget;
1509  }
template<class _LinkRegistry>
void Concurrency::source_link_manager< _LinkRegistry >::release ( )
inline

Releases the reference on the source_link_manager object.

1629  {
1630  ITarget<typename _Block::source_type> * _LinkedTarget = _M_pLinkedTarget;
1632 
1633  {
1634  _LockHolder _Lock(_M_lock);
1636  _M_iteratorCount--;
1637 
1638  if (_M_iteratorCount == 0)
1639  {
1640  if (_M_pendingRemove._Size() > 0)
1641  {
1642  // Snap the pending remove list with the lock held
1643  _M_pendingRemove._Swap(_LinksToRemove);
1644  }
1645  }
1646  }
1647 
1648  // NOTE: touching "this" pointer is dangerous as soon as the above lock is released
1649 
1650  // Release the references
1651  size_t _Size = _LinksToRemove._Size();
1652 
1653  for (size_t _I=0; _I < _Size; _I++)
1654  {
1655  _LinksToRemove[_I]->release_ref(_LinkedTarget);
1656  }
1657  }
void _Swap(_Myt &_Right)
Definition: agents.h:362
#define _CONCRT_ASSERT(x)
Definition: concrt.h:123
_CRT_BEGIN_C_HEADER _Check_return_ _Ret_maybenull_ _In_ size_t _Size
Definition: corecrt_malloc.h:58
size_t _Size() const
Definition: agents.h:354
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.
1570  {
1571  bool _Removed = false;
1572  _EType _RemovedLink = NULL;
1573  ITarget<typename _Block::source_type> * _LinkedTarget = _M_pLinkedTarget;
1574 
1575  if (_Link == NULL)
1576  {
1577  return false;
1578  }
1579 
1580  {
1581  _LockHolder _Lock(_M_lock);
1582  _Removed = _M_links.remove(_Link);
1583 
1584  if (!_Removed)
1585  {
1586  // No change was made
1587  return _Removed;
1588  }
1589 
1590  if (_M_iteratorCount == 0)
1591  {
1592  // Set the removed link to indicate that
1593  // notification callback needs to be invoked.
1594  _RemovedLink = _Link;
1595  }
1596  else
1597  {
1598  // The iterator will complete the pending operation
1600  }
1601  }
1602 
1603  // NOTE: touching "this" pointer is dangerous as soon as the above lock is released
1604 
1605  // Release the reference for this link
1606  if (_RemovedLink != NULL)
1607  {
1608  _RemovedLink->release_ref(_LinkedTarget);
1609  }
1610 
1611  return _Removed;
1612  }
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t *, const wchar_t *)
void _Push_back(_Type const &_Element)
Definition: agents.h:319
#define NULL
Definition: corecrt.h:158
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.
1520  {
1521  _M_links.set_bound(_MaxLinks);
1522  }

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: