Пример #1
0
TCPClientPort::~TCPClientPort()
{
  BufferedPort::BeginClose();

  if (socket.is_open())
    CancelWait(socket);
  else
    CancelWait(resolver);

  BufferedPort::EndClose();
}
Пример #2
0
TCPPort::~TCPPort()
{
  BufferedPort::BeginClose();

  if (connection.is_open())
    CancelWait(connection);

  if (acceptor.is_open())
    CancelWait(acceptor);

  BufferedPort::EndClose();
}
Пример #3
0
void
SkyLinesTracking::Client::Close()
{
    const ScopeLock protect(mutex);

    if (socket.is_open()) {
        CancelWait(socket.get_io_service(), socket);
        socket.close();
    }

    if (resolving) {
        CancelWait(socket.get_io_service(), resolver);
        resolving = false;
    }
}
Пример #4
0
//Timer handler for multiple waiting.
static DWORD MultiWaitTimerHandler(LPVOID pData)
{
    __KERNEL_THREAD_OBJECT* pKernelThread = (__KERNEL_THREAD_OBJECT*)pData;

    switch(pKernelThread->dwWaitingStatus & OBJECT_WAIT_MASK)
    {
    case OBJECT_WAIT_RESOURCE:
    case OBJECT_WAIT_DELETED:
        break;
    case OBJECT_WAIT_WAITING:
        pKernelThread->dwWaitingStatus &= ~OBJECT_WAIT_MASK;
        pKernelThread->dwWaitingStatus |= OBJECT_WAIT_TIMEOUT;
        //Delete the kernel thread object from all synobjects in waiting array.
        CancelWait(pKernelThread->MultipleWaitObjectArray,(__COMMON_OBJECT*)pKernelThread);
        //Add this kernel thread to ready queue.
        pKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_READY;
        KernelThreadManager.AddReadyKernelThread((__COMMON_OBJECT*)&KernelThreadManager,
                pKernelThread);
        break;
    default:
        BUG();
        break;
    }
    return 0;
}
Пример #5
0
bool ANDOR885_Camera::AbortIfAcquiring()
{
	int errorValue;
	bool error = false;

	//Check to see if the camera is acquiring. If it is, stop
	GetStatus(&errorValue);
	if(errorValue == DRV_ACQUIRING){
		//Check to see if the camera is playing. If it is, stop
		if (isPlaying)
			CancelWait();
		errorValue = AbortAcquisition();
		if(errorValue != DRV_SUCCESS){
			std::cerr << "ANDOR885_Camera: Error aborting acquisition" << std::endl;
			error = true;
		} else {
			//Wait until camera stops playing. (necessary? Yes, if called in play event.)
			waitForEndOfAcquisitionMutex->lock();
				while (isPlaying) {
					waitForEndOfAcquisitionCondition->wait();
				}
			waitForEndOfAcquisitionMutex->unlock();
		}

	}

	return error;
}
Пример #6
0
//A local helper routine,to process the case of waiting for all objects.
//This routine will be called by WaitForMultipleObjects.
static DWORD WaitForAll(__COMMON_OBJECT** pObjectArray,
                        int nObjectNum,
                        DWORD dwMillionSeconds,
                        int* pnSignalObjectIndex)
{
    DWORD                         dwRetVal      = OBJECT_WAIT_FAILED;
    DWORD                         dwFlags;
    DWORD                         dwTimeToWait  = dwMillionSeconds;
    __KERNEL_THREAD_OBJECT*       pKernelThread = NULL;
    BOOL                          bTryAgain     = FALSE;
    int                           i;

    pKernelThread = KernelThreadManager.lpCurrentKernelThread;
__TRY_AGAIN:
    __ENTER_CRITICAL_SECTION(NULL,dwFlags);
    while(TRUE)
    {
        if(ObjectsAreSignal(pObjectArray,nObjectNum))
        {
            ObtainAllObjects(pObjectArray,nObjectNum,(__COMMON_OBJECT*)pKernelThread);
            __LEAVE_CRITICAL_SECTION(NULL,dwFlags);
            return OBJECT_WAIT_RESOURCE;
        }
        if(0 == dwTimeToWait)  //Time out.
        {
            __LEAVE_CRITICAL_SECTION(NULL,dwFlags);
            KernelThreadManager.ScheduleFromProc(NULL);  //Re-schedule.
            return OBJECT_WAIT_TIMEOUT;
        }
        //Should wait on the objects whose status is non-signal.
        //Set the multiple waiting flags first.
        pKernelThread->dwMultipleWaitFlags |= MULTIPLE_WAITING_STATUS;
        pKernelThread->dwMultipleWaitFlags |= MULTIPLE_WAITING_WAITALL;
        //Save all waited objects.
        for(i = 0; i < nObjectNum; i ++)
        {
            pKernelThread->MultipleWaitObjectArray[i] = pObjectArray[i];
        }
        for(i = nObjectNum; i < MAX_MULTIPLE_WAIT_NUM; i ++)
        {
            pKernelThread->MultipleWaitObjectArray[i] = NULL;
        }
        //Set current kernel thread's status to BLOCKED.
        pKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_BLOCKED;
        pKernelThread->dwWaitingStatus &= ~OBJECT_WAIT_MASK;
        pKernelThread->dwWaitingStatus |= OBJECT_WAIT_WAITING;
        //Cancel wait for re-enter.
        if(bTryAgain)
        {
            CancelWait(pObjectArray,(__COMMON_OBJECT*)pKernelThread);
        }
        //Wait on all non-signal objects.
        if(!WaitTheseObjects(pObjectArray,nObjectNum,(__COMMON_OBJECT*)pKernelThread))  //Exception case,maybe caused by lack memory.
        {
            pKernelThread->dwThreadStatus = KERNEL_THREAD_STATUS_RUNNING;  //Restore.
            ClearMultipleWaitStatus(pKernelThread);
            __LEAVE_CRITICAL_SECTION(NULL,dwFlags);
            return OBJECT_WAIT_FAILED;
        }
        if(WAIT_TIME_INFINITE == dwTimeToWait)  //Should wait forever.
        {
            __LEAVE_CRITICAL_SECTION(NULL,dwFlags);
            KernelThreadManager.ScheduleFromProc(NULL);
            switch(pKernelThread->dwWaitingStatus)
            {
            case OBJECT_WAIT_DELETED:
                *pnSignalObjectIndex = (pKernelThread->dwMultipleWaitFlags & 0x000000FF);
                ClearMultipleWaitStatus(pKernelThread);
                //__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
                return OBJECT_WAIT_DELETED;
            case OBJECT_WAIT_RESOURCE:
                ClearMultipleWaitStatus(pKernelThread);
                bTryAgain = TRUE;
                goto __TRY_AGAIN;
            default:
                BUG();  //Should not occur this case.
                ClearMultipleWaitStatus(pKernelThread);
                //__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
                return OBJECT_WAIT_FAILED;
            }
        }
        else  //Timeout waiting.
        {
            __LEAVE_CRITICAL_SECTION(NULL,dwFlags);
            dwRetVal = MultiTimeOutWaiting(pKernelThread,nObjectNum,dwTimeToWait);
            switch(dwRetVal)
            {
            case OBJECT_WAIT_RESOURCE:
                ClearMultipleWaitStatus(pKernelThread);
                bTryAgain = TRUE;
                goto __TRY_AGAIN;
            case OBJECT_WAIT_DELETED:
                *pnSignalObjectIndex = (pKernelThread->dwMultipleWaitFlags & 0x000000FF);
                ClearMultipleWaitStatus(pKernelThread);
                //__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
                return OBJECT_WAIT_DELETED;
            case OBJECT_WAIT_TIMEOUT:
                ClearMultipleWaitStatus(pKernelThread);
                //__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
                return OBJECT_WAIT_TIMEOUT;
            default:
                BUG();  //Should not occur this case.
                ClearMultipleWaitStatus(pKernelThread);
                //__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
                return OBJECT_WAIT_FAILED;
            }
        }
    }

    //Should not reach here.
    //BUG();
    //return OBJECT_WAIT_FAILED;
}