예제 #1
0
c_bool
d_waitsetDetach(
    d_waitset waitset,
    d_waitsetEntity we)
{
    u_result ur;
    c_bool result = FALSE;
    int i;
    d_waitsetHelper helper;

    helper = NULL;

    assert(d_objectIsValid(d_object(waitset), D_WAITSET) == TRUE);
    assert(d_objectIsValid(d_object(we), D_WAITSET_ENTITY) == TRUE);

    if(waitset && we){
        d_lockLock(d_lock(waitset));

        if(c_iterContains(waitset->entities, we) == TRUE) {
            if(waitset->runToCompletion == TRUE){
                ur = u_waitsetDetach(waitset->uwaitset, u_entity(we->dispatcher));
            } else {
                for(i=0; i<c_iterLength(waitset->threads) && !helper; i++){
                    helper = d_waitsetHelper(c_iterObject(waitset->threads, i));

                    if(helper->entity != we){
                        helper = NULL;
                    }
                }
                assert(helper);
                c_iterTake(waitset->threads, helper);
                helper->terminate = TRUE;
                u_waitsetNotify(helper->userWaitset, NULL);
                os_threadWaitExit(helper->tid, NULL);
                ur = u_waitsetDetach(helper->userWaitset, u_entity(we->dispatcher));
                u_waitsetFree(helper->userWaitset);
                os_free(helper);
            }
            if(ur == U_RESULT_OK) {
                c_iterTake(waitset->entities, we);
                we->waitset = NULL;
                result = TRUE;
            }
        }
        d_lockUnlock(d_lock(waitset));
    }
    return result;
}
예제 #2
0
jni_result
jni_deleteSubscriber(
    jni_participant p, 
    jni_subscriber sub)
{
    jni_result r;
    
    if((p == NULL) || (sub == NULL)){
        r = JNI_RESULT_BAD_PARAMETER;
    }
    else if(p->subscribers == NULL){
       r = JNI_RESULT_PRECONDITION_NOT_MET;
    }
    else if(sub->participant != p){
      r = JNI_RESULT_PRECONDITION_NOT_MET;
    }
    else{
        r = jni_subscriberFree(sub);
        
        if(r == JNI_RESULT_OK){
            c_iterTake(p->subscribers, sub);
        }
    }
    return r;
}
예제 #3
0
void
cmx_readerSnapshotFree(
    c_char* snapshot)
{
    cmx_readerSnapshot s;
    c_char* sample;
    os_mutex m;
    
    s = cmx_readerSnapshotLookup(snapshot);
    
    if(s != NULL){   
        m = cmx_getReaderSnapshotMutex();
        os_mutexLock(&m);
        c_iterTake(readerSnapshots, s);
        os_mutexUnlock(&m);
            
        if(s->samples != NULL){
            sample = (c_char*)(c_iterTakeFirst(s->samples));
            
            while(sample != NULL){
                os_free(sample);
                sample = (c_char*)(c_iterTakeFirst(s->samples));
            }
            c_iterFree(s->samples);
        }
        os_free(s);
        os_free(snapshot);
    }
}
예제 #4
0
static void
_ObjectRegistryDeregister (
    _ObjectRegistry registry,
    gapi_handle handle)
{
    assert(registry);
    assert(handle);

    os_mutexLock(&registry->mutex);
    c_iterTake(registry->active, handle);
    if (handle->kind != OBJECT_KIND_WAITSET) {
        if (registry->trash[registry->ptr]) {
            UT_TRACE("_ObjectRegistryDeregister(%x,%x) %d freed\n",
                     (unsigned int)registry,
                     (unsigned int)registry->trash[registry->ptr],
                     ((gapi_handle)registry->trash[registry->ptr])->kind);
            gapi__free(registry->trash[registry->ptr]);
        }
        UT_TRACE("_ObjectRegistryDeregister(%x,%x) %d added to trash\n",
                   (unsigned int)registry,
                   (unsigned int)handle,
                   handle->kind);

        registry->trash[registry->ptr] = handle;
        registry->ptr = (registry->ptr+1)%TRASH_LENGTH;
    }
    os_mutexUnlock(&registry->mutex);
}
예제 #5
0
u_result
u_dispatcherRemoveListener(
    u_dispatcher _this,
    u_dispatcherListener listener)
{
    u_listener ul;
    v_observer ko;
    os_threadId tid;
    u_result result = U_RESULT_OK;
    struct compareArg arg;

    if ((_this != NULL) && (listener != NULL)) {
        os_mutexLock(&_this->mutex);
        arg.listener = listener;
        ul = (u_listener) c_iterResolve(_this->listeners, compare, &arg);
        tid = _this->threadId;
        if (ul != NULL) {
            c_iterTake(_this->listeners, ul);
            if (c_iterLength(_this->listeners) == 0) {
                result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko));
                if(result == U_RESULT_OK) {
                    assert(ko);
                    /* Wakeup the dispatch thread */
                    v_observerLock(ko);
                    v_observerNotify(ko, NULL, NULL);
                    v_observerUnlock(ko);
                    result = u_entityRelease(u_entity(_this));
                    if (result != U_RESULT_OK) {
                        OS_REPORT(OS_ERROR, "u_dispatcherRemoveListener", 0,
                                  "Release observer failed.");
                    }
                } else {
                    OS_REPORT(OS_WARNING, "u_dispatcherRemoveListener", 0,
                              "Failed to claim Dispatcher.");
                }
            }
            u_listenerFree(ul);
        }
        os_mutexUnlock(&_this->mutex);
        if ((c_iterLength(_this->listeners) == 0)
            && (os_threadIdToInteger(tid) != 0U)) {
            os_threadWaitExit(tid, NULL);
        }
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherInsertListener",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
예제 #6
0
파일: u_waitset.c 프로젝트: osrf/opensplice
u_result
u_waitsetDetachFromDomain(
    _Inout_ u_waitset _this,
    _Inout_ u_domain domain)
{
    u_result result;
    os_result osr;
    u_waitsetEntry entry;

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

    osr = os_mutexLock_s(&_this->mutex);
    if (osr == os_resultSuccess) {
        entry = c_iterResolve(_this->entries, compare_domain, domain);
        if (entry != NULL) {
            _this->notifyDetached = OS_TRUE;
            result = u_objectClose(entry);
            if (result == U_RESULT_ALREADY_DELETED) {
                result = U_RESULT_OK;
            }
            if (result == U_RESULT_OK) {
                /* The entry is already freed but the address value can still
                 * be used to update the administration because it only removes
                 * the address value from the list.
                 */
                c_iterTake(_this->entries, entry);
            } else {
                result = U_RESULT_INTERNAL_ERROR;
                OS_REPORT(OS_ERROR,
                            "u_waitsetDetachFromDomain", result,
                            "Operation u_waitsetEntryFree failed: "
                            "Waitset = 0x%"PA_PRIxADDR", result = %s",
                             (os_address)_this, u_resultImage(result));
                assert(FALSE);
            }
        } else {
            result = U_RESULT_PRECONDITION_NOT_MET;
        }
        (void)u_domainRemoveWaitset(domain, _this);
        os_mutexUnlock(&_this->mutex);
    } else {
        result = U_RESULT_INTERNAL_ERROR;
        OS_REPORT(OS_WARNING, "u_waitsetDetachFromDomain", result,
                  "Could not claim waitset.");
    }

    return result;
}
예제 #7
0
gapi_returnCode_t
_ConditionRemoveWaitset(
    _Condition   _this,
    gapi_waitSet waitset,
    u_waitset    uWaitset)
{
    gapi_returnCode_t result = GAPI_RETCODE_OK;
    u_result uResult;

    c_iterTake(_this->waitsets, waitset);
    if ((_this->uEntity != NULL) && (uWaitset != NULL)) {
        uResult = u_waitsetDetach(uWaitset, _this->uEntity);
        if (uResult != U_RESULT_OK) {
            result = GAPI_RETCODE_ERROR;
        }
    }
    return result;
}
예제 #8
0
static c_bool
updatePartitions(
    c_object o,
    c_voidp arg)
{
    v_partition d = v_partition(o);
    struct updatePartitionsArg *a = (struct updatePartitionsArg *)arg;

    if (c_iterContains(*(a->addPartitions), (void *)d)) {
        c_iterTake(*(a->addPartitions), (void *)d);
        /* remove since we already know the partition */
        c_free(d);

    } else {
        /* add to remove list, we are no longer interested */
        *(a->removePartitions) = c_iterInsert(*(a->removePartitions), c_keep(d));
    }

    return TRUE; /* never break the walk */
}
예제 #9
0
u_result
u_readerRemoveQuery(
    u_reader _this,
    u_query query)
{
    u_query found;
    u_result result;
    os_result r;

    if (_this && query) {
        if(u_entityOwner(u_entity(_this))) {
            r = os_mutexLock(&_this->mutex);
            if (r == os_resultSuccess) {
                found = c_iterTake(_this->queries,query);
                os_mutexUnlock(&_this->mutex);
                if (found) {
                    result = U_RESULT_OK;
                } else {
                    OS_REPORT(OS_WARNING,"u_readerRemoveQuery",0,
                              "The specified Querie is not related to the given Reader.");
                    result = U_RESULT_PRECONDITION_NOT_MET;
                }
            } else {
                OS_REPORT(OS_WARNING,
                          "u_readerRemoveQuery",0,
                          "Failed to lock Reader.");
                result = U_RESULT_ILL_PARAM;
            }
        } else {
            result = U_RESULT_OK;
        }
    } else {
        OS_REPORT(OS_WARNING,
                  "u_readerRemoveQuery",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }

    return result;
}
예제 #10
0
u_result
u_subscriberRemoveReader(
    u_subscriber _this,
    u_reader reader)
{
    u_reader found;
    u_result result;

    result = u_entityLock(u_entity(_this));
    if (result == U_RESULT_OK) {
        found = c_iterTake(_this->readers,reader);
        if (found) {
            u_entityDereference(u_entity(_this));
        }
        u_entityUnlock(u_entity(_this));
    } else {
        OS_REPORT(OS_WARNING,
                  "u_subscriberRemoveReader",0,
                  "Failed to lock Subscriber.");
    }
    return result;
}
예제 #11
0
파일: u_user.c 프로젝트: cynron/opensplice
void
u_userFree (
    c_object o)
{
    u_user u;
    u_domainAdmin ka;
    c_object found;
    c_long i;

    if (o) {
        u = u__userLock();
        if (u) {
            for (i=1; i <= u->domainCount; i++) {
                ka = &u->domainList[i];
                if (ka->domain) {
                    if (((c_address)o >= ka->lowerBound) &&
                        ((c_address)o <= ka->upperBound))
                    {
                        /* o is in the address range of this domain.
                         * so take it from the keepList.
                         * and free it only if it is actually found in the keepList.
                         */
                        found = c_iterTake(ka->keepList,o);
                        if (found) {
                            c_free(found);
                        } else {
                            OS_REPORT_1(OS_WARNING,"u_userFree",0,
                                       "User tries to free non existing object == 0x%x.",
                                        found);
                        }
                        i = u->domainCount + 1; /* jump out of the loop */
                    }
                }
            }
            u__userUnlock();
        }
    }
}
예제 #12
0
jni_result
jni_deleteTopic(
    jni_participant p,
    jni_topic top)
{
    jni_result r;
    c_bool found;
        
    if((top == NULL) || (p == NULL)){
        r = JNI_RESULT_BAD_PARAMETER;
    }
    else if(p->topics == NULL){
        r = JNI_RESULT_PRECONDITION_NOT_MET;
    }
    else if( (jni_topicDescription(top)->participant) != p ){
        r = JNI_RESULT_PRECONDITION_NOT_MET;
    }
    else if(!(jni_participantMayTopicBeDeleted(p, jni_topicDescription(top)->name))){
        r = JNI_RESULT_PRECONDITION_NOT_MET;
    }
    else{
        found = c_iterContains(p->topics, top);
        
        if(!found){
            r = JNI_RESULT_PRECONDITION_NOT_MET;
        }
        else{
            r = jni_topicFree(top);
            
            if(r == JNI_RESULT_OK){
                c_iterTake(p->topics, top);
            }
        } 
    } 
    return r;
}
예제 #13
0
c_bool
d_waitsetAttach(
    d_waitset waitset,
    d_waitsetEntity we)
{
    c_bool result = FALSE;
    u_result ur;
    os_result osr;
    d_waitsetHelper helper;
    c_ulong mask;
    d_admin admin;
    d_durability durability;

    assert(d_objectIsValid(d_object(waitset), D_WAITSET) == TRUE);
    assert(d_objectIsValid(d_object(we), D_WAITSET_ENTITY) == TRUE);

    if(waitset && we){
        d_lockLock(d_lock(waitset));

        if(!we->waitset) {
            if(c_iterContains(waitset->entities, we) == FALSE) {
                waitset->entities = c_iterInsert(waitset->entities, we);
                if(waitset->runToCompletion == TRUE){
                    ur = u_waitsetAttach(waitset->uwaitset, u_entity(we->dispatcher),
                             (c_voidp)we->dispatcher);

                    if(ur == U_RESULT_OK) {
                        we->waitset = waitset;
                        result = TRUE;
                    }
                } else {
                    admin = d_subscriberGetAdmin(waitset->subscriber);
                    durability = d_adminGetDurability(admin);

                    helper = os_malloc(C_SIZEOF(d_waitsetHelper));
                    helper->waitset     = waitset;
                    helper->entity      = we;
                    helper->terminate   = FALSE;
                    helper->tid         = OS_THREAD_ID_NONE;
                    helper->userWaitset = u_waitsetNew(u_participant(d_durabilityGetService(durability)));

                    mask = V_EVENT_DATA_AVAILABLE;
                    mask |= V_EVENT_NEW_GROUP;
                    mask |= V_EVENT_HISTORY_DELETE;
                    mask |= V_EVENT_HISTORY_REQUEST;
                    mask |= V_EVENT_PERSISTENT_SNAPSHOT;
                    mask |= V_EVENT_TRIGGER;
                    u_waitsetSetEventMask(helper->userWaitset, mask);
                    ur = u_waitsetAttach(helper->userWaitset, u_entity(we->dispatcher),
                             (c_voidp)we->dispatcher);

                    if(ur != U_RESULT_OK) {
                        assert(FALSE);
                    } else {
                        result = TRUE;
                    }
                    if(result){
                        waitset->threads  = c_iterInsert(waitset->threads, helper);

                        osr = os_threadCreate(&(helper->tid), we->name, &(we->attr),
                                    d_waitsetEventHandler, helper);

                        if(osr != os_resultSuccess){
                            c_iterTake(waitset->threads, helper);
                            u_waitsetDetach(helper->userWaitset, u_entity(we->dispatcher));
                            u_waitsetFree(helper->userWaitset);
                            os_free(helper);
                            result = FALSE;
                        }
                    } else {
                        u_waitsetFree(helper->userWaitset);
                        os_free(helper);
                    }

                }
            }
        }
        d_lockUnlock(d_lock(waitset));
    }
    return result;
}
예제 #14
0
파일: u_waitset.c 프로젝트: osrf/opensplice
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;
}