Skip to content

Commit

Permalink
Semaphore bugs fixed. Multiple process sync now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
JuArce committed May 22, 2021
1 parent 565d6a8 commit 4c5fd5a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions Kernel/utilities/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ int semOpen(char *semId, uint64_t initialValue) {
acquire(&lock);

int firstFree = -1;
// int found = 0;
int i;
for (i = 0; i < TOTAL_SEMS && firstFree == -1; i++) {
for (i = 0; i < TOTAL_SEMS; i++) {
if (strlen(semaphores[i].semId) != 0) {
if (strcmp(semaphores[i].semId, semId) == 0) {
// found = 1;
semaphores[i].attached++;
release(&lock);
return 1;
Expand All @@ -44,7 +42,7 @@ int semOpen(char *semId, uint64_t initialValue) {

if (firstFree != -1) {
strcpy(semaphores[firstFree].semId, semId);
semaphores[i].blockedProcesses = newQueue();
semaphores[firstFree].blockedProcesses = newQueue();
semaphores[firstFree].value = initialValue;
semaphores[firstFree].attached = 1;

Expand Down
1 change: 1 addition & 0 deletions Userland/SampleCodeModule/asm/lib64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ invalidOpCode:
UD2
ret

;TODO Modificar para que llame a una interrupcion que cambie de contexto de una, sin importar prioridad.
yield:
int 20h;
ret
2 changes: 1 addition & 1 deletion Userland/SampleCodeModule/utilities/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void initShell() {
// test_prio();
// test_processes();
// test_no_sync();
test_sync();
// test_sync();


char c;
Expand Down
9 changes: 4 additions & 5 deletions Userland/SampleCodeModule/utilities/test_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uint64_t my_sem_close(char *sem_id) {
return semClose(sem_id);
}

#define TOTAL_PAIR_PROCESSES 1
#define TOTAL_PAIR_PROCESSES 10
#define SEM_ID "sem"

int64_t global; //shared memory
Expand All @@ -50,9 +50,8 @@ void inc(uint64_t sem, int64_t value, uint64_t N) {
for (i = 0; i < N; i++) {
if (sem) my_sem_wait(SEM_ID);
slowInc(&global, value);
printc("parcial: ", 0x00FF00);
printc(", ", 0x00FF00);
printInt(global);
print(" ");
if (sem) my_sem_post(SEM_ID);
}

Expand All @@ -72,8 +71,8 @@ void test_sync() {
print("CREATING PROCESSES...(WITH SEM)\n");

for (i = 0; i < TOTAL_PAIR_PROCESSES; i++) {
my_create_process((uint64_t * ) & inc, 1, 1, 20);
my_create_process((uint64_t * ) & inc, 1, 1, 20);
my_create_process((uint64_t * ) & inc, 1, 10, 500);
my_create_process((uint64_t * ) & inc, 1, 10, 500);
}
}

Expand Down

0 comments on commit 4c5fd5a

Please sign in to comment.