Exemplo n.º 1
0
// For each group, updates the call.
// Queues each group that isn't already queued.
// Caller must acquire the group read lock.
//
void ListenersBase::Proxy::update (Call* const c, const timestamp_t timestamp)
{
  // why would we even want to be called?
  jassert (!m_entries.empty());

  // With the read lock, this list can't change on us unless someone
  // adds a listener to a new thread queue in response to a call.
  for (Entries::iterator iter = m_entries.begin(); iter != m_entries.end();)
  {
    Entry* entry = &(*iter++);

    // Manually add a reference since we use a raw pointer
    c->incReferenceCount ();

    // Atomically exchange the new call for the old one
    Call* old = entry->call.exchange (c);

    // If no old call then they need to be queued
    if (!old)
    {
      CallQueue& callQueue = entry->group->getCallQueue();
      callQueue.callp (new (callQueue.getAllocator ()) Work (this, entry, timestamp));
    }
    else
    {
      old->decReferenceCount ();
    }
  }
}