mirror of
https://gitlab.com/klmp200/LO41.git
synced 2025-07-20 00:29:24 +00:00
Voilà comment gérer ses threads comme un boss
This commit is contained in:
@ -11,6 +11,7 @@ GETTER(Resident, char *, name);
|
||||
GETTER(Resident, int, destination);
|
||||
GETTER(Resident, int, id);
|
||||
GETTER(Resident, int, apartment_floor);
|
||||
SETTER(Resident, int, thread_number);
|
||||
|
||||
void * runnable_Resident(void * void_this){
|
||||
Resident * this = (Resident*) void_this;
|
||||
@ -30,6 +31,7 @@ void * runnable_Resident(void * void_this){
|
||||
else
|
||||
data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger);
|
||||
data->decrement_active_passengers(data);
|
||||
data->unregister_thread(data, this->thread_number);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -50,13 +52,15 @@ Resident *_init_Resident(int id, char* name, int apartment_floor, int destinatio
|
||||
new_resident->position = new_resident->apartment_floor;
|
||||
new_resident->destination = destination;
|
||||
new_resident->passenger = NULL;
|
||||
new_resident->thread_number = -1;
|
||||
|
||||
LINK_ALL(Resident, new_resident,
|
||||
get_name,
|
||||
get_destination,
|
||||
get_id,
|
||||
runnable,
|
||||
get_apartment_floor
|
||||
get_name,
|
||||
get_destination,
|
||||
get_id,
|
||||
runnable,
|
||||
get_apartment_floor,
|
||||
set_thread_number
|
||||
)
|
||||
|
||||
return new_resident;
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
typedef struct o_Resident {
|
||||
PRIVATE int id;
|
||||
PRIVATE int thread_number;
|
||||
PRIVATE int apartment_floor;
|
||||
PRIVATE int destination;
|
||||
PRIVATE int position;
|
||||
@ -20,6 +21,7 @@ typedef struct o_Resident {
|
||||
PUBLIC int (*get_id)(_THIS(Resident));
|
||||
PUBLIC int (*get_apartment_floor)(_THIS(Resident));
|
||||
PUBLIC int (*get_destination)(_THIS(Resident));
|
||||
PUBLIC void (*set_thread_number)(_THIS(Resident), int data);
|
||||
|
||||
DESTRUCTOR(Resident);
|
||||
} Resident;
|
||||
|
Reference in New Issue
Block a user