Skip to content

Commit cf53860

Browse files
committed
[ppctty] add semaphore
1 parent 2517e27 commit cf53860

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

iop/debug/ppctty/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ IOP_INCS +=
1010

1111
IOP_OBJS = main.o tty.o imports.o
1212

13-
ifeq ($(KRPINTF), 1)
13+
ifeq ($(KPRINTF), 1)
1414
IOP_CFLAGS += -DKPRINTF
1515
endif
1616

17+
ifeq ($(DEBUG), 1)
18+
IOP_CFLAGS += -DDEBUG
19+
endif
20+
1721
include $(PS2SDKSRC)/Defs.make
1822
include $(PS2SDKSRC)/iop/Rules.bin.make
1923
include $(PS2SDKSRC)/iop/Rules.make

iop/debug/ppctty/src/imports.lst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ I_close
2727
I_AddDrv
2828
I_DelDrv
2929
ioman_IMPORTS_end
30+
31+
thsemap_IMPORTS_start
32+
I_CreateSema
33+
I_DeleteSema
34+
I_SignalSema
35+
I_WaitSema
36+
thsemap_IMPORTS_end

iop/debug/ppctty/src/irx_imports.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
#include "sysclib.h"
1717
#include "ioman.h"
1818
#include "modload.h"
19+
#include "thsemap.h"
1920

2021
#endif /* IOP_IRX_IMPORTS_H */

iop/debug/ppctty/src/tty.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ IOP->PPC TTY
1212
#include <excepman.h>
1313
#include <intrman.h>
1414
#include <ioman.h>
15+
#include <thsemap.h>
16+
static int tty_sema = -1;
1517

1618
extern void tty_puts(const char *str);
1719

@@ -20,12 +22,18 @@ static int ttyfs_error() { return -1; }
2022
static int ttyfs_init()
2123
{
2224
//DBG_puts("SIOTTY: FS Init()\n");
25+
if ((tty_sema = CreateMutex(IOP_MUTEX_UNLOCKED)) < 0)
26+
{
27+
DPRINTF("Failed to create mutex\n");
28+
return -1;
29+
}
2330
return 0;
2431
}
2532

2633
static int ttyfs_deinit()
2734
{
2835
//DBG_puts("SIOTTY: FS Deinit()\n");
36+
DeleteSema(tty_sema);
2937
return 0;
3038
}
3139

@@ -64,6 +72,7 @@ static int ttyfs_write(iop_file_t *file, void *ptr, int size) {
6472

6573
//DBG_puts("SIOTTY: FS Write()\n");
6674

75+
WaitSema(tty_sema);
6776
while(bCount < size)
6877
{
6978
int toWrite;
@@ -78,6 +87,7 @@ static int ttyfs_write(iop_file_t *file, void *ptr, int size) {
7887

7988
bCount += toWrite;
8089
}
90+
SignalSema(tty_sema);
8191

8292
return(bCount);
8393
}

0 commit comments

Comments
 (0)