mirror of
https://gitlab.com/klmp200/LO41.git
synced 2025-07-21 00:59:24 +00:00
Voilà comment gérer ses threads comme un boss
This commit is contained in:
@ -12,6 +12,7 @@ SYNCHRONIZED_GETTER(Elevator, ELEVATOR_STATE, state)
|
||||
SYNCHRONIZED_SETTER(Elevator, ELEVATOR_STATE, state)
|
||||
SYNCHRONIZED_GETTER(Elevator, int, floor)
|
||||
SYNCHRONIZED_SETTER(Elevator, int, floor)
|
||||
SETTER(Elevator, int, thread_number);
|
||||
|
||||
void _free__Elevator(THIS(Elevator)){
|
||||
DELETE(this->passengers);
|
||||
@ -167,6 +168,7 @@ void *runnable_Elevator(void * void_this){
|
||||
printf("Ascenseur %s : Je suis en route vers l'étage %d\n", this->name, this->target_floor);
|
||||
}
|
||||
}
|
||||
data->unregister_thread(data, this->thread_number);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -176,22 +178,25 @@ Elevator *_init_Elevator(char * name){
|
||||
new_elevator->name = strdup(name);
|
||||
new_elevator->passengers = NEW(List);
|
||||
new_elevator->target_floor = 0;
|
||||
new_elevator->thread_number = -1;
|
||||
|
||||
pthread_mutex_init(&new_elevator->mutex_passengers, NULL);
|
||||
pthread_mutex_init(&new_elevator->mutex_state, NULL);
|
||||
pthread_mutex_init(&new_elevator->mutex_floor, NULL);
|
||||
|
||||
LINK_ALL(Elevator, new_elevator,
|
||||
runnable,
|
||||
get_number_of_passengers,
|
||||
get_next_passenger_stop,
|
||||
can_get_inside,
|
||||
remove_passenger,
|
||||
add_passenger,
|
||||
get_state,
|
||||
set_state,
|
||||
get_floor,
|
||||
set_floor,
|
||||
repair
|
||||
runnable,
|
||||
get_number_of_passengers,
|
||||
get_next_passenger_stop,
|
||||
can_get_inside,
|
||||
remove_passenger,
|
||||
add_passenger,
|
||||
get_state,
|
||||
set_state,
|
||||
get_floor,
|
||||
set_floor,
|
||||
repair,
|
||||
set_thread_number
|
||||
);
|
||||
|
||||
new_elevator->set_floor(new_elevator, 0);
|
||||
|
@ -21,11 +21,13 @@ typedef struct o_Elevator {
|
||||
PRIVATE char * name;
|
||||
PRIVATE int floor;
|
||||
PRIVATE int target_floor;
|
||||
PRIVATE int thread_number;
|
||||
PRIVATE pthread_mutex_t mutex_passengers;
|
||||
PRIVATE pthread_mutex_t mutex_state;
|
||||
PRIVATE pthread_mutex_t mutex_floor;
|
||||
|
||||
PUBLIC void * (*runnable)(void * void_this);
|
||||
PUBLIC void (*set_thread_number)(_THIS(Elevator), int data);
|
||||
|
||||
SYNCHRONIZE PRIVATE void (*set_state)(_THIS(Elevator), ELEVATOR_STATE var);
|
||||
SYNCHRONIZE PRIVATE void (*set_floor)(_THIS(Elevator), int var);
|
||||
|
Reference in New Issue
Block a user