Beispiel #1
0
static SEM_ID get_mutex (os_mutex *mutex)
{
    SEM_ID result;
    int options;
    semTake (cache_lock, WAIT_FOREVER);
    result = (SEM_ID) ut_get (cache, mutex);

    if (!result)
    {
        /* In single process mode only "private" variables are required */
        options = (SEM_Q_PRIORITY | SEM_DELETE_SAFE);
        /* Set option for priority inheritance if feature is enabled */
        if (ospl_mtx_prio_inherit) {
            options = options | SEM_INVERSION_SAFE;
        }
        result = semOpen(mutex->name, SEM_TYPE_MUTEX, SEM_EMPTY, options, 0, NULL);
        if (result) {
            (void) ut_tableInsert ((ut_table) cache, mutex, result);
        } else {
            mutex_panic ("get_mutex", 0);
        }
    }

    semGive (cache_lock);
    return result;
}
Beispiel #2
0
/** \brief Destroy the mutex
 *
 * \b os_mutexDestroy calls \b pthread_mutex_destroy to destroy the
 * posix \b mutex.
 */
void os_mutexDestroy (os_mutex *mutex)
{
    assert (mutex != NULL);
#ifdef OSPL_STRICT_MEM
    assert (mutex->signature == OS_MUTEX_MAGIC_SIG);
#endif

    if (mutex->name[0] != '\0') {
        SEM_ID id;

        /* shared mutex */
        id = ut_get (cache, mutex);
        cas_mutex_info_id (mutex, 0, invalid_sem_id);

        if (id) {
            semClose (id);
            semTake(cache_lock, WAIT_FOREVER);
            ut_remove (cache, mutex);
            semGive(cache_lock);
        }
    } else {
        int res = pthread_mutex_destroy (&mutex->info.posix_mutex);
        if (res != 0) {
            mutex_panic ("pthread_mutex_destroy failed", res);
        }
    }

#ifdef OSPL_STRICT_MEM
    mutex->signature = 0;
#endif
}
Beispiel #3
0
static refLeaf
monitor_typeExtent (
    c_type o,
    monitor_trc trace
    )
{
    refLeaf ted = NULL;

    ted = (refLeaf)ut_get (trace->extTree, o);
    if (ted) {
        if (ted->cycleNr != trace->cycleNr) {
            ted->ecp = ted->ec;
            ted->ec = o->objectCount;
            ted->cycleNr = trace->cycleNr;
        }
    } else {
        ted = malloc (C_SIZEOF(refLeaf));
        ted->tr = o;
        ted->ec = o->objectCount;
        ted->ecp = 0;
        ted->cycleNr = trace->cycleNr;
        ut_tableInsert(ut_table(trace->extTree), o, ted);
    }
    return ted;
}
Beispiel #4
0
DDS::Object_ptr
DDS::OpenSplice::StrObjMap::findElement(const char *key)
{
    DDS::Object_ptr element;

    element = reinterpret_cast<DDS::Object_ptr>(ut_get((ut_collection) myStrMap, const_cast<char *>(key)));
    return DDS::Object::_duplicate(element);
}
Beispiel #5
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;
}
Beispiel #6
0
/** 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);
    }
}
Beispiel #7
0
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;
}
Beispiel #8
0
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 (trace->refTree, tr);
    if (ord) {
        ord->rc++;
    } else {
        ord = malloc (C_SIZEOF(refLeaf));
        ord->tr = tr;
        ord->rc = 1;
        ord->prc = 0;
        ut_tableInsert(ut_table(trace->refTree), tr, ord);
    }
}