コード例 #1
0
ファイル: vf_Listeners.cpp プロジェクト: ZECTBynmo/VFLib
// Search for an existing Proxy that matches the pointer to
// member and replace it's Call, or create a new Proxy for it.
//
void ListenersBase::updatep (void const* const member,
                             const size_t bytes, Call::Ptr cp)
{
  Call* c = cp;

  ReadWriteMutex::ScopedReadLockType lock (m_groups_mutex);

  if (!m_groups.empty ())
  {
    Proxy* proxy;
    
    {
      ReadWriteMutex::ScopedReadLockType lock (m_proxies_mutex);

      // See if there's already a proxy
      proxy = find_proxy (member, bytes);
    }

    // Possibly create one
    if (!proxy)
    {
      ReadWriteMutex::ScopedWriteLockType lock (m_proxies_mutex);

      // Have to search for it again in case someone else added it
      proxy = find_proxy (member, bytes);

      if (!proxy)
      {
        // Create a new empty proxy
        proxy = new (m_allocator) Proxy (member, bytes);

        // Add all current groups to the Proxy.
        // We need the group read lock for this (caller provided).
        for (Groups::iterator iter = m_groups.begin(); iter != m_groups.end();)
        {
          Group* group = &(*iter++);
          proxy->add (group, *m_allocator);
        }

        // Add it to the list.
        m_proxies.push_front (*proxy);
      }
    }

    // Requires the group read lock
    proxy->update (c, m_timestamp);
  }
}