Пример #1
0
void
v_deadLineInstanceListRemoveInstance(
    v_deadLineInstanceList list,
    v_instance instance)
{
    assert(C_TYPECHECK(list,v_deadLineInstanceList));
    assert((instance->prev != NULL) && (instance->next != NULL));
    assert(c_refCount(list) > 0);
    assert(c_refCount(instance) > 0);

    /* As the instance is removed, there is no need to update the lease.
     * Updating the lease might trigger the leasemanager thread to determine
     * the next expiry time. The next expiry time can also be determined on
     * the next deadline check, which is more efficient as the administration
     * might already have changed many times.
     */
    v_instanceRemove(instance);
    if (v_instanceAlone(v_instance(list))) { /* list has become empty */
        if (list->deadlineLease != NULL) {
            v_leaseManagerDeregister(list->leaseManager, list->deadlineLease);
            c_free(list->deadlineLease);
            list->deadlineLease = NULL;
        }
    }
}
Пример #2
0
c_object
c_checkType (
    c_object o,
    const c_char *name)
{
    c_type type;
    c_string str;
    c_bool found = FALSE;
    c_bool stop = FALSE;

    if (o == NULL) {
        return NULL;
    }
    c_assertValidDatabaseObject(o);
    assert(c_refCount(o) > 0);
    assert(name != NULL);
    type = c__getType(o);
    while (!found && !stop) {
        str = c_metaObject(type)->name;
        if (str == NULL) {
            found = TRUE; /** assume TRUE **/
        } else if (strcmp(str,name) != 0) {
            switch (c_baseObject(type)->kind) {
            case M_CLASS:
                type = c_type(c_class(type)->extends);
                if (type == NULL) {
                    if ((strcmp(str,"c_base") == 0) && (strcmp(name,"c_module") == 0)) {
                        found = TRUE;
                    }
                    stop = TRUE;
                }
            break;
            case M_TYPEDEF:
                type = c_typeDef(type)->alias;
                if (type == NULL) {
                    stop = TRUE;
                }
            break;
            default:
              stop = TRUE;
            }
        } else {
            found = TRUE;
        }
    }
    if (!found) {
#ifndef NDEBUG
        if(o != NULL){
            str = c_metaObject(c__getType(o))->name;
            OS_REPORT_2(OS_ERROR, "Database", 0,
                    "Type mismatch: object type is %s but %s was expected\n",
                    str,name);
        }
#endif

        return NULL;
    }
    return o;
}
Пример #3
0
static void
checkSample(
    v_dataViewSample sample)
{
    if (((v_dataViewInstance)(((v_readerSample)sample)->instance))->sampleCount != 0) {
        v_readerSample readerSample = (v_readerSample)(v_dataViewSampleTemplate(sample)->sample);
        v_dataViewSampleList sampleList = (v_dataViewSampleList)(sample);
        REL_ASSERT(c_refCount(readerSample) > 0);
        REL_ASSERT(C_TYPECHECK(readerSample, v_readerSample));
        REL_ASSERT(c_refCount(sampleList) > 0);
        if (sampleList->prev == NULL) {
            REL_ASSERT(readerSample->viewSamples == sample);
        } else {
            REL_ASSERT(readerSample->viewSamples != sample);
        }
    }
}
Пример #4
0
void
v_dataReaderSampleFree(
    v_dataReaderSample sample)
{
    v_dataReaderInstance instance;
    v_index index;
    v_dataReader dataReader;
    v_message message;

    if (sample) {
        assert(C_TYPECHECK(sample, v_dataReaderSample));
        if (c_refCount(sample) == 1) {
            /* Free the slave-samples as well */
            instance = v_readerSample(sample)->instance;
            index = v_index(instance->index);
            dataReader = v_dataReader(index->reader);
            if (!v_readerSampleTestState(sample,L_READ)) {
                dataReader->notReadCount--;
            }
#ifdef _SL_
            if (dataReader->cachedSampleCount < 1000) {
                message = v_dataReaderSampleMessage(sample);
                c_free(message);
                v_dataReaderSampleTemplate(sample)->message = NULL;
                sample->prev = dataReader->cachedSample;
                dataReader->cachedSample = sample;
                dataReader->cachedSampleCount++;
#else
            if (dataReader->cachedSample == NULL) {
                dataReader->cachedSample = sample;
                message = v_dataReaderSampleMessage(sample);
                c_free(message);
                v_dataReaderSampleTemplate(sample)->message = NULL;
#endif
            } else {
                c_free(sample);
            }
        } else {
            c_free(sample);
        }
    }
}

void
v_dataReaderSampleRemoveFromLifespanAdmin(
    v_dataReaderSample sample)
{
    v_dataReaderInstance instance;
    v_index index;

    if (sample) {
        assert(C_TYPECHECK(sample, v_dataReaderSample));
        instance = v_readerSample(sample)->instance;
        index = v_index(instance->index);
        v_lifespanAdminRemove(v_dataReaderEntry(index->entry)->lifespanAdmin,
                              v_lifespanSample(sample));
    }
}
Пример #5
0
/* put at end of list */
void
v_deadLineInstanceListInsertInstance(
    v_deadLineInstanceList list,
    v_instance instance)
{
    v_instance head = v_instance(list);
    v_kernel k;
    v_result result;

    assert(C_TYPECHECK(instance,v_instance));
    assert(C_TYPECHECK(list,v_deadLineInstanceList));
    assert(v_instanceAlone(instance));
    assert(c_refCount(list) > 0);
    assert(c_refCount(instance) > 0);

    /* As the instance is put at the end of the list no need to update the
       lease!
     */
    v_instanceUpdate(instance); /* Updates instance checkTime */
    v_instanceAppend(head,instance);
    if (list->deadlineLease == NULL) {
        if (c_timeCompare(list->leaseDuration, C_TIME_INFINITE) != C_EQ) {
            k = v_objectKernel(list->leaseManager);
            list->deadlineLease = v_leaseNew(k, list->leaseDuration);
            if(list->deadlineLease)
            {
                result = v_leaseManagerRegister(
                             list->leaseManager,
                             list->deadlineLease,
                             list->actionId,
                             v_public(list->actionObject),
                             TRUE /* repeat lease if expired */);
                if(result != V_RESULT_OK)
                {
                    c_free(list->deadlineLease);
                    list->deadlineLease = NULL;
                    OS_REPORT_1(OS_ERROR, "v_deadLineInstanceList", 0,
                                "A fatal error was detected when trying to register the deadline lease."
                                "The result code was %d.", result);
                }
            }
        }
    }
}
Пример #6
0
static void
toolAction (
    d_storeMMFKernel kernel,
    c_voidp addr)
{
    c_base base;
    c_type type;
    c_char *name;
    c_object o;
    c_address offset;
    c_long size;
    struct toolActionData actionData;

    actionData.fin = stdin;
    actionData.fout = stdout;
    actionData.depth = 0;
    actionData.stack = NULL;

    base = c_getBase(kernel);
    o = c_baseCheckPtr(base, addr);
    if (o) {
        type = c_getType(o);
        size = c_typeSize(type);
        if (o != addr) {
            offset = C_ADDRESS(addr) - C_ADDRESS(o);
            if (offset < (c_address)size) {
                printf("Warning: address is %lu bytes in %s "
                       "object starting at 0x"PA_ADDRFMT"\n",
                       offset, _METANAME(type), (os_address)o);
                OBJECT_PUSH(&actionData, o);
                tryPrintOffset(o,&actionData,offset);
                OBJECT_POP(&actionData);
            } else {
                printf("Warning: address is %lu bytes in "
                       "memory starting at 0x"PA_ADDRFMT"\n",
                   offset, (os_address)o);
            }
        } else {
            name = c_metaScopedName(c_metaObject(type));
            printf("Object <0x"PA_ADDRFMT"> refCount=%d size=%d type is: <0x"PA_ADDRFMT"> %s\n",
                   (os_address)o, c_refCount(o), size, (os_address)type, name);
            os_free(name);
            OBJECT_PUSH(&actionData, o);
            printType(type, &actionData);
            printf("\n");
            OBJECT_POP(&actionData);
        }
    } else {
        printf("Address <0x"PA_ADDRFMT"> is not a Database Object\n",
               (os_address)addr);
    }
}
Пример #7
0
void
v_deadLineInstanceListUpdate(
    v_deadLineInstanceList list,
    v_instance instance)
{
    assert(C_TYPECHECK(instance,v_instance));
    assert(C_TYPECHECK(list,v_deadLineInstanceList));
    assert(c_refCount(list) > 0);
    assert(c_refCount(instance) > 0);

    /* This will also place the current instance at the end of the list.
       Again no need to update the lease, we can determine the next wake-up
       as soon as the next deadlinecheck is performed.
    */
    if (v_instanceAlone(instance)) {
        v_deadLineInstanceListInsertInstance(list,instance);
    } else {
        v_instanceRemove(instance);
        v_instanceUpdate(instance); /* Updates instance checkTime */
        v_instanceAppend(v_instance(list), instance);
    }
}
Пример #8
0
void
checkInstance(
    v_dataViewInstance instance,
    c_bool isNotEmpty)
{
    int i = 0;
    v_dataViewSample current;
    v_dataViewSample next;

    if (instance) {
        if (!isNotEmpty) {
            REL_ASSERT(instance->sampleCount == 0);
        }
        if (!v_reader(v_dataViewReader(instance->dataView))->qos->userKey.enable && isNotEmpty) {
            REL_ASSERT(instance->sampleCount == 1);
        }
        REL_ASSERT(c_refCount(instance) > 0);
        REL_ASSERT(C_TYPECHECK(instance, v_dataViewInstance));
        next = NULL;
        current = v_dataViewInstanceTemplate(instance)->sample;
        while (current != NULL) {
            if (!isNotEmpty) {
                checkSample(current);
            }
            REL_ASSERT(current->next == next);
            if (next != NULL) {
                REL_ASSERT(next->prev == current);
            }
            next = current;
            current = current->prev;
            i++;
        }
        if (next != NULL) {
            REL_ASSERT(next->prev == current);
        }
        if (isNotEmpty) {
            REL_ASSERT(i == instance->sampleCount);
        } else {
            REL_ASSERT(i == 1);
        }
    }
}
Пример #9
0
static void
printCollectionAction(
    c_metaObject mo,
    c_scopeWalkActionArg arg)
{
    c_type type;
    c_object o = c_metaObject (mo);
    toolActionData actionData = (toolActionData)arg;
    c_char *name;

    if (o != NULL) {
        type = c_getType(o);
        name = c_metaScopedName(c_metaObject(type));
        iprintf("Object <0x"PA_ADDRFMT"> refCount=%d type is: <0x"PA_ADDRFMT"> %s\n",
                (os_address)o, c_refCount(o), (os_address)type, name);
        os_free(name);
        OBJECT_PUSH(actionData, o);
        printType(type, actionData);
        printf("\n");
        OBJECT_POP(actionData);
    }
}
Пример #10
0
v_result
v_deliveryWaitListFree(
    v_deliveryWaitList _this)
{
    v_deliveryWaitList found;
    v_result result;

    assert(C_TYPECHECK(_this,v_deliveryWaitList));

    if (_this) {
        /* lookup or create a writer specific admin.
         */
        found = c_remove(v_deliveryGuard(_this->guard)->waitlists, _this, NULL, NULL);
        assert(found == _this);
        assert(c_refCount(found) == 2);
        c_free(found);
        c_free(_this);
        result = V_RESULT_OK;
    } else {
        result = V_RESULT_ILL_PARAM;
    }
    return result;
}
Пример #11
0
v_writeResult
v_dataViewInstanceWrite (
    v_dataViewInstance instance,
    v_readerSample sample)
{
    v_dataViewSample viewSample;
    v_dataViewSample *prev;
    v_dataViewSample next;

    assert(C_TYPECHECK(instance,v_dataViewInstance));
    assert(C_TYPECHECK(sample,v_readerSample));

    CHECK_INSTANCE(instance);

    viewSample = v_dataViewSampleNew(instance,sample);
    if (viewSample) {
        viewSample->next = NULL;

        prev = &v_dataViewInstanceTemplate(instance)->sample;
        next = NULL;

        while (*prev) {
            next = *prev;
            prev = &(*prev)->prev;
        }
        *prev = viewSample;
        viewSample->next = next;

        v_readerSampleAddViewSample(sample,viewSample);
        instance->sampleCount++;
        assert(c_refCount(viewSample) == 1);
        v_dataViewNotifyDataAvailable(v_dataView(instance->dataView), viewSample);
    }
    CHECK_INSTANCE(instance);
    return V_WRITE_SUCCESS;
}
Пример #12
0
static d_storeResult
d_instanceInsert(
    d_instance instance,
    v_message msg,
    d_groupInfo groupInfo,
    d_sample toInsert)
{
    d_sample sample;
    d_sample oldest;
    d_sample ptr;
    v_state state;
    c_equality equality;
    v_topicQos topicQos;

    assert(C_TYPECHECK(instance, d_instance));
    assert(C_TYPECHECK(msg, v_message));
    assert(C_TYPECHECK(groupInfo, d_groupInfo));

    if (msg == NULL) {
        return D_STORE_RESULT_ILL_PARAM;
    }
    topicQos = groupInfo->topic->qos;

    if(toInsert){
        sample = toInsert;
        sample->instance = instance;
    } else {
        sample = d_groupInfoSampleNew(groupInfo, instance, msg);
    }

    if (!sample) {
        return D_STORE_RESULT_OUT_OF_RESOURCES;
    }

    if (v_stateTest(instance->state, L_EMPTY)) {
        assert(d_instanceGetHead(instance) == NULL);
        assert(d_instanceGetTail(instance) == NULL);
        assert(instance->count == 0);
        d_instanceSetHead(instance,sample);
        v_stateClear(instance->state, L_EMPTY);
    } else {
        assert(d_instanceGetHead(instance) != NULL);
        assert(d_instanceGetTail(instance) != NULL);
        assert(instance->count != 0);

        if(topicQos->orderby.kind == V_ORDERBY_RECEPTIONTIME){
            sample->older = d_instanceGetHead(instance);
            d_instanceSetHead(instance, sample);
        } else {
            ptr = d_instanceGetHead(instance);
            equality = v_timeCompare(msg->writeTime,
                    d_sampleGetMessage(ptr)->writeTime);

            if (equality == C_LT) {
                while (ptr->older != NULL) {
                    equality = v_timeCompare(msg->writeTime,
                                 d_sampleGetMessage(ptr->older)->writeTime);

                    if (equality != C_LT) {
                        break;
                    }
                    ptr = ptr->older;
                }
                sample->newer = ptr;
                sample->older = ptr->older;
                ptr->older = c_keep(sample);
            } else {
                sample->older = d_instanceGetHead(instance);
                d_instanceSetHead(instance,sample);
            }
        }
    }
    assert(c_refCount(sample) == 2);

    if (sample->older != NULL) {
        sample->older->newer = sample;
    } else {
        d_instanceSetTail(instance,sample);
    }
    sample->instance = instance;
    state = v_nodeState(msg);

    if (v_stateTest(state,L_DISPOSED)) {
        instance->count++;
    }
    if (v_stateTest(state, L_WRITE)) {
        if (topicQos->history.kind == V_HISTORY_KEEPALL
            || instance->messageCount < topicQos->history.depth) {
            instance->count++;
            instance->messageCount++;
        } else {
            ptr = NULL;
            oldest = instance->oldest;

            while (!v_messageStateTest(d_sampleGetMessage(oldest),L_WRITE)) {
                instance->count--;
                ptr = oldest;
                oldest = oldest->newer;
            }
            if (v_messageStateTest(d_sampleGetMessage(oldest),L_DISPOSED)) {
                instance->count--;
            }
            ptr = oldest;
            oldest = oldest->newer;

            while (!v_messageStateTest(d_sampleGetMessage(oldest),L_WRITE)) {
                instance->count--;
                ptr = oldest;
                oldest = oldest->newer;
            }
            d_instanceSetTail(instance,oldest);
            oldest->older = NULL;
            ptr->newer = NULL;

            while(ptr){
                oldest = ptr->older;
                ptr->older = NULL;
                c_free(ptr);
                ptr = oldest;
            }
        }
    }
    if (v_messageStateTest(d_sampleGetMessage(d_instanceGetHead(instance)), L_DISPOSED)) {
        v_stateSet(instance->state, L_DISPOSED);
    } else {
        if (v_stateTest(instance->state, L_DISPOSED)) {
            v_stateClear(instance->state, L_DISPOSED);
        }
    }
    c_free(sample);

    assert((instance->count == 0) == (d_instanceGetTail(instance) == NULL));
    assert((instance->count == 0) == (d_instanceGetHead(instance) == NULL));

    return D_STORE_RESULT_OK;
}
Пример #13
0
void
v_lifespanAdminRemove(
    v_lifespanAdmin admin,
    v_lifespanSample sample)
{
    c_equality eq;

    assert(C_TYPECHECK(admin,v_lifespanAdmin));
    assert(C_TYPECHECK(sample,v_lifespanSample));

    eq = c_timeCompare(sample->expiryTime, C_TIME_INFINITE);
    if (eq == C_EQ) {
        return; /* no insert, since sample never expires! */
    }

    CHECK_ADMIN(admin, sample);
    if (sample == admin->head) {
        assert(sample->prev == NULL);
        if (sample == admin->tail) {
            assert(c_refCount(sample) > 2);
            assert(sample->next == NULL);
            c_free(sample); /* free tail reference */
            admin->head = NULL;
            admin->tail = NULL;
        } else {
            assert(c_refCount(sample) > 1);
            admin->head = sample->next; /* transfer refcount */
            if (sample->next) {
                sample->next = NULL;
                admin->head->prev = NULL; /* or sample->next->prev = NULL */
            }
        }
        c_free(sample); /* free head reference */
        admin->sampleCount--;
    } else {
        if (sample == admin->tail) {
            assert(sample->prev);
            assert(c_refCount(sample) > 2); /* Both tail and next field from prev sample. */
            assert(sample->next == NULL);
            c_free(admin->tail);
            admin->tail = c_keep(sample->prev);
            sample->prev = NULL;
            c_free(admin->tail->next); /* admin->tail->next == sample */
            admin->tail->next = NULL;
            admin->sampleCount--;
        } else {
            if ((sample->next != NULL) && (sample->prev != NULL)) {
                assert(c_refCount(sample) > 1);
                assert(admin->sampleCount > 0);
                v_lifespanSample(sample->prev)->next = sample->next; /* transfer refcount */
                sample->next->prev = sample->prev;
                sample->next = NULL;
                sample->prev = NULL;
                c_free(sample);
                admin->sampleCount--;
            } /* else sample not in admin, so no removing needed */
        }
    }

    CHECK_ADMIN(admin, sample);
}
Пример #14
0
void
v_cacheNodeRemove (
    v_cacheNode node,
    v_cacheKind kind)
{
    struct v_cacheLink *nodeLink;

    assert(C_TYPECHECK(node,v_cacheNode));

    v_cacheNodeCheck(node);

    switch (kind) {
    case V_CACHE_OWNER:
        nodeLink = &node->owner;
        if (nodeLink->next != NULL) {
            v_cacheNode(nodeLink->next)->owner.prev = nodeLink->prev;
        }
        if (nodeLink->prev != NULL) {
            v_cacheNode(nodeLink->prev)->owner.next = nodeLink->next;
        }
        nodeLink->next = NULL;
        nodeLink->prev = NULL;
        v_cacheNodeCheck(node);
        c_free(node);
        break;
    case V_CACHE_TARGETS:
        nodeLink = &node->targets;
        if (nodeLink->next != NULL) {
            v_cacheNode(nodeLink->next)->targets.prev = nodeLink->prev;
        }
        if (nodeLink->prev != NULL) {
            v_cacheNode(nodeLink->prev)->targets.next = nodeLink->next;
        }
        nodeLink->next = NULL;
        nodeLink->prev = NULL;
        v_cacheNodeCheck(node);
        c_free(node);
        break;
    case V_CACHE_SOURCES:
        v_cacheItem(node)->instance = NULL;
        nodeLink = &node->sources;
        if (nodeLink->next != NULL) {
            v_cacheNode(nodeLink->next)->sources.prev = nodeLink->prev;
        }
        if (nodeLink->prev != NULL) {
            v_cacheNode(nodeLink->prev)->sources.next = nodeLink->next;
        }
        nodeLink->next = NULL;
        nodeLink->prev = NULL;
        v_cacheNodeCheck(node);
        c_free(node);
        break;
    case V_CACHE_ANY:
        assert(c_refCount(node) > 1);
        v_cacheNodeRemove(node,V_CACHE_OWNER);
        v_cacheNodeRemove(node,V_CACHE_TARGETS);
        break;
    default:
        break;
    }
}