diff options
author | Christian Cunningham <cc@localhost> | 2022-02-13 17:45:33 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-02-13 17:45:33 -0700 |
commit | 1a5a0e5cd6f82535c80f7a88b2b4dfac222fa2bb (patch) | |
tree | cb2d3161723656116d3d91d234ff65a989f5d22c | |
parent | 1a3e539f46911081170c9b2515331cfed5c00f05 (diff) |
Implement Lock on Drawer
-rw-r--r-- | include/graphics/drawer.h | 3 | ||||
-rw-r--r-- | src/graphics/drawer.c | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/include/graphics/drawer.h b/include/graphics/drawer.h index 67abca0..b654989 100644 --- a/include/graphics/drawer.h +++ b/include/graphics/drawer.h @@ -1,9 +1,12 @@ #ifndef GRAPHICS_DRAWER_H #define GRAPHICS_DRAWER_H +#include <util/lock.h> + struct Drawer { unsigned int x; unsigned int y; + struct Lock l; }; void write_cchar(struct Drawer* d, char s, unsigned int c); diff --git a/src/graphics/drawer.c b/src/graphics/drawer.c index 4445919..dc0ffe1 100644 --- a/src/graphics/drawer.c +++ b/src/graphics/drawer.c @@ -3,6 +3,7 @@ void write_cchar(struct Drawer* d, char s, unsigned int c) { + lock(&d->l); d->x %= GG_MAX_X; d->y %= GG_MAX_Y; if (s == 0x0A) { @@ -15,6 +16,7 @@ void write_cchar(struct Drawer* d, char s, unsigned int c) d->x = 0; } } + unlock(&d->l); // CHECK Y EVENTUALLY } @@ -25,6 +27,7 @@ void write_char(struct Drawer* d, char s) void write_cstring(struct Drawer* d, char* s, unsigned int c) { + lock(&d->l); d->x %= GG_MAX_X; d->y %= GG_MAX_Y; unsigned int idx = 0; @@ -42,6 +45,7 @@ void write_cstring(struct Drawer* d, char* s, unsigned int c) } // CHECK Y EVENTUALLY } + unlock(&d->l); } void write_string(struct Drawer* d, char* s) @@ -51,12 +55,14 @@ void write_string(struct Drawer* d, char* s) void write_chex32(struct Drawer* d, unsigned long val, unsigned int c) { + lock(&d->l); draw_chex32(d->x, d->y, val, c); d->x += 8; if (d->x >= GG_MAX_X) { d->y += 1; d->x %= GG_MAX_X; } + unlock(&d->l); } void write_hex32(struct Drawer* d, unsigned long val) @@ -87,6 +93,8 @@ void write_10(struct Drawer* d, unsigned long val) void set_drawer(struct Drawer* d, unsigned int x, unsigned int y) { + lock(&d->l); d->x = x % GG_MAX_X; d->y = y % GG_MAX_Y; + unlock(&d->l); } |