예제 #1
0
bool
Open(const PrivateIPDLInterface&,
     MessageChannel* aOpenerChannel, ProcessId aOtherProcessId,
     Transport::Mode aOpenerMode,
     ProtocolId aProtocol, ProtocolId aChildProtocol)
{
  bool isParent = (Transport::MODE_SERVER == aOpenerMode);
  ProcessId thisPid = GetCurrentProcId();
  ProcessId parentId = isParent ? thisPid : aOtherProcessId;
  ProcessId childId = !isParent ? thisPid : aOtherProcessId;
  if (!parentId || !childId) {
    return false;
  }

  TransportDescriptor parentSide, childSide;
  if (!CreateTransport(parentId, &parentSide, &childSide)) {
    return false;
  }

  Message* parentMsg = new ChannelOpened(parentSide, childId, aProtocol);
  Message* childMsg = new ChannelOpened(childSide, parentId, aChildProtocol);
  nsAutoPtr<Message> messageForUs(isParent ? parentMsg : childMsg);
  nsAutoPtr<Message> messageForOtherSide(!isParent ? parentMsg : childMsg);
  if (!aOpenerChannel->Echo(messageForUs.forget()) ||
      !aOpenerChannel->Send(messageForOtherSide.forget())) {
    CloseDescriptor(parentSide);
    CloseDescriptor(childSide);
    return false;
  }
  return true;
}
예제 #2
0
    int StatsTable::RegisterThread(const std::string& name)
    {
        int slot = 0;
        if(!impl_)
        {
            return 0;
        }

        // Registering a thread requires that we lock the shared memory
        // so that two threads don't grab the same slot.  Fortunately,
        // thread creation shouldn't happen in inner loops.
        {
            SharedMemoryAutoLock lock(impl_->shared_memory());
            slot = FindEmptyThread();
            if(!slot)
            {
                return 0;
            }

            // We have space, so consume a column in the table.
            std::string thread_name = name;
            if(name.empty())
            {
                thread_name = kUnknownName;
            }
            strlcpy(impl_->thread_name(slot), thread_name.c_str(),
                kMaxThreadNameLength);
            *(impl_->thread_tid(slot)) = PlatformThread::CurrentId();
            *(impl_->thread_pid(slot)) = GetCurrentProcId();
        }

        // Set our thread local storage.
        TLSData* data = new TLSData;
        data->table = this;
        data->slot = slot;
        tls_index_.Set(data);
        return slot;
    }