示例#1
0
void dbPrintSets(FILE *f)
{
    dictIterator *iter = NULL;
    dictEntry *entry = NULL;

    if (NULL == f)
        return;

    lockRead(sets);

    if (0 == dictSize(sets))
    {
        unlockRead(sets);
        fprintf(f, "No sets in db.\r\n");
        return;
    }

    if (NULL == (iter = dictGetIterator(sets)))
    {
        unlockRead(sets);
        return;
    }

    while (NULL != (entry = dictNext(iter)))
    {
        fprintf(f, "%s\r\n", dictGetEntryKey(entry));
        lockRead(dictGetEntryVal(entry));
        setPrint((set *) dictGetEntryVal(entry), f, 1);
        unlockRead(dictGetEntryVal(entry));
        fprintf(f, "\r\n");
    }

    dictReleaseIterator(iter);
    unlockRead(sets);
}
示例#2
0
int dbFindSet(const set *s, valType *index, int lock)
{
    valType i;

    if (NULL == s)
        return 0;

    if (lock)
        lockRead(objectIndex);

    for (i = 0; i < objectIndexLength; i++)
    {
        if (NULL != objectIndex[i] &&
            objectSet == objectIndex[i]->objectType &&
            1 == setCmpE(s, objectIndex[i]->objectPtr.setPtr))
        {
            if (index)
                *index = i;

            if (lock)
                unlockRead(objectIndex);
            return 1;
        }
    }

    if (lock)
        unlockRead(objectIndex);
    return 0;
}
示例#3
0
int dbFindObject(const dbObject *object, valType *index, int lock)
{
    valType i;

    if (NULL == object)
        return 0;

    if (lock)
        lockRead(objectIndex);

    for (i = 0; i < objectIndexLength; i++)
    {
        if (NULL != objectIndex[i] &&
            1 == dbObjectCompare(object, objectIndex[i]))
        {
            if (index)
                *index = i;

            if (lock)
                unlockRead(objectIndex);
            return 1;
        }
    }

    if (lock)
        unlockRead(objectIndex);
    return 0;
}
示例#4
0
const set *dbGet(const sds setName)
{
    const set *result = NULL;
    lockRead(sets);
    result = (const set *) dictFetchValue(sets, setName);
    unlockRead(sets);
    return result;
}
示例#5
0
const dbObject *dbGetObject(valType id, int lock)
{
    const dbObject *result = NULL;

    if (lock)
        lockRead(objectIndex);

    if (id >= objectIndexLength)
    {
        unlockRead(objectIndex);
        return NULL;
    }

    result = objectIndex[id];

    if (lock)
        unlockRead(objectIndex);
    return result;
}
示例#6
0
const sds dbGetRandSet(void)
{
    dictEntry *entry = NULL;
    sds result = NULL;
    lockRead(sets);
    if (NULL != (entry = dictGetRandomKey(sets)))
    {
        result = (sds) entry->key;
    }
    unlockRead(sets);
    return result;
}
示例#7
0
valType dbSetTrunc(void)
{
    valType freed = 0, i;
    dictIterator *iter = NULL;
    dictEntry *entry = NULL;

    lockWrite(objectIndex);
    lockRead(sets);

    if (NULL == (iter = dictGetIterator(sets)))
    {
        unlockRead(sets);
        unlockWrite(objectIndex);
        return 0;
    }

    while (NULL != (entry = dictNext(iter)))
    {
        lockWrite(entry);
        freed += setTrunc((set *) dictGetEntryVal(entry));
        unlockWrite(entry);
    }

    for (i = 0; i < objectIndexLength; i++)
    {
        if (NULL != objectIndex[i] &&
            objectSet == objectIndex[i]->objectType)
        {
            freed += setTrunc(objectIndex[i]->objectPtr.setPtr);
        }
    }

    dictReleaseIterator(iter);

    unlockRead(sets);
    unlockWrite(objectIndex);

    return freed;
}
        flatbuffers::Offset<FlatResult> GraphHolder::execute(Nd4jLong graphId, flatbuffers::FlatBufferBuilder &builder, const FlatInferenceRequest* request) {
            if (!hasGraph(graphId))
                throw unknown_graph_exception(graphId);

            lockRead(graphId);

            auto graph = cloneGraph(graphId);
            auto res = GraphExecutioner::execute(graph, builder, request);
            delete graph;

            unlockRead(graphId);

            return res;
        }
示例#9
0
valType dbGC(void)
{
    valType collected = 0, i;
    dictIterator *iter = NULL;
    dictEntry *entry = NULL;
    set *acc = NULL;

    lockWrite(objectIndex);
    lockRead(sets);

    // Step 1. Union all sets in db.
    if (NULL == (iter = dictGetIterator(sets)))
    {
        unlockRead(sets);
        unlockWrite(objectIndex);
        return 0;
    }

    if (NULL == (acc = setCreate()))
    {
        unlockRead(sets);
        unlockWrite(objectIndex);
        return 0;
    }

    while (NULL != (entry = dictNext(iter)))
    {
        valType currentSetId = 0;
        set *tmp = NULL, *currentSet = (set *) dictGetEntryVal(entry);
        set *flattened = setFlatten(currentSet, 0);

        if (NULL == flattened)
        {
            continue;
        }

        if (1 == dbFindSet(currentSet, &currentSetId, 0))
        {
            if (-1 == setAdd(acc, currentSetId))
            {
                setDestroy(acc);
                dictReleaseIterator(iter);
                unlockRead(sets);
                unlockWrite(objectIndex);
                return 0;
            }
        }

        if (NULL == (tmp = setUnion(acc, flattened)))
        {
            setDestroy(flattened);
            setDestroy(acc);
            dictReleaseIterator(iter);
            unlockRead(sets);
            unlockWrite(objectIndex);
            return 0;
        }

        setDestroy(flattened);
        setDestroy(acc);
        acc = tmp;
    }

    dictReleaseIterator(iter);

    // Step 2. Find objects not present in grand total union.
    for (i = 0; i < objectIndexLength; i++)
    {
        if (NULL != objectIndex[i] && !setIsMember(acc, i))
        {
            dbObjectRelease((dbObject *) objectIndex[i]);
            free((dbObject *) objectIndex[i]);
            objectIndex[i] = NULL;

            if (i < objectIndexFreeId)
            {
                objectIndexFreeId = i;
            }

            collected++;
        }
    }

    setDestroy(acc);

    unlockRead(sets);
    unlockWrite(objectIndex);

    return collected;
}