OSCL_EXPORT_REF ThreadSafeQueueId ThreadSafeQueue::AddToQueue(OsclAny *EventData, ThreadSafeQueueId* aId)
{
    iQueueMut.Lock();
    uint32 count = (aId) ? *aId : ++iCounter;
    ThreadSafeQueueElement elem(count, EventData);
    iQueue.push_back(elem);
    uint32 size = iQueue.size();
    iQueueMut.Unlock();

    //Signal the AO.  Only signal when the queue was previously empty in order
    // to minimize the amount of blocking in this call.
    if (size == 1)
    {
#if USE_SEM_WAIT
        //Wait on the AO to be ready to be signaled.
        iQueueReadySem.Wait();
        PendComplete(OSCL_REQUEST_ERR_NONE);
#else
        //To avoid problems under brew applet, don't do a sem wait here.
        //instead just check AO status and signal if needed.  It should
        //not be possible to lose data, since the only time AO is *not* ready
        //to be signaled is when a notification is already pending.
        //The reason to not do this in all platforms is that Status() call
        //is not thread-safe, but on non-preemptive OS it's ok here.
        if (Status() == OSCL_REQUEST_PENDING)
            PendComplete(OSCL_REQUEST_ERR_NONE);
#endif
    }

    return count;
}
void OsclAcceptRequest::Accept(OsclSocketI &aSocket)
{
    OsclAny *p = NewRequest(sizeof(AcceptParam));
    if (!p)
        PendComplete(OsclErrNoMemory);
    else
    {
        iParam = OSCL_PLACEMENT_NEW(p, AcceptParam(aSocket));
        if (!iParam)
            PendComplete(OsclErrNoMemory);
        else
            SocketI()->Accept(*Param(), *this);
    }
}
void OsclSendToRequest::SendTo(const uint8* &aPtr, uint32 aLen, OsclNetworkAddress &aAddress)
{
    OsclAny *p = NewRequest(sizeof(SendToParam));
    if (!p)
        PendComplete(OsclErrNoMemory);
    else
    {
        iParam = OSCL_PLACEMENT_NEW(p, SendToParam(aPtr, aLen, aAddress, 0));
        if (!iParam)
            PendComplete(OsclErrNoMemory);
        else
            SocketI()->SendTo(*Param(), *this);
    }
}
void OsclConnectRequest::Connect(OsclNetworkAddress &aAddress)
{
    OsclAny *p = NewRequest(sizeof(ConnectParam));
    if (!p)
        PendComplete(OsclErrNoMemory);
    else
    {
        iParam = OSCL_PLACEMENT_NEW(p, ConnectParam(aAddress));
        if (!iParam)
            PendComplete(OsclErrNoMemory);
        else
        {
            SocketI()->Connect(*Param(), *this);
        }
    }
}
void OsclGetHostByNameRequest::GetHostByName(char *name, OsclNetworkAddress *addr, Oscl_Vector<OsclNetworkAddress, OsclMemAllocator> *aAddressList)
{
    NewRequest();

    if (iParam)
        iParam->RemoveRef();
    iParam = NULL;

    if (!name || !addr)
    {
        PendComplete(OsclErrGeneral);
        return;
    }

    iParam = GetHostByNameParam::Create(name, addr, aAddressList);
    if (!iParam)
        PendComplete(OsclErrNoMemory);
    else
        iDNSI->GetHostByName(*iParam, *this);
}
void LipSyncDummyOutputMIO::QueueCommandResponse(CommandResponse& aResp)
{
    PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE,
                    (0, "LipSyncDummyOutputMIO::QueueCommandResponse(), aResp.CmdId is %d ", aResp.iCmdId));
    //queue a command response and schedule processing.
    iCommandResponseQueue.push_back(aResp);

    //schedule the AO.
    if (!IsBusy())
        PendForExec();
    if (IsAdded() && iStatus == OSCL_REQUEST_PENDING)
        PendComplete(OSCL_REQUEST_ERR_NONE);
}