Make changes to the pipes implementation
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
10783bd50e
commit
ab402462c5
|
@ -21,12 +21,12 @@ uint64_t read(uint64_t fd, uint64_t buffer, uint64_t length) {
|
||||||
char *bufferAux = (char *) buffer;
|
char *bufferAux = (char *) buffer;
|
||||||
int readBytes = 0;
|
int readBytes = 0;
|
||||||
|
|
||||||
if (!isForeground())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
fd = getFdIn();
|
fd = getFdIn();
|
||||||
|
|
||||||
if (fd == STDIN) {
|
if (fd == STDIN) {
|
||||||
|
if (!isForeground())
|
||||||
|
return 0;
|
||||||
|
|
||||||
while (length-- > 0) {
|
while (length-- > 0) {
|
||||||
*bufferAux = getKeyFromBuffer();
|
*bufferAux = getKeyFromBuffer();
|
||||||
if (*bufferAux == 0) {
|
if (*bufferAux == 0) {
|
||||||
|
@ -35,12 +35,10 @@ uint64_t read(uint64_t fd, uint64_t buffer, uint64_t length) {
|
||||||
readBytes--;
|
readBytes--;
|
||||||
blockIO();
|
blockIO();
|
||||||
}
|
}
|
||||||
if (*bufferAux == '\v') {
|
|
||||||
return 0;
|
|
||||||
// break;
|
|
||||||
}
|
|
||||||
readBytes++;
|
readBytes++;
|
||||||
bufferAux++;
|
if (*bufferAux++ == '\v') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
// blockIO();
|
// blockIO();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -48,10 +46,13 @@ uint64_t read(uint64_t fd, uint64_t buffer, uint64_t length) {
|
||||||
*bufferAux = readPipe(fd);
|
*bufferAux = readPipe(fd);
|
||||||
if (*bufferAux == 0)
|
if (*bufferAux == 0)
|
||||||
break;
|
break;
|
||||||
bufferAux++;
|
|
||||||
readBytes++;
|
readBytes++;
|
||||||
|
if (*bufferAux++ == '\v') {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// *bufferAux = 0;
|
||||||
|
|
||||||
return readBytes;
|
return readBytes;
|
||||||
}
|
}
|
|
@ -88,20 +88,20 @@ void writePipe(int fd, char c) {
|
||||||
|
|
||||||
semWait(node->pipe->sem);
|
semWait(node->pipe->sem);
|
||||||
|
|
||||||
semPost(node->pipe->fullSem);
|
|
||||||
|
|
||||||
node->pipe->buffer[node->pipe->currentW++ % PIPE_MAX_SIZE] = c;
|
node->pipe->buffer[node->pipe->currentW++ % PIPE_MAX_SIZE] = c;
|
||||||
|
|
||||||
semPost(node->pipe->sem);
|
semPost(node->pipe->sem);
|
||||||
|
|
||||||
|
semPost(node->pipe->fullSem);
|
||||||
}
|
}
|
||||||
|
|
||||||
char readPipe(int fd) {
|
char readPipe(int fd) {
|
||||||
node_t *prev = NULL;
|
node_t *prev = NULL;
|
||||||
node_t *node = searchRPipe(&prev, fd);
|
node_t *node = searchRPipe(&prev, fd);
|
||||||
|
|
||||||
semWait(node->pipe->sem);
|
semWait(node->pipe->fullSem);
|
||||||
|
|
||||||
semPost(node->pipe->fullSem);
|
semWait(node->pipe->sem);
|
||||||
|
|
||||||
char c = node->pipe->buffer[node->pipe->currentR++ % PIPE_MAX_SIZE];
|
char c = node->pipe->buffer[node->pipe->currentR++ % PIPE_MAX_SIZE];
|
||||||
|
|
||||||
|
|
|
@ -234,14 +234,14 @@ char blockIO() {
|
||||||
currentProcess->state = BLOCKEDIO;
|
currentProcess->state = BLOCKEDIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
processCDT *prev = NULL;
|
// processCDT *prev = NULL;
|
||||||
processADT parent = searchProcess(&prev, currentProcess->ppid, firstProcess);
|
// processADT parent = searchProcess(&prev, currentProcess->ppid, firstProcess);
|
||||||
if (currentProcess->foreground) {
|
// if (currentProcess->foreground) {
|
||||||
if (parent->backWait) {
|
// if (parent->backWait) {
|
||||||
parent->backWait = 0;
|
// parent->backWait = 0;
|
||||||
parent->foreground = 1;
|
// parent->foreground = 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
forceTimer();
|
forceTimer();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -14,5 +14,4 @@ clean:
|
||||||
cd SampleCodeModule; make clean
|
cd SampleCodeModule; make clean
|
||||||
rm -rf *.bin
|
rm -rf *.bin
|
||||||
|
|
||||||
|
|
||||||
.PHONY: sampleCodeModule all clean
|
.PHONY: sampleCodeModule all clean
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
include ../Makefile.inc
|
include ../Makefile.inc
|
||||||
|
|
||||||
MODULE=0000-sampleCodeModule.bin
|
MODULE=../0000-sampleCodeModule.bin
|
||||||
MODULE_ELF=0000-sampleCodeModule.elf
|
MODULE_ELF=../0000-sampleCodeModule.elf
|
||||||
SOURCES=$(wildcard *.c)
|
SOURCES=$(wildcard *.c)
|
||||||
SOURCES_SHELL=$(wildcard shell/*.c)
|
SOURCES_SHELL=$(wildcard shell/*.c)
|
||||||
SOURCES_ASM=$(wildcard asm/*.asm)
|
SOURCES_ASM=$(wildcard asm/*.asm)
|
||||||
|
@ -13,17 +13,17 @@ OBJECTS_PROMPT=$(SOURCES_PROMPT:.c=.o)
|
||||||
OBJECTS_BOTTLER=$(SOURCES_BOTTLER:.c=.o)
|
OBJECTS_BOTTLER=$(SOURCES_BOTTLER:.c=.o)
|
||||||
OBJECTS_ASM=$(SOURCES_ASM:.asm=.o)
|
OBJECTS_ASM=$(SOURCES_ASM:.asm=.o)
|
||||||
|
|
||||||
ALL_OBJECTS= $(OBJECTS) $(OBJECTS_ASM) $(OBJECTS_SHELL) $(OBJECTS_COMMANDS) $(OBJECTS_PROMPT) $(OBJECTS_BOTTLER)
|
ALL_OBJECTS= $(OBJECTS) $(OBJECTS_ASM) $(OBJECTS_SHELL) $(OBJECTS_PROMPT) $(OBJECTS_BOTTLER)
|
||||||
|
|
||||||
STATICLIBS=
|
STATICLIBS=
|
||||||
|
|
||||||
all: $(MODULE) $(MODULE_ELF)
|
all: $(MODULE) $(MODULE_ELF)
|
||||||
|
|
||||||
$(MODULE): $(STATICLIBS) $(ALL_OBJECTS)
|
$(MODULE): $(STATICLIBS) $(ALL_OBJECTS)
|
||||||
$(LD) $(LDFLAGS) -T sampleCodeModule.ld $(OBJECTS) $(OBJECTS_SHELL) $(OBJECTS_ASM) $(OBJECTS_PROMPT) $(OBJECTS_BOTTLER) -o ../$(MODULE)
|
$(LD) $(LDFLAGS) -T sampleCodeModule.ld -o $@ $^
|
||||||
|
|
||||||
$(MODULE_ELF): $(STATICLIBS) $(ALL_OBJECTS)
|
$(MODULE_ELF): $(STATICLIBS) $(ALL_OBJECTS)
|
||||||
$(LD) $(LDFLAGS) -I./include -I./shell/include -I./bottler/include -T sampleCodeModule.ld --oformat=elf64-x86-64 $(OBJECTS) $(OBJECTS_SHELL) $(OBJECTS_ASM) $(OBJECTS_PROMPT) $(OBJECTS_BOTTLER) -o ../$(MODULE_ELF)
|
$(LD) $(LDFLAGS) -T sampleCodeModule.ld --oformat=elf64-x86-64 -o $@ $^
|
||||||
|
|
||||||
%.o:%.c
|
%.o:%.c
|
||||||
$(GCC) $(GCCFLAGS) -T _loader.c -I./include -I./shell/include -I./bottler/include -c $< -o $@
|
$(GCC) $(GCCFLAGS) -T _loader.c -I./include -I./shell/include -I./bottler/include -c $< -o $@
|
||||||
|
@ -32,6 +32,6 @@ $(MODULE_ELF): $(STATICLIBS) $(ALL_OBJECTS)
|
||||||
$(ASM) $(ASMFLAGS) $< -o $@
|
$(ASM) $(ASMFLAGS) $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(ALL_OBJECTS)
|
rm -rf $(ALL_OBJECTS) ../*.bin
|
||||||
|
|
||||||
.PHONY: all clean print
|
.PHONY: all clean print
|
|
@ -7,7 +7,7 @@ void winClear();
|
||||||
void printString(char * string);
|
void printString(char * string);
|
||||||
void printStringError(char * string);
|
void printStringError(char * string);
|
||||||
void printStringLen(char * string, int len);
|
void printStringLen(char * string, int len);
|
||||||
void new_line();
|
void newline();
|
||||||
void backspace();
|
void backspace();
|
||||||
char getChar();
|
char getChar();
|
||||||
void putChar(char c);
|
void putChar(char c);
|
||||||
|
@ -28,5 +28,6 @@ char * strstrip(char * s, char c);
|
||||||
void ftoa(double f, char * buf, int precision);
|
void ftoa(double f, char * buf, int precision);
|
||||||
char * strcat(char * dest, const char * src);
|
char * strcat(char * dest, const char * src);
|
||||||
int strcpy(char * strDest, const char * strSrc);
|
int strcpy(char * strDest, const char * strSrc);
|
||||||
|
void addEOF();
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -2,39 +2,28 @@
|
||||||
|
|
||||||
#define SIZE 1000
|
#define SIZE 1000
|
||||||
|
|
||||||
/*
|
|
||||||
void cat(int argc, char ** argv) {
|
|
||||||
char c;
|
|
||||||
int i = 0;
|
|
||||||
char buffer[SIZE] = {0};
|
|
||||||
while ((c = getChar()) != 0 && c != -1) {
|
|
||||||
if (i >= SIZE)
|
|
||||||
break;
|
|
||||||
buffer[i++] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
printStringLen(buffer, i);
|
|
||||||
sys_exit();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void cat(int argc, char ** argv) {
|
void cat(int argc, char ** argv) {
|
||||||
char c;
|
char c;
|
||||||
int i = 0, j = 0, line = 0;
|
int i = 0, j = 0, line = 0;
|
||||||
char buffer[SIZE] = {0};
|
char buffer[SIZE] = {0};
|
||||||
|
|
||||||
while ((c = getChar()) <= 0) {
|
while ((c = getChar()) > 0) {
|
||||||
if (i >= SIZE)
|
if (i >= SIZE)
|
||||||
break;
|
break;
|
||||||
|
buffer[i++] = c;
|
||||||
|
j++;
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
printStringLen(buffer[line], j);
|
printStringLen(buffer + line, j);
|
||||||
j = 0;
|
j = 0;
|
||||||
line = i;
|
line = i;
|
||||||
}
|
}
|
||||||
buffer[i++] = c;
|
if (c == '\b') {
|
||||||
j++;
|
buffer[--i] = 0;
|
||||||
|
buffer[--i] = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
printStringLen(buffer + line, j);
|
||||||
|
|
||||||
printStringLen(buffer, i);
|
newline();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -104,8 +104,9 @@ void cpufeatures(int argc, char *argv[]) {
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
if (checks[i]()) {
|
if (checks[i]()) {
|
||||||
printString(supports[i]);
|
printString(supports[i]);
|
||||||
new_line();
|
newline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addEOF();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,30 +6,31 @@ int isVocal(char c) {
|
||||||
return c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' || c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
|
return c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' || c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug8()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void debug9()
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void filter(int argc, char ** argv) {
|
void filter(int argc, char ** argv) {
|
||||||
char c;
|
char c;
|
||||||
int i = 0;
|
int i = 0, j = 0, line = 0;
|
||||||
char buffer[SIZE] = {0};
|
char buffer[SIZE] = {0};
|
||||||
debug9();
|
while ((c = getChar()) > 0) {
|
||||||
while ((c = getChar()) != 0 && c != -1) {
|
|
||||||
debug8();
|
|
||||||
if (i >= SIZE)
|
if (i >= SIZE)
|
||||||
break;
|
break;
|
||||||
if (isVocal(c))
|
if (!isVocal(c)) {
|
||||||
buffer[i++] = c;
|
buffer[i++] = c;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
if (c == '\b') {
|
||||||
|
buffer[--i] = 0;
|
||||||
|
if (isVocal(buffer[i-1]))
|
||||||
|
buffer[--i] = 0;
|
||||||
|
}
|
||||||
|
if (c == '\n') {
|
||||||
|
printStringLen(buffer + line, j);
|
||||||
|
j = 0;
|
||||||
|
line = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printStringLen(buffer, i);
|
printStringLen(buffer + line, j);
|
||||||
new_line();
|
|
||||||
|
newline();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -7,7 +7,8 @@ static const int len = 9;
|
||||||
void help(int argc, char *argv[]) {
|
void help(int argc, char *argv[]) {
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
printString(info[i]);
|
printString(info[i]);
|
||||||
new_line();
|
newline();
|
||||||
}
|
}
|
||||||
|
addEOF();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -17,13 +17,14 @@ void inforeg(int argc, char *argv[]) {
|
||||||
|
|
||||||
for (int i = 0; i < 17; i++) {
|
for (int i = 0; i < 17; i++) {
|
||||||
if (i % 5 == 0 && i != 0)
|
if (i % 5 == 0 && i != 0)
|
||||||
new_line();
|
newline();
|
||||||
printString(regsNames[i]);
|
printString(regsNames[i]);
|
||||||
printStringLen("0x", 2);
|
printStringLen("0x", 2);
|
||||||
printString(gtoa(regs[i], bufferAux, 16, 20));
|
printString(gtoa(regs[i], bufferAux, 16, 20));
|
||||||
if (i != 14 && i % 5 != 4)
|
if (i != 14 && i % 5 != 4)
|
||||||
printStringLen(" - ", 3);
|
printStringLen(" - ", 3);
|
||||||
}
|
}
|
||||||
new_line();
|
addEOF();
|
||||||
|
newline();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ void loop(int argc, char *argv[]) {
|
||||||
buffer = strcat(strcat(itoa(pid, buffer, 10), " "), str);
|
buffer = strcat(strcat(itoa(pid, buffer, 10), " "), str);
|
||||||
while (1) {
|
while (1) {
|
||||||
printString(buffer);
|
printString(buffer);
|
||||||
putChar('\n');
|
newline();
|
||||||
sys_sleep(secs);
|
sys_sleep(secs);
|
||||||
}
|
}
|
||||||
sys_free(buffer);
|
sys_free(buffer);
|
||||||
|
|
|
@ -1,32 +1,7 @@
|
||||||
#include "phylo.h"
|
#include "phylo.h"
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define ARGV_SIZE 2
|
|
||||||
#define BUFF_SIZE 20
|
|
||||||
#define MAX_PHILO_SIZE 3
|
|
||||||
#define MAX_NAME_SIZE 10
|
|
||||||
#define STARTING 5
|
|
||||||
|
|
||||||
int * state;
|
|
||||||
typedef enum states {EATING = 0, HUNGRY, THINKING} states;
|
|
||||||
|
|
||||||
typedef struct philosopher_t {
|
|
||||||
int debug;
|
|
||||||
char ** argv;
|
|
||||||
char * buffer;
|
|
||||||
sem_t * sem;
|
|
||||||
int pid;
|
|
||||||
states state;
|
|
||||||
|
|
||||||
struct philosopher_t * left;
|
|
||||||
struct philosopher_t * right;
|
|
||||||
} philosopher_t;
|
|
||||||
|
|
||||||
philosopher_t *firstPhil;
|
philosopher_t *firstPhil;
|
||||||
|
|
||||||
sem_t *mutex;
|
sem_t *mutex;
|
||||||
|
|
||||||
int philoCount = STARTING;
|
int philoCount = STARTING;
|
||||||
|
|
||||||
void printState() {
|
void printState() {
|
||||||
|
@ -37,7 +12,7 @@ void printState() {
|
||||||
else putChar('.');
|
else putChar('.');
|
||||||
phil = phil->right;
|
phil = phil->right;
|
||||||
} while (phil != firstPhil);
|
} while (phil != firstPhil);
|
||||||
putChar('\n');
|
newline();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test(philosopher_t * phil)
|
void test(philosopher_t * phil)
|
||||||
|
@ -48,8 +23,6 @@ void test(philosopher_t * phil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void philosopher(int argc, char ** argv);
|
|
||||||
|
|
||||||
void addPhilo() {
|
void addPhilo() {
|
||||||
philoCount++;
|
philoCount++;
|
||||||
|
|
||||||
|
@ -60,8 +33,6 @@ void addPhilo() {
|
||||||
new->sem = sys_semOpen("filosofo", 0);
|
new->sem = sys_semOpen("filosofo", 0);
|
||||||
|
|
||||||
new->argv[0] = "filosofo";
|
new->argv[0] = "filosofo";
|
||||||
// new->argv[1] = itoa((uint64_t) new, new->argv[1], 10);
|
|
||||||
// strcpy(phil->buffer, itoa((uint64_t) phil, phil->buffer, 10));
|
|
||||||
strcpy(new->buffer, itoa((uint64_t) new, new->buffer, 10));
|
strcpy(new->buffer, itoa((uint64_t) new, new->buffer, 10));
|
||||||
new->argv[1] = new->buffer;
|
new->argv[1] = new->buffer;
|
||||||
|
|
||||||
|
@ -98,12 +69,9 @@ void take_fork(philosopher_t * phil) {
|
||||||
sys_semPost(mutex);
|
sys_semPost(mutex);
|
||||||
|
|
||||||
sys_semWait(phil->sem);
|
sys_semWait(phil->sem);
|
||||||
|
|
||||||
// sys_sleep(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void put_fork(philosopher_t * phil) {
|
void put_fork(philosopher_t * phil) {
|
||||||
|
|
||||||
sys_semWait(mutex);
|
sys_semWait(mutex);
|
||||||
|
|
||||||
phil->state = THINKING;
|
phil->state = THINKING;
|
||||||
|
@ -114,8 +82,7 @@ void put_fork(philosopher_t * phil) {
|
||||||
sys_semPost(mutex);
|
sys_semPost(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void philosopher(int argc, char ** argv)
|
void philosopher(int argc, char ** argv) {
|
||||||
{
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
|
@ -123,14 +90,12 @@ void philosopher(int argc, char ** argv)
|
||||||
philosopher_t * i = (philosopher_t *) ((uint64_t) atoi(argv[1], -1));
|
philosopher_t * i = (philosopher_t *) ((uint64_t) atoi(argv[1], -1));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// sys_sleep(1);
|
|
||||||
sys_sleep(1);
|
sys_sleep(1);
|
||||||
|
|
||||||
take_fork(i);
|
take_fork(i);
|
||||||
printState();
|
printState();
|
||||||
|
|
||||||
sys_sleep(1);
|
sys_sleep(1);
|
||||||
// sys_sleep(2);
|
|
||||||
|
|
||||||
put_fork(i);
|
put_fork(i);
|
||||||
printState();
|
printState();
|
||||||
|
@ -162,7 +127,6 @@ void phylo(int argc, char ** argv) {
|
||||||
phil->sem = sys_semOpen("filosofo", 0);
|
phil->sem = sys_semOpen("filosofo", 0);
|
||||||
|
|
||||||
phil->argv[0] = "filosofo";
|
phil->argv[0] = "filosofo";
|
||||||
// phil->argv[1] = itoa((uint64_t) phil, phil->argv[1], 10);
|
|
||||||
strcpy(phil->buffer, itoa((uint64_t) phil, phil->buffer, 10));
|
strcpy(phil->buffer, itoa((uint64_t) phil, phil->buffer, 10));
|
||||||
phil->argv[1] = phil->buffer;
|
phil->argv[1] = phil->buffer;
|
||||||
|
|
||||||
|
@ -190,7 +154,7 @@ void phylo(int argc, char ** argv) {
|
||||||
} while (phil != firstPhil);
|
} while (phil != firstPhil);
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
while (1) {
|
// while (1) {
|
||||||
while ((c = getChar()) != 0 && c != -1) {
|
while ((c = getChar()) != 0 && c != -1) {
|
||||||
if (c == 'a') {
|
if (c == 'a') {
|
||||||
addPhilo();
|
addPhilo();
|
||||||
|
@ -202,12 +166,10 @@ void phylo(int argc, char ** argv) {
|
||||||
end();
|
end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "ps.h"
|
|
||||||
|
|
||||||
void freePhilo(philosopher_t * phil) {
|
void freePhilo(philosopher_t * phil) {
|
||||||
sys_semClose(phil->sem);
|
sys_semClose(phil->sem);
|
||||||
sys_free(phil);
|
sys_free(phil);
|
||||||
|
@ -232,12 +194,7 @@ void end() {
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// La primera es muy similar a:
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Taken from "Operating Systems - Design and Implementation" by Tanenbaum
|
* Taken from "Operating Systems - Design and Implementation" by Tanenbaum
|
||||||
* Section 2.3, page 91, Figure 2-10
|
* Section 2.3, page 91, Figure 2-10
|
||||||
* https://gist.github.com/codelance/4186161
|
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
void pipes(int argc, char *argv[]) {
|
void pipes(int argc, char *argv[]) {
|
||||||
char * output = sys_pipes();
|
char * output = sys_pipes();
|
||||||
printString(output);
|
printString(output);
|
||||||
new_line();
|
newline();
|
||||||
sys_free(output);
|
sys_free(output);
|
||||||
|
addEOF();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -28,7 +28,8 @@ void printmem(int argc, char *argv[]) {
|
||||||
char bufferAux[8];
|
char bufferAux[8];
|
||||||
printStringLen("0x", 2);
|
printStringLen("0x", 2);
|
||||||
printString(itoa(buffer[i], bufferAux, 16));
|
printString(itoa(buffer[i], bufferAux, 16));
|
||||||
new_line();
|
newline();
|
||||||
}
|
}
|
||||||
|
addEOF();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -4,7 +4,8 @@
|
||||||
void ps(int argc, char *argv[]) {
|
void ps(int argc, char *argv[]) {
|
||||||
char * output = sys_ps();
|
char * output = sys_ps();
|
||||||
printString(output);
|
printString(output);
|
||||||
new_line();
|
addEOF();
|
||||||
|
newline();
|
||||||
sys_free(output);
|
sys_free(output);
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -32,13 +32,14 @@ void quadratic(int argc, char *argv[]) {
|
||||||
printString("x + ");
|
printString("x + ");
|
||||||
ftoa(c, buffer, 10);
|
ftoa(c, buffer, 10);
|
||||||
printString(buffer);
|
printString(buffer);
|
||||||
new_line();
|
newline();
|
||||||
ftoa(sol1, buffer, 10);
|
ftoa(sol1, buffer, 10);
|
||||||
printString(buffer);
|
printString(buffer);
|
||||||
printStringLen(" and ", 6);
|
printStringLen(" and ", 6);
|
||||||
char buffer2[30] = {0};
|
char buffer2[30] = {0};
|
||||||
ftoa(sol2, buffer2, 10);
|
ftoa(sol2, buffer2, 10);
|
||||||
printString(buffer2);
|
printString(buffer2);
|
||||||
new_line();
|
addEOF();
|
||||||
|
newline();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -4,7 +4,8 @@
|
||||||
void sem(int argc, char *argv[]) {
|
void sem(int argc, char *argv[]) {
|
||||||
char * output = sys_sem();
|
char * output = sys_sem();
|
||||||
printString(output);
|
printString(output);
|
||||||
new_line();
|
newline();
|
||||||
sys_free(output);
|
sys_free(output);
|
||||||
|
addEOF();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -47,5 +47,7 @@ void time(int argc, char *argv[]) {
|
||||||
printTime(getMinutes());
|
printTime(getMinutes());
|
||||||
putChar(':');
|
putChar(':');
|
||||||
printTime(getSeconds());
|
printTime(getSeconds());
|
||||||
|
addEOF();
|
||||||
|
newline();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ void wc(int argc, char ** argv) {
|
||||||
char c;
|
char c;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char buffer[SIZE] = {0};
|
char buffer[SIZE] = {0};
|
||||||
while ((c = getChar()) != 0 && c != -1) {
|
while ((c = getChar()) > 0) {
|
||||||
if (i >= SIZE)
|
if (i >= SIZE)
|
||||||
break;
|
break;
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
|
@ -14,5 +14,6 @@ void wc(int argc, char ** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
printStringLen(gtoa(i, buffer, 10, SIZE), SIZE);
|
printStringLen(gtoa(i, buffer, 10, SIZE), SIZE);
|
||||||
|
newline();
|
||||||
sys_exit();
|
sys_exit();
|
||||||
}
|
}
|
|
@ -1,9 +1,33 @@
|
||||||
#ifndef PHYLO_LIB
|
#ifndef PHYLO_H
|
||||||
#define PHYLO_LIB
|
#define PHYLO_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include "libc.h"
|
#include "libc.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
#include "phyloLib.h"
|
||||||
|
|
||||||
void phylo(int argc, char *argv[]);
|
#define ARGV_SIZE 2
|
||||||
|
#define BUFF_SIZE 20
|
||||||
|
#define MAX_PHILO_SIZE 3
|
||||||
|
#define MAX_NAME_SIZE 10
|
||||||
|
#define STARTING 5
|
||||||
|
|
||||||
|
int * state;
|
||||||
|
typedef enum states {EATING = 0, HUNGRY, THINKING} states;
|
||||||
|
|
||||||
|
typedef struct philosopher_t {
|
||||||
|
int debug;
|
||||||
|
char ** argv;
|
||||||
|
char * buffer;
|
||||||
|
sem_t * sem;
|
||||||
|
int pid;
|
||||||
|
states state;
|
||||||
|
|
||||||
|
struct philosopher_t * left;
|
||||||
|
struct philosopher_t * right;
|
||||||
|
} philosopher_t;
|
||||||
|
|
||||||
|
void philosopher(int argc, char ** argv);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef PHYLOLIB_H
|
||||||
|
#define PHYLOLIB_H
|
||||||
|
|
||||||
|
void phylo(int argc, char *argv[]);
|
||||||
|
|
||||||
|
#endif
|
|
@ -21,7 +21,7 @@
|
||||||
#include "semCom.h"
|
#include "semCom.h"
|
||||||
#include "stddef.h"
|
#include "stddef.h"
|
||||||
#include "nice.h"
|
#include "nice.h"
|
||||||
#include "phylo.h"
|
#include "phyloLib.h"
|
||||||
#include "kill.h"
|
#include "kill.h"
|
||||||
#include "block.h"
|
#include "block.h"
|
||||||
#include "unblock.h"
|
#include "unblock.h"
|
||||||
|
|
Loading…
Reference in New Issue