예제 #1
0
/**
 * \brief Wrapper function for the comparison of two key values.
 * 
 * This operation gets the key values from both objects and passes them to the
 * user provided compare function which is retrieved from the collection object.
 * 
 * \param o1 Object to which the second object is compared.
 * \param o2 The second object that is compared.
 * \param c Collection on which this operation takes place. 
 * 
 * \return C_LT, C_EQ, or a C_GT as the first argument is less than, 
 *         equal to, or greater than the second.
 */
static os_equality 
ut_tableCmpWrapper(
    void *o1,
    void *o2,
    void *c)
{    
    os_equality result = OS_ER;
    
    result = ut_collection(c)->cmpFunc(ut_tableNode(o1)->key, ut_tableNode(o2)->key, ut_collection(c)->args);
    return result;
}
예제 #2
0
파일: os_cond.c 프로젝트: osrf/opensplice
/** freeCachedItem. precondition : cache is locked */
static void freeCachedItem (os_cond * cond)
{
    struct cache_item * c;

    c = (struct cache_item*) ut_get (ut_collection(semCache), cond);
    if (c)
    {
        if (c->h)
        {
            CloseHandle (c->h);
        }

        ut_remove (ut_collection(semCache), cond);
        free (c);
    }
}
예제 #3
0
os_int32
ut_tableInsert(
    ut_table t,
    void *key,
    void *value)
{
    os_int32 returnValue;
    void *treeValue;
    ut_tableNode node;
    
    returnValue = 0;
    treeValue = NULL;
    node = NULL;
    
    assert(ut_collection(t)->type == UT_TABLE);
    
    node = ut_newTableNode(key, value);
    
    treeValue = ut_avlTreeInsert(ut_table(t)->tree, 
                                 node, 
                                 ut_tableCmpWrapper, 
                                 (void *)t);
                                   
    if (treeValue == node) {
        returnValue = 1;
    } else {
        os_free(node);
    }
    
    return returnValue;    
}
예제 #4
0
static c_object
qp_qosTableLookup(
        ut_table t,
        const c_char *defaultProfile,
        const c_char *id)
{
    c_object qos = NULL;
    const c_char * normalized = NULL;
    const c_char * normalizedDefaultProfile;

    assert(t);
    assert(defaultProfile);

    normalizedDefaultProfile = strncmp("::", defaultProfile, strlen("::")) == 0 ? defaultProfile + strlen("::") : defaultProfile;

    if(id) {
        normalized = strncmp("::", id, strlen("::")) == 0 ? id + strlen("::") : id;
        if(id != normalized){
            /* Fully-qualified name */
            qos = ut_get(ut_collection(t), (void *)normalized);
        } else {
            c_char fullname[256];
            c_char *fn = fullname;
            os_size_t len;

            if((len = snprintf(fn, sizeof(fullname), "%s::%s", normalizedDefaultProfile, id)) >= sizeof(fullname)) {
                if((fn = os_malloc(len + 1)) != NULL) {
                    (void) snprintf(fn, len + 1, "%s::%s", normalizedDefaultProfile, id);
                }
            }
            if(fn){
                qos = ut_get(ut_collection(t), (void *)fn);

                if(fn != fullname) {
                    os_free(fn);
                }
            }
        }
    } else {
        /* Empty qosName in default profile */
        qos = ut_get(ut_collection(t), (void *)normalizedDefaultProfile);
    }

    return qos;
}
예제 #5
0
ut_collection
ut_tableNew(
    const ut_compareElementsFunc cmpFunc,
    void *arg)
{
    ut_table table;
    ut_avlTree tree;
    
    table = NULL;
    tree = NULL;
    
    table = (ut_table)os_malloc((os_uint32)OS_SIZEOF(ut_table));
    ut_collection(table)->type = UT_TABLE;
    
    ut_collection(table)->cmpFunc = cmpFunc;
    ut_collection(table)->args = arg;
    
    tree = ut_avlTreeNew(0);
    
    table->tree = tree;
    
    return ut_collection(table);
}
예제 #6
0
파일: os_cond.c 프로젝트: osrf/opensplice
static HANDLE get_semaphore_handle (os_cond *cond)
{
    struct cache_item *c = NULL;
    HANDLE h = NULL;

    /* lookup the semaphore handle from the local cache.  If it doesnt exist
     * create it the expensive way but cache it for likely future calls
     */
    os_mutexLock(&semCacheMutex);

    c = (struct cache_item*) ut_get (ut_collection(semCache), cond);
    if (c)
    {
        h = (HANDLE)c->h;

        /* check that the lifecycleIds of the item cached is the same as the
         * requested item.  If not, then we have a stale reference in the cache.
         * In this case, remove this item from the cache and create another
         * new handle that is current
         */
        if (c->id != cond->qId  || c->lifecycleId != cond->lifecycleId)
        {
            freeCachedItem (cond);
            h = createNewHandle (cond);
            addCacheItem (cond, h);
        }
    }
    else
    {
        h = createNewHandle (cond);
        addCacheItem (cond, h);
    }

    os_mutexUnlock(&semCacheMutex);
    assert (h != NULL);

    return h;
}
예제 #7
0
파일: mm_orc.c 프로젝트: osrf/opensplice
static void
monitor_object (
    c_object o,
    monitor_orc trace
    )
{
    refLeaf ord;
    c_type tr = c_header(o)->type;

    if (tr == NULL) {
        tr = nullType;
    }
    ord = (refLeaf)ut_get (ut_collection(trace->refTree), tr);
    if (ord) {
        ord->rc++;
    } else {
        ord = malloc (C_SIZEOF(refLeaf));
        ord->tr = tr;
        ord->rc = 1;
        ord->prc = 0;
        ut_tableInsert(trace->refTree, tr, ord);
    }
}