Esempio n. 1
0
void SqlDelayThread::run()
{
#ifndef DO_POSTGRESQL
    mysql_thread_init();
#endif

    const uint32 loopSleepms = 10;

    const uint32 pingEveryLoop = m_dbEngine->GetPingIntervall() / loopSleepms;

    uint32 loopCounter = 0;
    while (m_running)
    {
        // if the running state gets turned off while sleeping
        // empty the queue before exiting
        ACE_Based::Thread::Sleep(loopSleepms);

        ProcessRequests();

        if ((loopCounter++) >= pingEveryLoop)
        {
            loopCounter = 0;
            m_dbEngine->Ping();
        }
    }

#ifndef DO_POSTGRESQL
    mysql_thread_end();
#endif
}
Esempio n. 2
0
    void ResourceManager::Destroy()
    {
        ProcessRequests();

#if defined( CARBON_DEBUG )
        if ( resourceTable.Count() )
        {
            Array< Resource *, FrameAllocator > unreleased;
            resourceTable.Dump( unreleased );

            Char res_msg[512];

            CARBON_TRACE( "====================================================\n" );
            CARBON_TRACE( "# Some resources are leaking\n\n" );

            Array< Resource * >::Iterator it = unreleased.Begin();
            Array< Resource * >::ConstIterator end = unreleased.End();
            for ( ; it != end; ++it )
            {
                Resource * res = *it;

                StringUtils::FormatString( res_msg, sizeof(res_msg), "# %s | ref count : %d\n", res->GetName(), res->GetRefCount() );
                CARBON_TRACE( res_msg );
            }

            CARBON_TRACE( "\n====================================================\n" );
        }
#endif
        CARBON_ASSERT( resourceTable.Count() == 0 );
    }
Esempio n. 3
0
int OverlappedCall::Main()
{
	int ret;

	if (beStarted())
		ret = ProcessRequests();
	else
	{
		// Terminated even before the try block could be entered. This will happen if the beStarted() call
		// found that the state had already transitioned away from the Starting state, probably to the
		// Terminated state.
		NotifyInterpreterOfTermination();
		ret = -1;
	}

	return ret;
}
void CThreadWithRequestsAndTimers::LoopFunction()
{
	// Define constants for events.
	const int TerminateThread = WAIT_OBJECT_0;     
	const int InputMessage    = WAIT_OBJECT_0 + 1;  

	HANDLE WaitHandles[2];
	WaitHandles[0] = m_CloseEvent;
	WaitHandles[1] = m_Queue;
    int NextTimoutTime = TIMEOUT_TIME;

	OnThreadStart();
	while (true)
	{
        LogThreadPerformance();

		//wait for close event, queue item or timer that elapsed
		int Result = WaitForMultipleObjects(2, WaitHandles, FALSE, NextTimoutTime);
        NextTimoutTime = TIMEOUT_TIME; // reset the next timeout time

        if (Result == TerminateThread)
        {
            HandleThreadClose();
            return; // This will terminate the thread
        }

        if (Result == InputMessage)
            //requests are waiting - Start processing them
            ProcessRequests();

        // In any case check if need to process timers
        if (ShouldProcessTimers() == true)
        {
            m_LastProcessTimers = GetTickCount();
            CTimingCenter::ProcessTimers(TIMERS_MAX_EXECUTION_TIME, NextTimoutTime);
        }

        // Calls the thread's function that should provide the call to OnTimeout()
        HandleTimeout();
        // update the next timeout also according to the timeout val.
        NextTimoutTime = min(NextTimoutTime, (int)m_TimeoutInMilli);

	} // while
}
Esempio n. 5
0
	void CoreService::ProcessElevatedRequests ()
	{
		int pid = fork();
		throw_sys_if (pid == -1);
		if (pid == 0)
		{
			try
			{
				int f = open ("/dev/null", 0);
				throw_sys_sub_if (f == -1, "/dev/null");
				throw_sys_if (dup2 (f, STDERR_FILENO) == -1);

				// Wait for sync code
				while (true)
				{
					byte b;
					throw_sys_if (read (STDIN_FILENO, &b, 1) != 1);
					if (b != 0x00)
						continue;
					
					throw_sys_if (read (STDIN_FILENO, &b, 1) != 1);
					if (b != 0x11)
						continue;
					
					throw_sys_if (read (STDIN_FILENO, &b, 1) != 1);
					if (b == 0x22)
						break;
				}

				ElevatedPrivileges = true;
				ProcessRequests (STDIN_FILENO, STDOUT_FILENO);
				_exit (0);
			}
			catch (exception &e)
			{
#ifdef DEBUG
				SystemLog::WriteException (e);
#endif
			}
			catch (...)	{ }
			_exit (1);
		}
	}
Esempio n. 6
0
DWORD
CAsyncIo::ThreadProc(void)
{
    HANDLE ahev[] = {m_evStop, m_evWork};

    for (;;) {
	DWORD dw = WaitForMultipleObjects(
		    2,
		    ahev,
		    FALSE,
		    INFINITE);
	if (dw == WAIT_OBJECT_0+1) {

	    
	    ProcessRequests();
	} else {
	    
	    return 0;
	}
    }
}
Esempio n. 7
0
// the thread proc - assumes that DWORD thread param is the
// this pointer
DWORD
CAsyncIo::ThreadProc(void)
{
    HANDLE ahev[] = {m_evStop, m_evWork};

    for (;;) {
	DWORD dw = WaitForMultipleObjects(
		    2,
		    ahev,
		    FALSE,
		    INFINITE);
	if (dw == WAIT_OBJECT_0+1) {

	    // requests need processing
	    ProcessRequests();
	} else {
	    // any error or stop event - we should exit
	    return 0;
	}
    }
}
Esempio n. 8
0
void service(void)
{
    TCPSOCKET *sock;
    FILE *stream;

    /*
     * Loop endless for connections.
     */
    for (;;) {
        /*
         * Create a socket.
         */
        sock = NutTcpCreateSocket();

        /*
         * Listen at the configured port. If we return, we got a client.
         */
        NutTcpAccept(sock, MY_PORT);

        /*
         * Create a stream from the socket.
         */
        stream = _fdopen((int) sock, "r+b");

        /*
         * Process client requests.
         */
        ProcessRequests(stream);

        /*
         * Destroy our device.
         */
        fclose(stream);

        /*
         * Close our socket.
         */
        NutTcpCloseSocket(sock);
    }
}
Esempio n. 9
0
SqlDelayThread::~SqlDelayThread()
{
    // process all requests which might have been queued while thread was stopping
    ProcessRequests();
}
Esempio n. 10
0
 void ResourceManager::Update()
 {
     ProcessRequests();
 }