2018-06-06 11:50:11 +00:00
|
|
|
//
|
|
|
|
// Created by Antoine Bartuccio on 06/06/2018.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LO41_SHAREDDATA_H
|
|
|
|
#define LO41_SHAREDDATA_H
|
|
|
|
|
2018-06-07 20:04:30 +00:00
|
|
|
#include <pthread.h>
|
2018-06-06 11:50:11 +00:00
|
|
|
#include "../Objects.h"
|
2018-06-07 20:04:30 +00:00
|
|
|
#include "../Building/Building.h"
|
2018-06-22 01:59:36 +00:00
|
|
|
#include "../ElevatorBreaker/ElevatorBreaker.h"
|
2018-06-07 20:04:30 +00:00
|
|
|
|
2018-06-06 11:50:11 +00:00
|
|
|
typedef struct o_SharedData {
|
2018-06-07 20:04:30 +00:00
|
|
|
PRIVATE int threads_nb;
|
2018-06-21 23:58:11 +00:00
|
|
|
PRIVATE int active_passengers;
|
2018-06-22 01:59:36 +00:00
|
|
|
PRIVATE ElevatorBreaker * elevator_breaker;
|
2018-06-22 00:50:04 +00:00
|
|
|
PRIVATE pthread_t ** threads;
|
2018-06-07 20:04:30 +00:00
|
|
|
PRIVATE Building * main_building;
|
2018-06-21 23:58:11 +00:00
|
|
|
PRIVATE pthread_mutex_t mutex_active_passengers;
|
2018-06-22 00:50:04 +00:00
|
|
|
PRIVATE pthread_mutex_t mutex_threads;
|
2018-06-07 20:04:30 +00:00
|
|
|
|
2018-06-10 23:58:52 +00:00
|
|
|
PRIVATE void (*start_thread)(_THIS(SharedData), void * (*thread)(void *), void * data, int thread_number);
|
|
|
|
|
|
|
|
PUBLIC void (*wait_all_threads)(_THIS(SharedData));
|
|
|
|
PUBLIC void (*start_all_threads)(_THIS(SharedData));
|
2018-06-07 20:04:30 +00:00
|
|
|
PUBLIC void (*set_main_building)(_THIS(SharedData), Building * building);
|
2018-06-07 22:49:20 +00:00
|
|
|
PUBLIC Building * (*get_main_building)(_THIS(SharedData));
|
2018-06-07 20:04:30 +00:00
|
|
|
PUBLIC int (*call_elevator)(_THIS(SharedData), int starting_floor, int destination_floor);
|
2018-06-11 09:09:08 +00:00
|
|
|
PUBLIC int (*use_call_box)(_THIS(SharedData), char * resident_name);
|
2018-06-21 23:58:11 +00:00
|
|
|
SYNCHRONIZE PUBLIC void (*decrement_active_passengers)(_THIS(SharedData));
|
|
|
|
SYNCHRONIZE PUBLIC int (*is_active_passengers_left)(_THIS(SharedData));
|
2018-06-22 00:50:04 +00:00
|
|
|
SYNCHRONIZE PUBLIC void (*unregister_thread)(_THIS(SharedData), int thread_number);
|
2018-06-06 11:50:11 +00:00
|
|
|
|
|
|
|
DESTRUCTOR(SharedData);
|
|
|
|
} SharedData;
|
|
|
|
|
|
|
|
SharedData *_get_instance_SharedData();
|
|
|
|
|
|
|
|
#endif //LO41_SHAREDDATA_H
|