コード例 #1
0
ファイル: Os.c プロジェクト: MatthewMiddleweek/ohNet
static int32_t SocketInterrupted(const OsNetworkHandle* aHandle)
{
    int32_t interrupted;
    OsMutexLock(aHandle->iCtx->iMutex);
    interrupted = aHandle->iInterrupted;
    OsMutexUnlock(aHandle->iCtx->iMutex);
    return interrupted;
}
コード例 #2
0
ファイル: Os.c プロジェクト: astaykov/ohNet
static int OsNetworkHandle_IsInterrupted(OsNetworkHandle* aHandle)
{
    int state;
    OsMutexLock(aHandle->iMutex);
    state = aHandle->iFlagInterrupted;
    OsMutexUnlock(aHandle->iMutex);
    return state;
}
コード例 #3
0
ファイル: Os.c プロジェクト: broonie/ohNet
int32_t OsNetworkInterrupt(THandle aHandle, int32_t aInterrupt)
{
    int32_t err = 0;
    OsNetworkHandle* handle = (OsNetworkHandle*)aHandle;
    OsMutexLock(handle->iCtx->iMutex);
    handle->iInterrupted = aInterrupt;
    if (aInterrupt != 0) {
        (void)WSASetEvent(handle->iEvent);
    }
    else {
        (void)WSAResetEvent(handle->iEvent);
    }
    OsMutexUnlock(handle->iCtx->iMutex);
    return err;
}
コード例 #4
0
ファイル: Os.c プロジェクト: astaykov/ohNet
static void OsNetworkHandle_SetInterrupted(OsNetworkHandle* aHandle, int aNewInterruptState)
{
    OsMutexLock(aHandle->iMutex);

    if ( aNewInterruptState != (int) aHandle->iFlagInterrupted )
    {
        aHandle->iFlagInterrupted = aNewInterruptState;
        
#if INT_ENABLED
        if ( aHandle->iFlagInterrupted )
            post_int(aHandle);
        else
            clear_int(aHandle);
#endif
    }
    
    OsMutexUnlock(aHandle->iMutex);
}
コード例 #5
0
ファイル: Os.c プロジェクト: MatthewMiddleweek/ohNet
uint64_t OsTimeInUs(OsContext* aContext)
{
    struct timeval now, diff, adjustedNow;
    OsMutexLock(aContext->iMutex);
    gettimeofday(&now, NULL);
    
    /* if time has moved backwards, calculate by how much and add this to aContext->iTimeAdjustment */
    if (now.tv_sec < aContext->iPrevTime.tv_sec ||
        (now.tv_sec == aContext->iPrevTime.tv_sec && now.tv_usec < aContext->iPrevTime.tv_usec)) {
        diff = subtractTimeval(&aContext->iPrevTime, &now);
        fprintf(stderr, "WARNING: clock moved backwards by %llu.%03llusecs\n", (unsigned long long)diff.tv_sec, (unsigned long long)(diff.tv_usec/1000));
        aContext->iTimeAdjustment = addTimeval(&aContext->iTimeAdjustment, &diff);
    }
    aContext->iPrevTime = now; /* stash current time to allow the next call to spot any backwards move */
    adjustedNow = addTimeval(&now, &aContext->iTimeAdjustment); /* add any previous backwards moves to the time */
    diff = subtractTimeval(&adjustedNow, &aContext->iStartTime); /* how long since we started, ignoring any backwards moves */
    OsMutexUnlock(aContext->iMutex);

    return (uint64_t)diff.tv_sec * 1000000 + diff.tv_usec;
}
コード例 #6
0
ファイル: Os.c プロジェクト: astaykov/ohNet
int32_t OsNetworkInterrupt(THandle aHandle, int32_t aInterrupt)
{
    int32_t err = 0;
    OsNetworkHandle* handle = (OsNetworkHandle*)aHandle;
    OsMutexLock(gMutex);
    handle->iInterrupted = aInterrupt;
    int32_t val = 1;
    if (aInterrupt != 0) {
        if (TEMP_FAILURE_RETRY(write(handle->iPipe[1], &val, sizeof(val))) == -1) {
            err = -1;
        }
    }
    else {
        while (TEMP_FAILURE_RETRY(read(handle->iPipe[0], &val, sizeof(val))) > 0) {
            ;
        }
    }
    OsMutexUnlock(gMutex);
    return err;
}
コード例 #7
0
ファイル: Os.c プロジェクト: sewood/ohNet
const char* OsStackTraceEntry(THandle aStackTrace, uint32_t aIndex)
{
#ifndef STACK_TRACE_ENABLE
    aStackTrace = aStackTrace;
    aIndex = aIndex;
    return NULL;
#else
    OsStackTrace* stackTrace = (OsStackTrace*)aStackTrace;
    OsMutexLock(stackTrace->iOsContext->iMutex);
    if (stackTrace->iSymbol == NULL) {
        stackTrace->iSymbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256, 1);
        if (stackTrace->iSymbol == NULL) {
            return NULL;
        }
        stackTrace->iSymbol->MaxNameLen = 255;
        stackTrace->iSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
    }
    SymFromAddr(stackTrace->iOsContext->iDebugSymbolHandle, (DWORD64)(stackTrace->iStack[aIndex]), 0, stackTrace->iSymbol);
    OsMutexUnlock(stackTrace->iOsContext->iMutex);
    return stackTrace->iSymbol->Name;
#endif
}
コード例 #8
0
ファイル: Os.c プロジェクト: sewood/ohNet
uint64_t OsTimeInUs(OsContext* aContext)
{
    uint64_t now, diff, adjustedNow;
    FILETIME ft;
    OsMutexLock(aContext->iMutex);
    GetSystemTimeAsFileTime(&ft);
    now = ft.dwHighDateTime;
    now <<= 32;
    now |= ft.dwLowDateTime;
    
    /* if time has moved backwards, calculate by how much and add this to aContext->iTimeAdjustment */
    if (now < aContext->iPrevTime) {
        diff = aContext->iPrevTime - now;
        fprintf(stderr, "WARNING: clock moved backwards by %3llums\n", now / 10000);
        aContext->iTimeAdjustment += diff;
    }
    aContext->iPrevTime = now; /* stash current time to allow the next call to spot any backwards move */
    adjustedNow = now + aContext->iTimeAdjustment; /* add any previous backwards moves to the time */
    diff = adjustedNow - aContext->iStartTime; /* how long since we started, ignoring any backwards moves */
    diff /= 10; // GetSystemTimeAsFileTime has units of 100 nano-secs
    OsMutexUnlock(aContext->iMutex);

    return diff;
}