mirror of
https://gitlab.com/klmp200/LO41.git
synced 2024-11-22 16:53:21 +00:00
42 lines
1.0 KiB
C
42 lines
1.0 KiB
C
//
|
|
// Created by Antoine Bartuccio on 05/06/2018.
|
|
//
|
|
|
|
#include <string.h>
|
|
#include "Elevator.h"
|
|
|
|
void _free__Elevator(THIS(Elevator)){
|
|
DELETE(this->passenger_ids);
|
|
if (this->name != NULL)
|
|
free(this->name);
|
|
pthread_mutex_unlock(&this->passenger_mutex);
|
|
pthread_mutex_destroy(&this->passenger_mutex);
|
|
free(this);
|
|
}
|
|
|
|
int get_number_of_passengers_Elevator(THIS(Elevator)){
|
|
int num;
|
|
pthread_mutex_lock(&this->passenger_mutex);
|
|
num = this->passenger_ids->get_size(this->passenger_ids);
|
|
pthread_mutex_lock(&this->passenger_mutex);
|
|
return num;
|
|
}
|
|
|
|
int can_get_more_passengers_Elevator(_THIS(Elevator)){
|
|
return (this->get_number_of_passengers(this) < MAX_ELEVATOR_CAPACITY);
|
|
}
|
|
|
|
Elevator *_init_Elevator(char * name){
|
|
Elevator * new_elevator = malloc_or_die(sizeof(Elevator));
|
|
new_elevator->state = waiting;
|
|
new_elevator->name = strdup(name);
|
|
new_elevator->passenger_ids = NEW(List);
|
|
pthread_mutex_init(&new_elevator->passenger_mutex, NULL);
|
|
|
|
LINK_ALL(Elevator, new_elevator,
|
|
get_number_of_passengers,
|
|
can_get_more_passengers
|
|
);
|
|
|
|
return new_elevator;
|
|
} |