void set_sem_sezC(int protocol) { pthread_mutex_init(&mx_sezNorm, 0); printf("Selected protocol : -%d- \n", protocol); if (protocol == PRIO_INHERITANCE) { printf("PRIO_INHERITANCE \n"); pmux_create_pi(&mx_sezA); pmux_create_pi(&mx_sezB); } else if (protocol == PRIO_CEILING) { printf("PRIO_CEILING \n"); pmux_create_pc(&mx_sezA, PRIO); pmux_create_pc(&mx_sezB, PRIO); } else { pthread_mutex_init(&mx_sezA, 0); pthread_mutex_init(&mx_sezB, 0); } }
void init() { allegro_init(); /* Initializes this library */ tspec_init(); set_gfx_mode(GFX_AUTODETECT_WINDOWED, XWIN, YWIN, 0, 0); clear_to_color(screen, BGC); install_keyboard(); install_mouse(); srand(time(NULL)); /* semaphore to write on the screen */ pmux_create_pi(&mxa); }
void ptask_init(int policy, global_policy global, sem_protocol protocol) { int i; ptask_policy = policy; ptask_global = global; ptask_protocol = protocol; ptask_num_cores = sysconf(_SC_NPROCESSORS_ONLN); /* checks that admission control is disabled in case of partitioned edf */ if ((ptask_policy == SCHED_DEADLINE) && (ptask_global == PARTITIONED)) { FILE *f = fopen("/proc/sys/kernel/sched_rt_runtime_us", "r"); int v = 0; fscanf(f, "%d", &v); fclose(f); if (v != -1) { fprintf(stderr, "Cannot set PARTITIONED EDF scheduling, because " "admission control is enabled\n"); exit(-1); } } /* initializes all private sems with the value 0 */ for (i = 0; i < MAX_TASKS; i++) { sem_init(&_tsem[i], 0, 0); if (i == MAX_TASKS - 1) _tp[i].free = _TP_NOMORE; else _tp[i].free = i + 1; } first_free = 0; if (ptask_protocol == PRIO_INHERITANCE) pmux_create_pi(&_tp_mutex); else if (ptask_protocol == PRIO_CEILING) pmux_create_pc(&_tp_mutex, 99); else if (ptask_protocol == NO_PROTOCOL) pthread_mutex_init(&_tp_mutex, 0); else ptask_syserror("ptask_init()", "Semaphore protocol not supported"); // initialize time tspec_init(); }
/** This function returns a free descriptor, or -1 if there are no more free descriptors. _tp is organised as a linked list, first_free is the head of the list. This extracts from the head. It uses the _tp_mutex to protect the critical section. */ static int allocate_tp() { int x = first_free; if (x == _TP_NOMORE) return -1; else { pthread_mutex_lock(&_tp_mutex); if (_tp[x].free == _TP_BUSY) { /*< already taken by another thread ! */ pthread_mutex_unlock(&_tp_mutex); return -1; } first_free = _tp[x].free; _tp[x].free = _TP_BUSY; if (ptask_protocol == PRIO_INHERITANCE) pmux_create_pi(&_tp[x].mux); else if (ptask_protocol == PRIO_CEILING) pmux_create_pc(&_tp[x].mux, 99); else pthread_mutex_init(&_tp[x].mux, 0); pthread_mutex_unlock(&_tp_mutex); return x; } }