mirror of
https://gitlab.com/klmp200/LO41.git
synced 2025-07-15 22:29:24 +00:00
Voilà comment gérer ses threads comme un boss
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
GETTER(Visitor, char*, name);
|
||||
GETTER(Visitor, int, destination);
|
||||
GETTER(Visitor, int, id);
|
||||
SETTER(Visitor, int, thread_number);
|
||||
|
||||
void * runnable_Visitor(void * void_this){
|
||||
Visitor *this = (Visitor*) void_this;
|
||||
@ -24,6 +25,7 @@ void * runnable_Visitor(void * void_this){
|
||||
printf("Visiteur %s : J'apelle à l'interphone\nVisiteur %s : J'apprends que %s habite à l'étage %d\n", this->name, this->name, this->contact_name, (this->destination = data->use_call_box(data, this->contact_name)));
|
||||
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;
|
||||
}
|
||||
|
||||
@ -44,6 +46,7 @@ Visitor *_init_Visitor(int id, char* name, char * contact_name){
|
||||
new_visitor->position = 0;
|
||||
new_visitor->destination = -1;
|
||||
new_visitor->passenger = NULL;
|
||||
new_visitor->thread_number = -1;
|
||||
|
||||
if (contact_name != NULL)
|
||||
new_visitor->contact_name = strdup(contact_name);
|
||||
@ -51,10 +54,11 @@ Visitor *_init_Visitor(int id, char* name, char * contact_name){
|
||||
new_visitor->contact_name = NULL;
|
||||
|
||||
LINK_ALL(Visitor, new_visitor,
|
||||
get_name,
|
||||
get_destination,
|
||||
get_id,
|
||||
runnable
|
||||
get_name,
|
||||
get_destination,
|
||||
get_id,
|
||||
runnable,
|
||||
set_thread_number
|
||||
);
|
||||
|
||||
return new_visitor;
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
typedef struct o_Visitor {
|
||||
PRIVATE int id;
|
||||
PRIVATE int thread_number;
|
||||
PRIVATE char * name;
|
||||
PRIVATE char * contact_name;
|
||||
PRIVATE int position;
|
||||
@ -19,6 +20,7 @@ typedef struct o_Visitor {
|
||||
PUBLIC char * (*get_name)(_THIS(Visitor));
|
||||
PUBLIC int (*get_id)(_THIS(Visitor));
|
||||
PUBLIC int (*get_destination)(_THIS(Visitor));
|
||||
PUBLIC void (*set_thread_number)(_THIS(Visitor), int data);
|
||||
|
||||
DESTRUCTOR(Visitor);
|
||||
} Visitor;
|
||||
|
Reference in New Issue
Block a user