// called from main thread only
NS_IMETHODIMP
nsSocketTransportService::Shutdown()
{
    LOG(("nsSocketTransportService::Shutdown\n"));

    NS_ASSERTION(nsIThread::IsMainThread(), "wrong thread");

    if (!mInitialized)
        return NS_OK;

    {
        nsAutoLock lock(mEventQLock);

        // signal uninitialized to block further events
        mInitialized = PR_FALSE;

        if (mThreadEvent)
            PR_SetPollableEvent(mThreadEvent);
        // else wait for Poll timeout
    }

    // join with thread
    mThread->Join();
    NS_RELEASE(mThread);

    return NS_OK;
}
NS_IMETHODIMP
nsSocketTransportService::PostEvent(PLEvent *event)
{
    LOG(("nsSocketTransportService::PostEvent [event=%p]\n", event));

    NS_ASSERTION(event, "null event");

    nsAutoLock lock(mEventQLock);
    if (!mInitialized) {
        // Allow socket detach handlers to post events
        if (!mShuttingDown || (PR_GetCurrentThread() != gSocketThread)) {
            NS_WARN_IF_FALSE(PR_GetCurrentThread() != gSocketThread,
                            "Rejecting event posted to uninitialized sts");
            return NS_ERROR_OFFLINE;
        }

    }

    PR_APPEND_LINK(&event->link, &mEventQ);

    if (mThreadEvent)
        PR_SetPollableEvent(mThreadEvent);
    // else wait for Poll timeout
    return NS_OK;
}
NS_IMETHODIMP
nsSocketTransportService::OnDispatchedEvent(nsIThreadInternal *thread)
{
    nsAutoLock lock(mLock);
    if (mThreadEvent)
        PR_SetPollableEvent(mThreadEvent);
    return NS_OK;
}
示例#4
0
文件: prtpool.c 项目: Akesure/jxcore
static void
notify_ioq(PRThreadPool *tp)
{
PRStatus rval_status;

	/*
	 * wakeup the io thread(s)
	 */
	rval_status = PR_SetPollableEvent(tp->ioq.notify_fd);
	PR_ASSERT(PR_SUCCESS == rval_status);
}
示例#5
0
nsresult
IPC_SendMsg(ipcMessage *msg)
{
    if (!gConnState || !gConnThread)
        return NS_ERROR_NOT_INITIALIZED;

    PR_Lock(gConnState->lock);
    gConnState->send_queue.Append(msg);
    PR_SetPollableEvent(gConnState->fds[POLL].fd);
    PR_Unlock(gConnState->lock);

    return NS_OK;
}
示例#6
0
nsresult
IPC_DoCallback(ipcCallbackFunc func, void *arg)
{
    if (!gConnState || !gConnThread)
        return NS_ERROR_NOT_INITIALIZED;

    ipcCallback *callback = new ipcCallback;
    if (!callback)
        return NS_ERROR_OUT_OF_MEMORY;
    callback->func = func;
    callback->arg = arg;

    PR_Lock(gConnState->lock);
    gConnState->callback_queue.Append(callback);
    PR_SetPollableEvent(gConnState->fds[POLL].fd);
    PR_Unlock(gConnState->lock);
    return NS_OK;
}
// called from main thread only
NS_IMETHODIMP
nsSocketTransportService::Shutdown()
{
    LOG(("nsSocketTransportService::Shutdown\n"));

    NS_ENSURE_STATE(NS_IsMainThread());

    if (!mInitialized)
        return NS_OK;

    if (mShuttingDown)
        return NS_ERROR_UNEXPECTED;

    {
        nsAutoLock lock(mLock);

        // signal the socket thread to shutdown
        mShuttingDown = PR_TRUE;

        if (mThreadEvent)
            PR_SetPollableEvent(mThreadEvent);
        // else wait for Poll timeout
    }

    // join with thread
    mThread->Shutdown();
    {
        nsAutoLock lock(mLock);
        // Drop our reference to mThread and make sure that any concurrent
        // readers are excluded
        mThread = nsnull;
    }

    nsCOMPtr<nsIPrefBranch2> tmpPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
    if (tmpPrefService) 
        tmpPrefService->RemoveObserver(SEND_BUFFER_PREF, this);

    mInitialized = PR_FALSE;
    mShuttingDown = PR_FALSE;

    return NS_OK;
}
示例#8
0
nsresult
IPC_Disconnect()
{
    // Must disconnect on same thread used to connect!
    PR_ASSERT(gMainThread == PR_GetCurrentThread());

    if (!gConnState || !gConnThread)
        return NS_ERROR_NOT_INITIALIZED;

    PR_Lock(gConnState->lock);
    gConnState->shutdown = PR_TRUE;
    PR_SetPollableEvent(gConnState->fds[POLL].fd);
    PR_Unlock(gConnState->lock);

    PR_JoinThread(gConnThread);

    ConnDestroy(gConnState);

    gConnState = NULL;
    gConnThread = NULL;
    return NS_OK;
}