示例#1
0
文件: mutex.c 项目: JamesHyunKim/F4OS
static int get_lock(volatile struct mutex *mutex) {
    struct task_mutex_data *curr_task_data = &curr_task->mutex_data;

    /* TODO: Use a nicer name than this builtin */
    if (__sync_bool_compare_and_swap(&mutex->lock, 0, 1)) {
        mutex->held_by = curr_task;
        held_mutexes_insert(curr_task_data->held_mutexes, mutex);
        curr_task_data->waiting = NULL;
        return 1;
    }
    else {
        if (mutex->held_by != NULL) {
            deadlock_check(mutex);

            /* Add to waitlist if higher priority */
            if (mutex->waiting) {
                if (task_compare(mutex->waiting, curr_task) < 0) {
                    mutex->waiting = curr_task;
                    curr_task_data->waiting = (struct mutex *) mutex;
                }
            }
            else {
                mutex->waiting = curr_task;
                curr_task_data->waiting = (struct mutex *) mutex;
            }

            return 0;
        }
        else {
            panic_print("Semaphore (0x%x) not available, but held_by unset.", mutex);
        }
    }

    return 0;
}
示例#2
0
文件: sat.c 项目: Meijuh/ltsmin
void
reach_sat_fix(reach_proc_t reach_proc, vset_t visited,
              bitvector_t *reach_groups, long *eg_count, long *next_count, long *guard_count)
{
    (void) reach_proc;
    (void) guard_count;

    if (PINS_USE_GUARDS)
        Abort("guard-splitting not supported with saturation=sat-fix");

    int level = 0;
    vset_t old_vis = vset_create(domain, -1, NULL);
    vset_t deadlocks = dlk_detect?vset_create(domain, -1, NULL):NULL;
    vset_t dlk_temp = dlk_detect?vset_create(domain, -1, NULL):NULL;

    LACE_ME;
    while (!vset_equal(visited, old_vis)) {
        if (trc_output != NULL) save_level(visited);
        vset_copy(old_vis, visited);
        stats_and_progress_report(NULL, visited, level);
        level++;
        for(int i = 0; i < nGrps; i++){
            if (!bitvector_is_set(reach_groups, i)) continue;
            expand_group_next(i, visited);
            reach_chain_stop();
            (*eg_count)++;
        }
        if (dlk_detect) vset_copy(deadlocks, visited);
        if (USE_PARALLELISM) vset_least_fixpoint_par(visited, visited, group_next, nGrps);
        else vset_least_fixpoint(visited, visited, group_next, nGrps);
        (*next_count)++;
        check_invariants(visited, level);
        if (dlk_detect) {
            for (int i = 0; i < nGrps; i++) {
                vset_prev(dlk_temp, visited, group_next[i],deadlocks);
                reduce(i, dlk_temp);
                vset_minus(deadlocks, dlk_temp);
                vset_clear(dlk_temp);
            }
            deadlock_check(deadlocks, reach_groups);
        }
        vset_reorder(domain);
    }

    vset_destroy(old_vis);
    if (dlk_detect) {
        vset_destroy(deadlocks);
        vset_destroy(dlk_temp);
    }
}
示例#3
0
文件: sat.c 项目: Meijuh/ltsmin
void
reach_sat(reach_proc_t reach_proc, vset_t visited,
          bitvector_t *reach_groups, long *eg_count, long *next_count, long *guard_count)
{
    (void) reach_proc;
    (void) next_count;
    (void) guard_count;

    if (PINS_USE_GUARDS)
        Abort("guard-splitting not supported with saturation=sat");

    if (act_detect != NULL && trc_output != NULL)
        Abort("Action detection with trace generation not supported");

    for (int i = 0; i < nGrps; i++) {
        if (bitvector_is_set(reach_groups, i)) {
            struct expand_info *ctx = RTmalloc(sizeof(struct expand_info));
            ctx->group = i;
            ctx->group_explored = group_explored[i];
            ctx->eg_count = eg_count;

            vrel_set_expand(group_next[i], expand_group_next_projected, ctx);
        }
    }

    if (trc_output != NULL) save_level(visited);
    stats_and_progress_report(NULL, visited, 0);
    if (USE_PARALLELISM) vset_least_fixpoint_par(visited, visited, group_next, nGrps);
    else vset_least_fixpoint(visited, visited, group_next, nGrps);
    stats_and_progress_report(NULL, visited, 1);

    check_invariants(visited, -1);

    if (dlk_detect) {
        vset_t deadlocks = vset_create(domain, -1, NULL);
        vset_t dlk_temp = vset_create(domain, -1, NULL);
        vset_copy(deadlocks, visited);
        for (int i = 0; i < nGrps; i++) {
            vset_prev(dlk_temp, visited, group_next[i],deadlocks);
            reduce(i, dlk_temp);
            vset_minus(deadlocks, dlk_temp);
            vset_clear(dlk_temp);
        }
        deadlock_check(deadlocks, reach_groups);
        vset_destroy(deadlocks);
        vset_destroy(dlk_temp);
    }
}
示例#4
0
void* th_main(void* th_main_args) {
    int i;
    int deadlock = -1;

    //printf("th_main\n");

    for (i = 0; i < NUM_CHOPSTICKS; i++) {
        chopsticks[i] = -1;
        deadlock_condition[i] = i;
    }

    for (i = 0; i < NUM_PHILOSPHERS; i++) {

        if (pthread_create(&philosphers[i], NULL, th_phil, i)) {
            perror("ERROR creating thread.");
            exit(1);
        }

    }

    while (TRUE) {
        //printf("DL INIT\n");
        deadlock = deadlock_check();

        if (deadlock == 0) {
            perror("Deadlock condition (0,1,2,3,4) ... terminating\n");
            break;
        }

        print_eating();__fpurge(stdout);
    }

    for (i = 0; i < NUM_PHILOSPHERS; i++) {
        pthread_kill(&philosphers[i], 9);

    }
    pthread_exit(0);

    return(0);



} // end th_main function