Example #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;
}
Example #2
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;
}
Example #3
0
static void
orderedWalk (
    c_metaObject o,
    monitor_trc trace
    )
{
    switch (c_baseObject(o)->kind) {
        case M_MODULE:
            c_metaWalk (o, orderedWalk, trace);
            break;
        case M_UNDEFINED:
        case M_ATTRIBUTE:
        case M_CONSTANT:
        case M_CONSTOPERAND:
        case M_EXPRESSION:
        case M_LITERAL:
        case M_MEMBER:
        case M_OPERATION:
        case M_PARAMETER:
        case M_RELATION:
        case M_BASE:
        case M_UNIONCASE:
        case M_COUNT:
            break;
        default:
            ut_tableInsert(ut_table(trace->orderedList), o, o);
            break;
    }
}
Example #4
0
os_result os_mutexInit (os_mutex *mutex, const os_mutexAttr *mutexAttr)
{
    os_mutexAttr defAttr;
    os_result rv;
    int options;
    SEM_ID id;

    assert (mutex != NULL);
    #ifdef OSPL_STRICT_MEM
    assert (mutex->signature != OS_MUTEX_MAGIC_SIG);
#endif

    if(!mutexAttr) {
        os_mutexAttrInit(&defAttr);
        mutexAttr = &defAttr;
    }

    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;
    }
    if (mutexAttr->scopeAttr == OS_SCOPE_SHARED) {
        /* create named mutex using shared address as unique name */
        snprintf (mutex->name, sizeof (mutex->name), "/%lu", (os_uint32) mutex);
        id = semOpen (mutex->name, SEM_TYPE_MUTEX, SEM_EMPTY, options, OM_CREATE|OM_EXCL, NULL);
        /* As it may exist from a previous run. remove leftover semaphore object */
        if (id != NULL) {
            /* a fresh one, initialise it and cache the SEM_ID */
            pa_st32 ((void *) &mutex->info.id, 0);
            semTake (cache_lock, WAIT_FOREVER);
            (void) ut_tableInsert ((ut_table) cache, mutex, id);
            semGive (cache_lock);
        } else {
            /* re-using an old one: it should have been destroyed and hence should have a marker in info.id */
            id = get_mutex (mutex);
            if (id != NULL) {
                semTake (id, WAIT_FOREVER);
                semGive (id);
                /*cas_mutex_info_id ((void*)&mutex->info.id, invalid_sem_id, 0);*/
            } else {
                mutex_panic ("init: attempt to reuse semaphore currently in use", 0);
            }
        }

        rv = (id != NULL) ? os_resultSuccess : os_resultFail;
    } else {
        int result;
        mutex->name[0] = '\0';
        /* TODO attrs */
        result = pthread_mutex_init(&mutex->info.posix_mutex, NULL);
        rv = (result == 0) ? os_resultSuccess : os_resultFail;
    }

#ifdef OSPL_STRICT_MEM
    mutex->signature = OS_MUTEX_MAGIC_SIG;
#endif
    return rv;
}
Example #5
0
/* addCacheItem.  precondition : cache is locked, and the cond does not exist in the cache */
static void addCacheItem (os_cond * cond, HANDLE h)
{
    struct cache_item * c = malloc (sizeof (struct cache_item));
    if (c)
    {
        c->h = h;
        c->lifecycleId = cond->lifecycleId;
        c->id = cond->qId;
        (void) ut_tableInsert (semCache, cond, c);
    }
    else
    {
        fprintf (stdout, "error : addCacheItem unable to malloc\n");
    }
}
Example #6
0
const DDS::Object *
DDS::OpenSplice::StrObjMap::insertElement(const char *key, DDS::Object_ptr element)
{
    DDS::Object_ptr result;
    char *keyCopy = DDS::string_dup(key);
    os_int32 inserted;

    inserted = ut_tableInsert(myStrMap, keyCopy, element);
    if (inserted) {
        result = DDS::Object::_duplicate(element);
    } else {
        DDS::string_free(keyCopy);
        result = NULL;
    }
    return result;
}
Example #7
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);
    }
}