Skip to content

Commit 12579d9

Browse files
pcercueiQuzarDC
authored andcommitted
vmu: Use blocking frame locking where possible
In some places in the VMU code, genwait_wait() is used, which means that the calling function cannot run in interrupt context. Therefore, in those places we can wait for the maple frame to lock as it is safe to do so. This fixes KallistiOS#1225. Signed-off-by: Paul Cercueil <paul@crapouillou.net>
1 parent f90427e commit 12579d9

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

  • kernel/arch/dreamcast/hardware/maple

kernel/arch/dreamcast/hardware/maple/vmu.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ int vmu_block_read(maple_device_t *dev, uint16_t blocknum, uint8_t *buffer) {
437437
assert(dev != NULL);
438438

439439
/* Lock the frame */
440-
if(maple_frame_trylock(&dev->frame) < 0)
441-
return MAPLE_EAGAIN;
440+
maple_frame_lock(&dev->frame);
442441

443442
/* This is (block << 24) | (phase << 8) | (partition (0 for all vmu)) */
444443
blkid = ((blocknum & 0xff) << 24) | ((blocknum >> 8) << 16);
@@ -516,8 +515,7 @@ static int vmu_block_write_internal(maple_device_t *dev, uint16_t blocknum, cons
516515
rv = MAPLE_EOK;
517516

518517
/* Lock the frame. XXX: Priority inversion issues here. */
519-
while(maple_frame_trylock(&dev->frame) < 0)
520-
thd_pass();
518+
maple_frame_lock(&dev->frame);
521519

522520
/* Writes have to occur in four phases per block -- this is the
523521
way of flash memory, which you must erase an entire block
@@ -638,8 +636,7 @@ int vmu_set_datetime(maple_device_t *dev, time_t unix) {
638636
assert(btime); /* A failure here means an invalid unix timestamp was given. */
639637

640638
/* Lock the frame */
641-
if(maple_frame_trylock(&dev->frame) < 0)
642-
return MAPLE_EAGAIN;
639+
maple_frame_lock(&dev->frame);
643640

644641
/* Reset the frame */
645642
maple_frame_init(&dev->frame);
@@ -687,8 +684,7 @@ int vmu_get_datetime(maple_device_t *dev, time_t *unix) {
687684
return MAPLE_EINVALID;
688685

689686
/* Lock the frame */
690-
if(maple_frame_trylock(&dev->frame) < 0)
691-
return MAPLE_EAGAIN;
687+
maple_frame_lock(&dev->frame);
692688

693689
/* Reset the frame */
694690
maple_frame_init(&dev->frame);

0 commit comments

Comments
 (0)