Beispiel #1
0
void tst_QWriteLocker::unlockAndRelockTest()
{
    class UnlockAndRelockThread : public tst_QWriteLockerThread
    {
    public:
        void run()
        {
            QWriteLocker locker(&lock);

            waitForTest();

            locker.unlock();

            waitForTest();

            locker.relock();

            waitForTest();
        }
    };

    thread = new UnlockAndRelockThread;
    thread->start();

    waitForThread();
    // lock should be locked by the QWriteLocker
    QVERIFY(!thread->lock.tryLockForWrite());
    releaseThread();

    waitForThread();
    // lock has been explicitly unlocked via QWriteLocker
    QVERIFY(thread->lock.tryLockForWrite());
    thread->lock.unlock();
    releaseThread();

    waitForThread();
    // lock has been explicity relocked via QWriteLocker
    QVERIFY(!thread->lock.tryLockForWrite());
    releaseThread();

    QVERIFY(thread->wait());

    delete thread;
    thread = 0;
}
Beispiel #2
0
void tst_QMutexLocker::unlockAndRelockTest()
{
    class UnlockAndRelockThread : public tst_QMutexLockerThread
    {
    public:
        void run()
        {
            QMutexLocker locker(&mutex);

            waitForTest();

            locker.unlock();

            waitForTest();

            locker.relock();

            waitForTest();
        }
    };

    thread = new UnlockAndRelockThread;
    thread->start();

    waitForThread();
    // mutex should be locked by the QMutexLocker
    QVERIFY(!thread->mutex.tryLock());
    releaseThread();

    waitForThread();
    // mutex has been explicitly unlocked via QMutexLocker
    QVERIFY(thread->mutex.tryLock());
    thread->mutex.unlock();
    releaseThread();

    waitForThread();
    // mutex has been explicitly relocked via QMutexLocker
    QVERIFY(!thread->mutex.tryLock());
    releaseThread();

    QVERIFY(thread->wait());

    delete thread;
    thread = 0;
}
Beispiel #3
0
void tst_QWriteLocker::scopeTest()
{
    class ScopeTestThread : public tst_QWriteLockerThread
    {
    public:
        void run()
        {
            waitForTest();

            {
                QWriteLocker locker(&lock);
                waitForTest();
            }

            waitForTest();
        }
    };

    thread = new ScopeTestThread;
    thread->start();

    waitForThread();
    // lock should be unlocked before entering the scope that creates the QWriteLocker
    QVERIFY(thread->lock.tryLockForWrite());
    thread->lock.unlock();
    releaseThread();

    waitForThread();
    // lock should be locked by the QWriteLocker
    QVERIFY(!thread->lock.tryLockForWrite());
    releaseThread();

    waitForThread();
    // lock should be unlocked when the QWriteLocker goes out of scope
    QVERIFY(thread->lock.tryLockForWrite());
    thread->lock.unlock();
    releaseThread();

    QVERIFY(thread->wait());

    delete thread;
    thread = 0;
}
Beispiel #4
0
/* void *arg is a argumentReceivingThread_t type */
void receivingThread( void *arg )
{
    TRACE_2( SERVER , "receivingThread()");

    char buff[BUFF_SIZE];
    char input[] = "rdb_remote~>";
    int ret;
    void *cliRet;

    argumentReceivingThread_t *arguments = ( argumentReceivingThread_t * )arg;

    TRACE_3( SERVER , "Thread argument: socket: %d , port: %d" , arguments->socket , arguments->port );

    TRACE_1( SERVER , "[!]Receiving thread create !");

    if( arguments->port == PORT_CLI )
        sendVoidSocket( arguments->socket , input , sizeof( input ) );
    else
		TRACE_1( SERVER , "Port not used at the moment.\n");

    while( 1 )
    {
        memset( buff , 0 , BUFF_SIZE );

        ret = recv( arguments->socket , buff , BUFF_SIZE , 0 );

        if( ret > 0 )
        {

            if( arguments->port == PORT_CLI )
            {
                TRACE_3( SERVER , "[+]Data: %s" , buff );

                cliRet = doCommand( buff );

                if( cliRet != NULL )
                {
                    sendVoidSocket( arguments->socket , cliRet , strlen( ( const char * )cliRet ) );

                    zfree( cliRet );

//                    sendVoidSocket( arguments->socket , input , sizeof( input ) );
                }
            }
        }

    }

    TRACE_3( SERVER , "[!]Quitting receiving thread !");

    releaseThread();

    pthread_exit( NULL );
}
Beispiel #5
0
void tst_QWriteLocker::lockerStateTest()
{
    class LockerStateThread : public tst_QWriteLockerThread
    {
    public:
        void run()
        {
            {
                QWriteLocker locker(&lock);
                locker.relock();
                locker.unlock();

                waitForTest();
            }

            waitForTest();
        }
    };

    thread = new LockerStateThread;
    thread->start();

    waitForThread();
    // even though we relock() after creating the QWriteLocker, it shouldn't lock the lock more than once
    QVERIFY(thread->lock.tryLockForWrite());
    thread->lock.unlock();
    releaseThread();

    waitForThread();
    // if we call QWriteLocker::unlock(), its destructor should do nothing
    QVERIFY(thread->lock.tryLockForWrite());
    thread->lock.unlock();
    releaseThread();

    QVERIFY(thread->wait());

    delete thread;
    thread = 0;
}
Beispiel #6
0
void doMigration(SpuThreadData * spu_data, SpuJavaThreadData * thread, int spuId)
{	
	prepareMigration(spu_data, 
									 spuId,
									 thread->methodClassTocOffset,
									 thread->methodSubArchOffset,
									 thread->paramsStart,
									 thread->paramsLength);

	runMigratedMethod(spu_data, spuId, thread->retType);

	supportSPU(spu_data, thread, spuId);

	// thread is now complete
	thread->complete = 1;
	// release SPU to allow it to do more work
	releaseThread(spu_data, spuId);

	return;
}
void * threadCallFunction(void *arg) { 
    ThreadInfo tiInfo = (ThreadInfo)arg; 

	// Get commands from client.
	int wait_for_commands = 1;
	do {
		// Read a line from the client.
		char cmd[MAX_CMD_LEN];
		int status = recvline(tiInfo->clientsock, cmd, MAX_CMD_LEN);
		
		if (status != 0) {
			// Either an error occurred or the client closed the connection.
			wait_for_commands = 0;
		}
		else {
			// Handle the command from the client.
			int status = handle_command(tiInfo->clientsock, cmd, tiInfo->fileptr, tiInfo->params, tiInfo->headlist, &(tiInfo->auth_success));
	
			if (status != 0)
				wait_for_commands = 0; // Oops.  An error occured.
	
		}
		
	} while (wait_for_commands);  
  
  
	if (close(tiInfo->clientsock)<0) { 
	pthread_mutex_lock( &printMutex ); 
	printf("ERROR in closing socket to %s:%d.\n", 
	   inet_ntoa(tiInfo->clientaddr.sin_addr), tiInfo->clientaddr.sin_port);
	pthread_mutex_unlock( &printMutex ); 
	}
	releaseThread( tiInfo ); 


	return NULL; 
}
Beispiel #8
0
void createServer( void *port )
{
    TRACE_2( SERVERMANAGER , "createServer( %d )." , *( int * )port );

    int s_server = socket( AF_INET , SOCK_STREAM , 0 );
    int clients[MAX_CLIENT];
    int numClients;

    struct sockaddr_in serv_addr;
    argumentReceivingThread_t *args;

    if( s_server < 0 )
    {
        TRACE_ERROR( SERVERMANAGER , "[-]Error to create socket.");

        pthread_exit( ( void * )PC_ERROR );
    }

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl( INADDR_ANY );
    serv_addr.sin_port = htons( *( int * )port );

    if( bind( s_server , ( struct sockaddr* )&serv_addr, sizeof( serv_addr ) ) < 0 )
    {
        TRACE_ERROR( SERVERMANAGER , "[-]Error to bind on port: %d." , *( int * )port );

        pthread_exit( ( void * )PC_ERROR );
    }

    if( listen( s_server , 10 ) < 0 )
    {
        TRACE_ERROR( SERVERMANAGER , "[-]Error to listen to 10 connection.");

        pthread_exit( ( void * )PC_ERROR );
    }

    while( 1 )
    {
        if( numClients < MAX_CLIENT )
        {
            clients[numClients] = accept( s_server , NULL , NULL );

            if( clients[numClients] > 0 )
            {

                TRACE_1( SERVERMANAGER , "[!]New client connected.");

                args = ( argumentReceivingThread_t * )zmalloc( sizeof( argumentReceivingThread_t ) );

                args->socket = clients[numClients];
                args->port = *( int * )port;

                createThread( &receivingThread , args );

                numClients++;
            }
        }
    }

    releaseThread();

    pthread_exit( ( void * )PC_SUCCESS );
}
Beispiel #9
0
/* void *arg is a argumentReceivingThread_t type */
void receivingThread( void *arg )
{
    TRACE_2( SERVERMANAGER , "receivingThread()");

    char buff[BUFF_SIZE];
    char input[] = "wMusic~>";
    int ret;
    int info;
    void *cliRet;

    argumentReceivingThread_t *arguments = ( argumentReceivingThread_t * )arg;

    TRACE_3( SERVERMANAGER , "Thread argument: socket: %d , port: %d" , arguments->socket , arguments->port );

    TRACE_1( SERVERMANAGER , "[!]Receiving thread create !");

    if( arguments->port == PORT_CLI )
        sendVoidSocket( arguments->socket , input , sizeof( input ) );
    else //usleep( 2000 ) for WAN connection, usleep( 300 ) for LAN connection.
        usleep( 2000 ); info = IAMBRIDGE; sendVoidSocket( arguments->socket , ( void *)&info , sizeof( int ) );    //Sending info that the remote is connected to a bridge.

    while( 1 )
    {
        memset( buff , 0 , BUFF_SIZE );

        ret = recv( arguments->socket , buff , BUFF_SIZE , 0 );

        if( ret > 0 )
        {

            if( arguments->port == PORT_COMMANDER )
            {
                TRACE_3( SERVERMANAGER , "[+]Data: %s" , buff );

                if( strstr( buff , "DISC") != NULL )
                {
                    disconnectClient( &arguments->socket );

                    break;
                }

                lastRequester = arguments->socket;

                doAction( buff );
            }
            else if( arguments->port == PORT_CLI )
            {
                TRACE_3( SERVERMANAGER , "[+]Data: %s" , buff );

                cliRet = doCommand( buff );

                if( cliRet != NULL )
                {
                    sendVoidSocket( arguments->socket , cliRet , strlen( ( const char * )cliRet ) );

                    zfree( cliRet );

                    sendVoidSocket( arguments->socket , input , sizeof( input ) );
                }
            }
        }

    }

    TRACE_3( SERVERMANAGER , "[!]Quitting receiving thread !");

    releaseThread();

    pthread_exit( NULL );
}