Beispiel #1
0
/**************************************************************
 * Private functions
 **************************************************************/
static void *
kernelManager(
    void *arg)
{
    s_kernelManager km = (s_kernelManager)arg;
    os_mutexLock(&km->mtx);
    km->active++;
    os_condBroadcast(&km->cv);
    os_mutexUnlock(&km->mtx);
    u_splicedKernelManager(km->spliced);
    return NULL;
}
Beispiel #2
0
c_syncResult
c_condBroadcast (
    c_cond *cnd)
{
    os_result result;

    result = os_condBroadcast(cnd);
    if(result != os_resultSuccess){
        OS_REPORT_1(OS_ERROR, "c_condBroadcast", 0, "os_condBroadcast failed; os_result = %d.", result);
        assert(result == os_resultSuccess);
    }
    return result;
}
Beispiel #3
0
static void *
cAndMCommandManager(
    void *arg)
{
    s_kernelManager km = (s_kernelManager)arg;
    os_mutexLock(&km->mtx);
    km->active++;
    os_condBroadcast(&km->cv);
    os_mutexUnlock(&km->mtx);
    u_splicedBuiltinCAndMCommandDispatcher(km->spliced);
    return NULL;
 
}
Beispiel #4
0
void
gapi_objectClearBusy (
    gapi_object _this)
{
    gapi_handle handle = gapi_handle(_this);

    if (gapi_handleClaim(handle) == GAPI_RETCODE_OK) {
        if ( handle->busy ) {
            handle->busy = FALSE;
            os_condBroadcast(&handle->cv);
        }
        gapi_handleRelease(handle);
    }
}
/**
 * Sets the terminate-flag in the parallel demarshalling context and signals workers.
 * @param[in] pdc the parallel demarshalling context to signal
 * @pre dr_mutex locked
 */
static void
pdc_terminateWorkers(
    DDS::ccpp_parDemContext *pdc)
{
    if(pdc){
        if(os_mutexLock(&pdc->superMtx) != os_resultSuccess) goto err_mutex_lock;
        if(os_mutexLock(&pdc->mtx) != os_resultSuccess) goto err_mutex_lock;
        pdc->terminate = 1U;
        os_condBroadcast(&pdc->startCnd);
        os_mutexUnlock(&pdc->mtx);
        os_mutexUnlock(&pdc->superMtx);
    }
    return;

err_mutex_lock:
    OS_REPORT(OS_FATAL, "CCPP", 0, "Failed to claim mutex");
    return;
}
Beispiel #6
0
void
_ObjectClearBusy (
    _Object object)
{
    gapi_handle handle;

    assert(object);
    assert(object->handle);

    handle = (gapi_handle)object->handle;

    assert(handle->magic == MAGIC);

    if ( handle->busy ) {
        handle->busy = FALSE;
        os_condBroadcast(&handle->cv);
    }
}
Beispiel #7
0
static void
nw_splicedaemonListener(
    v_serviceStateKind spliceDaemonState,
    c_voidp usrData)
{
    nw_termination *terminate = (nw_termination *)usrData;

    switch (spliceDaemonState) {
    case STATE_TERMINATING:
    case STATE_TERMINATED:
    case STATE_DIED:
        os_mutexLock( &terminate->mtx );
        terminate->terminate = TRUE;
	os_condBroadcast( &terminate->cv );
	os_mutexUnlock( &terminate->mtx );

    break;
    default:
        NW_CONFIDENCE(FALSE);
    break;
    }
}
Beispiel #8
0
u_result
u_waitsetDetach_s(
    const u_waitset _this,
    const u_observable observable)
{
    u_waitsetEntry entry;
    u_domain domain;
    u_result result;
    os_result osr;

    assert(_this != NULL);
    assert(observable != NULL);

    osr = os_mutexLock_s(&_this->mutex);
    if (osr == os_resultSuccess) {
        domain = u_observableDomain(observable);
        if (domain != NULL) {
            entry = c_iterResolve(_this->entries, compare_domain, domain);
            if (entry != NULL) {
                /* The following detach will wakeup any blocking wait call on this entry. */
                result = u_waitsetEntryDetach(entry, observable);
                if (result == U_RESULT_UNSUPPORTED) {
                    _this->detachCnt++;
                    /* removed last observable for this entry so can detach from domain. */
                    entry = c_iterTake(_this->entries, entry); /* use overwrite entry */
                    result = u_domainRemoveWaitset(domain, _this);
                    if (c_iterLength(_this->entries) == 1) {
                        _this->multi_mode = OS_FALSE;
                    } else {
                        _this->multi_mode = OS_TRUE;
                    }
                    while (_this->waitBusy) {
                        os_condWait(&_this->waitCv, &_this->mutex);
                    }

                    _this->detachCnt--;
                    /* Broadcast the detachCnt update. */
                    os_condBroadcast(&_this->waitCv);

                    os_mutexUnlock(&_this->mutex);
                    u_objectFree(entry);
                } else {
                    os_mutexUnlock(&_this->mutex);
                }
            } else {
                /* Check if the condition is already deleted */
                v_public ko;
                result = u_observableReadClaim(observable, &ko, C_MM_RESERVATION_NO_CHECK);
                if (result == U_RESULT_OK) {
                    u_observableRelease(observable, C_MM_RESERVATION_NO_CHECK);
                    result = U_RESULT_PRECONDITION_NOT_MET;
                    OS_REPORT(OS_ERROR, "u_waitSetDetach_s", result, "Condition is not attached to Waitset");
                }
                os_mutexUnlock(&_this->mutex);
            }
        } else {
            os_mutexUnlock(&_this->mutex);
            result = U_RESULT_INTERNAL_ERROR;
            OS_REPORT(OS_ERROR, "u_waitsetDetach_s", result,
                      "Failed to connect to domain.");
        }
    } else {
        result = U_RESULT_INTERNAL_ERROR;
        OS_REPORT(OS_ERROR, "u_waitSetDetach_s", result, "Could not lock the waitset.");
    }
    return result;
}
Beispiel #9
0
u_result
u_waitsetWaitAction (
    const u_waitset _this,
    u_waitsetAction action,
    void *arg,
    const os_duration timeout)
{
    u_result result = U_RESULT_OK;
    os_result osr;
    c_ulong length;

    assert(_this != NULL);
    assert(action != NULL);
    assert(OS_DURATION_ISPOSITIVE(timeout));

    osr = os_mutexLock_s(&_this->mutex);
    if (osr == os_resultSuccess) {
        if (!_this->alive) {
            result = U_RESULT_ALREADY_DELETED;
        }
        if (result == U_RESULT_OK) {
            if (!_this->waitBusy) {
                /* Wait for possible detach to complete.
                 * If you don't do that, it's possible that this wait call sets
                 * the waitBusy flag before the detach can wake up of its waitBusy
                 * loop, meaning that the detach will block at least until the
                 * waitset is triggered again.
                 */
                while (_this->detachCnt > 0) {
                    os_condWait(&_this->waitCv, &_this->mutex);
                }

                _this->waitBusy = TRUE;
                length = c_iterLength(_this->entries);
                if (length == 1) {
                    /* Single Domain Mode. */
                    u_waitsetEntry entry = c_iterObject(_this->entries,0);
                    os_mutexUnlock(&_this->mutex);
                    result = u_waitsetEntryWait(entry, action, arg, timeout);

                    os_mutexLock(&_this->mutex);
                    _this->waitBusy = FALSE;
                    os_condBroadcast(&_this->waitCv);
                    os_mutexUnlock(&_this->mutex);

                    if ((result == U_RESULT_OK) && (_this->alive == FALSE)) {
                        result = U_RESULT_ALREADY_DELETED;
                    }
                } else {
                    /* Multi Domain Mode (or no Domain). */
                    if (OS_DURATION_ISINFINITE(timeout)) {
                        os_condWait(&_this->cv, &_this->mutex);
                        osr = os_resultSuccess;
                    } else {
                        osr = os_condTimedWait(&_this->cv, &_this->mutex, timeout);
                    }
                    _this->waitBusy = FALSE;
                    os_condBroadcast(&_this->waitCv);
                    switch (osr) {
                    case os_resultSuccess:
                        if (_this->alive == TRUE) {
                            result = U_RESULT_OK;
                        } else {
                            result = U_RESULT_ALREADY_DELETED;
                        }
                    break;
                    case os_resultTimeout:
                        result = U_RESULT_TIMEOUT;
                    break;
                    default:
                        result = U_RESULT_INTERNAL_ERROR;
                        OS_REPORT(OS_ERROR, "u_waitsetWaitAction", result,
                                    "os_condWait failed for waitset 0x" PA_ADDRFMT,
                                    (PA_ADDRCAST)_this);
                    break;
                    }
                    os_mutexUnlock(&_this->mutex);
                }
            } else {
                os_mutexUnlock(&_this->mutex);
                result = U_RESULT_PRECONDITION_NOT_MET;
            }
        } else {
            os_mutexUnlock(&_this->mutex);
        }
    } else {
        result = U_RESULT_INTERNAL_ERROR;
        OS_REPORT(OS_ERROR, "u_waitsetWaitAction", result,
                    "os_mutexLock failed for waitset 0x" PA_ADDRFMT,
                    (PA_ADDRCAST)_this);
    }
    return result;
}
Beispiel #10
0
u_result
u_waitsetWaitAction2 (
    const u_waitset _this,
    u_waitsetAction2 action,
    void *arg,
    const os_duration timeout)
{
    u_result result = U_RESULT_OK;
    os_result osr;
    c_ulong length;
    struct checkArg a;
    a.action = action;
    a.arg = arg;
    a.count = 0;

    assert(_this != NULL);
    assert(OS_DURATION_ISPOSITIVE(timeout));

    osr = os_mutexLock_s(&_this->mutex);
    if (osr == os_resultSuccess) {
        if (!_this->alive) {
            result = U_RESULT_ALREADY_DELETED;
            OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result,
                      "Precondition not met: Waitset is already deleted");
        }
        if (_this->waitBusy) {
            result = U_RESULT_PRECONDITION_NOT_MET;
            OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result,
                      "Precondition not met: A Wait call is already active on this Waitset");
        }
        if (result == U_RESULT_OK) {
            /* Wait for possible detach to complete.
             * If you don't do that, it's possible that this wait call sets
             * the waitBusy flag before the detach can wake up of its waitBusy
             * loop, meaning that the detach will block at least until the
             * waitset is triggered again.
             */
            while (_this->detachCnt > 0) {
                os_condWait(&_this->waitCv, &_this->mutex);
            }

            length = c_iterLength(_this->entries);
            if (length == 1) {
                /* Single Domain Mode. */
                u_waitsetEntry entry = c_iterObject(_this->entries,0);
                _this->waitBusy = TRUE;
                os_mutexUnlock(&_this->mutex);

                result = u_waitsetEntryWait2(entry, action, arg, timeout);

                os_mutexLock(&_this->mutex);
                _this->waitBusy = FALSE;

                if (_this->notifyDetached) {
                    result = U_RESULT_DETACHING;
                    _this->notifyDetached = OS_FALSE;
                }

                os_condBroadcast(&_this->waitCv);
                os_mutexUnlock(&_this->mutex);

                if ((result == U_RESULT_OK) && (_this->alive == FALSE)) {
                    result = U_RESULT_ALREADY_DELETED;
                    OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result,
                              "Precondition not met: Waitset is already deleted");
                }
            } else {
                /* Multi Domain Mode (or no Domain). */
                a.count = 0;
                /* For each Domain test Conditions. */
                (void)c_iterWalkUntil(_this->entries, check_entry_conditions, &a);
                /* Test Guard Conditions */
                if ((a.count == 0) && (!action(NULL,arg))) {
                    a.count++;
                }
                /* If No Conditions are true then wait. */
                if (a.count == 0) {
                    _this->waitBusy = TRUE;
                    if (OS_DURATION_ISINFINITE(timeout)) {
                        os_condWait(&_this->cv, &_this->mutex);
                        osr = os_resultSuccess;
                    } else {
                        osr = os_condTimedWait(&_this->cv, &_this->mutex, timeout);
                    }
                    _this->waitBusy = FALSE;
                    os_condBroadcast(&_this->waitCv);
                    switch (osr) {
                    case os_resultSuccess:
                        if (_this->alive == TRUE) {
                            if (_this->notifyDetached) {
                                result = U_RESULT_DETACHING;
                                _this->notifyDetached = OS_FALSE;
                            } else {
                                result = U_RESULT_OK;
                            }
                        } else {
                            result = U_RESULT_ALREADY_DELETED;
                            OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result,
                                      "Precondition not met: Waitset is already deleted");
                        }
                    break;
                    case os_resultTimeout:
                        result = U_RESULT_TIMEOUT;
                    break;
                    default:
                        result = U_RESULT_INTERNAL_ERROR;
                        OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result,
                                    "os_condWait failed for waitset 0x" PA_ADDRFMT,
                                    (PA_ADDRCAST)_this);
                    break;
                    }
                }
                os_mutexUnlock(&_this->mutex);
            }
        } else {
            os_mutexUnlock(&_this->mutex);
        }
    } else {
        result = U_RESULT_INTERNAL_ERROR;
        OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result,
                    "os_mutexLock failed for waitset 0x" PA_ADDRFMT,
                    (PA_ADDRCAST)_this);
    }
    return result;
}