Пример #1
0
static d_instance
d_instanceNew(
    d_groupInfo groupInfo,
    const v_groupAction action)
{
    d_instance instance;
    c_type type;
    c_long nrOfKeys, i;
    c_array messageKeyList, instanceKeyList;

    instanceKeyList = c_tableKeyList(groupInfo->instances);
    type = c_subType(groupInfo->instances);
    instance = d_instance(c_new(type));
    c_free(type);

    if(instance){
        /*
         * copy the key value of the message into the newly created instance.
         */
        messageKeyList = v_topicMessageKeyList(v_groupTopic(action->group));
        nrOfKeys = c_arraySize(messageKeyList);
        assert(nrOfKeys == c_arraySize(instanceKeyList));

        for (i=0;i<nrOfKeys;i++) {
            c_fieldCopy(messageKeyList[i],action->message,
                        instanceKeyList[i], instance);
        }
        c_free(instanceKeyList);

        d_instanceSetHead(instance, NULL);
        d_instanceSetTail(instance, NULL);

        instance->messageCount = 0;
        instance->count = 0;
        instance->state = 0;

        v_stateSet(instance->state, L_EMPTY);
    } else {
        OS_REPORT(OS_ERROR,
                  "d_instanceNew",0,
                  "Failed to allocate instance.");
        assert(FALSE);
    }
    return instance;
}
Пример #2
0
v_deliveryWaitList
v_deliveryWaitListNew(
    v_deliveryGuard _this,
    v_message msg)
{
    v_deliveryWaitList waitlist = NULL;
    v_deliveryWaitList found;
    c_type type;

    assert(C_TYPECHECK(_this,v_deliveryGuard));

    if (_this) {
        /* lookup or create a writer specific admin.
         */
        type = c_subType(_this->waitlists);
        waitlist = c_new(type);
        c_free(type);
        if (waitlist) {
            waitlist->sequenceNumber = msg->sequenceNumber;
            waitlist->readerGID = copyReaderGIDsFromPublications(_this);
            waitlist->guard = _this;
            c_mutexInit(&waitlist->mutex, SHARED_MUTEX);
            c_condInit(&waitlist->cv, &waitlist->mutex, SHARED_COND);
        }
        found = c_tableInsert(_this->waitlists, waitlist);
        if (found != waitlist) {
            /* This should not happen! */
            OS_REPORT(OS_ERROR,
                      "v_deliveryWaitListNew",0,
                      "detected inconsistent waitlist admin.");
            c_free(waitlist);
            waitlist = NULL;
        }
    } else {
        OS_REPORT(OS_ERROR,
                  "v_deliveryWaitListNew",0,
                  "Operation failed: illegal parameter (_this == NULL).");
    }
    return waitlist;
}