-
Notifications
You must be signed in to change notification settings - Fork 0
/
disastrOS_semclose.c
61 lines (51 loc) · 1.48 KB
/
disastrOS_semclose.c
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
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include "disastrOS.h"
#include "disastrOS_syscalls.h"
#include "disastrOS_semaphore.h"
#include "disastrOS_semdescriptor.h"
#include "pool_allocator.h"
void internal_semClose() {
int id = running->syscall_args[0];
int ret;
SemDescriptor *sem_des = SemDescriptorList_byFd(&(running->sem_descriptors), id);
if(!sem_des) {
running->syscall_retvalue = DSOS_ESEMCLOSEDESNF;
return;
}
Semaphore *sem = sem_des->semaphore;
List_detach(&(sem->descriptors), (ListItem*)sem_des->ptr);
if (!(sem->descriptors).size) {
sem = (Semaphore*) List_detach(&semaphores_list, (ListItem*) sem);
(sem->descriptors).first = 0;
(sem->descriptors).last = 0;
ret = Semaphore_free(sem);
if (ret != 0x0) {
printf("Errore Semaphore_free: %s\n",PoolAllocator_strerror((PoolAllocatorResult) ret));
running->syscall_retvalue = DSOS_ESEMFREE;
return;
}
}
SemDescriptorPtr *sem_des_ptr = sem_des->ptr;
SemDescriptorPtr *sem_des_ptr_wtr = sem_des->ptr_wtr;
ret = SemDescriptor_free(sem_des);
if(ret != 0x0) {
running->syscall_retvalue = DSOS_ESEMDESFREE;
return;
}
ret = SemDescriptorPtr_free(sem_des_ptr);
if(ret != 0x0) {
running->syscall_retvalue = DSOS_ESEMDESPTRFREE;
return;
}
ret = SemDescriptorPtr_free(sem_des_ptr_wtr);
if(ret != 0x0) {
running->syscall_retvalue = DSOS_ESEMDESPTRFREE;
return;
}
else {
running->syscall_retvalue = 0;
return;
}
}