-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleaner.c
More file actions
71 lines (62 loc) · 2.31 KB
/
Copy pathCleaner.c
File metadata and controls
71 lines (62 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "Common.h"
#include "Cleaner.h"
void free_param_list(param_list aus_list){
/* eseguo la free dello spazio allocato per i nodi della lista */
if (aus_list == NULL) {
return;
}
free_param_list(aus_list->next);
free(aus_list);
}
void cleaner(param_list listaParametri, int shd_id_values_to_source, values_to_source *shd_mem_values_to_source, int shd_id_values_to_taxi, values_to_taxi *shd_mem_values_to_taxi, int msg_queue_id, int sem_sync_id, int sem_cells_id, int **map, int **SO_CAP, pid_t **SO_SOURCES_PID, long int **SO_TIMENSEC_MAP, int free_so_taxis_pid, pid_t *SO_TAXIS_PID){
int i;
/* deallocazione malloc matrici */
free_param_list(listaParametri);
free_mat(0, map, SO_CAP, SO_SOURCES_PID, SO_TIMENSEC_MAP, free_so_taxis_pid, SO_TAXIS_PID, NULL);
/* deallocazione memoria condivisa */
if(shd_id_values_to_source)
shmdt(shd_mem_values_to_source);
if(shd_id_values_to_taxi)
shmdt(shd_mem_values_to_taxi);
/* dealloco la coda di messaggi e ottengo i messaggi rimasti non letti nella coda */
msgctl(msg_queue_id, IPC_RMID, NULL);
if(sem_sync_id != -1){
semctl(sem_sync_id, 0, IPC_RMID);
semctl(sem_sync_id, 1, IPC_RMID);
semctl(sem_sync_id, 2, IPC_RMID);
}
if(sem_cells_id)
for(i=0;i<SO_HEIGHT*SO_WIDTH;i++){
semctl(sem_cells_id, i, IPC_RMID);
}
}
void free_mat(int type, int **map, int **SO_CAP, pid_t **SO_SOURCES_PID, long int **SO_TIMENSEC_MAP, int free_so_taxis_pid, pid_t *SO_TAXIS_PID, taxi_returned_values *aus_shd_mem_taxi_returned_values){
int i;
int *currentIntPtr;
long int *currentLongPtr;
pid_t *currentPid_tPtr;
for (i = 0; i < SO_HEIGHT; i++){
currentIntPtr = map[i];
free(currentIntPtr);
if(type == 0){
currentIntPtr = SO_CAP[i];
free(currentIntPtr);
currentPid_tPtr = SO_SOURCES_PID[i];
free(currentPid_tPtr);
}
if(type == 1){
currentLongPtr = SO_TIMENSEC_MAP[i];
free(currentLongPtr);
}
}
if(type == 0){
if(free_so_taxis_pid)
free(SO_TAXIS_PID);
free(map);
free(SO_CAP);
free(SO_TIMENSEC_MAP);
free(SO_SOURCES_PID);
}
if(type == 1)
free(aus_shd_mem_taxi_returned_values);
}