-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #473 from uyjulian/eekernel_waitsema_timeout
Refactor WaitSema with a timeout into a separate function
- Loading branch information
Showing
8 changed files
with
124 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
# _____ ___ ____ ___ ____ | ||
# ____| | ____| | | |____| | ||
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. | ||
#----------------------------------------------------------------------- | ||
# Copyright ps2dev - http://www.ps2dev.org | ||
# Licenced under Academic Free License version 2.0 | ||
# Review ps2sdk README & LICENSE files for further details. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* Kernel utility functions | ||
*/ | ||
|
||
#ifndef __KERNEL_UTIL_H__ | ||
#define __KERNEL_UTIL_H__ | ||
|
||
#include <tamtypes.h> | ||
|
||
extern s32 WaitSemaEx(s32 semaid, int signal, u64 *timeout); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
# _____ ___ ____ ___ ____ | ||
# ____| | ____| | | |____| | ||
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. | ||
#----------------------------------------------------------------------- | ||
# Copyright ps2dev - http://www.ps2dev.org | ||
# Licenced under Academic Free License version 2.0 | ||
# Review ps2sdk README & LICENSE files for further details. | ||
*/ | ||
|
||
#include <kernel.h> | ||
#include <timer_alarm.h> | ||
#include <kernel_util.h> | ||
|
||
#ifdef F_WaitSemaEx | ||
static void WaitSemaEx_callback(struct timer_alarm_t *alarm, void *arg) | ||
{ | ||
iReleaseWaitThread((s32)arg); | ||
} | ||
|
||
/** Semaphore wait function similar to newer platforms */ | ||
s32 WaitSemaEx(s32 semaid, int signal, u64 *timeout) | ||
{ | ||
int ret; | ||
struct timer_alarm_t alarm; | ||
|
||
// TODO: other values NYI | ||
if (signal != 1) | ||
{ | ||
return -1; | ||
} | ||
|
||
if (timeout != NULL && *timeout == 0) | ||
{ | ||
ret = PollSema(semaid); | ||
if (ret < 0) | ||
{ | ||
return ret; | ||
} | ||
return semaid; | ||
} | ||
|
||
if (timeout != NULL) | ||
{ | ||
InitializeTimerAlarm(&alarm); | ||
SetTimerAlarm(&alarm, USec2TimerBusClock(*timeout), &WaitSemaEx_callback, (void *)GetThreadId()); | ||
} | ||
|
||
ret = WaitSema(semaid); | ||
|
||
if (timeout != NULL) | ||
{ | ||
StopTimerAlarm(&alarm); | ||
} | ||
|
||
if (ret < 0) | ||
{ | ||
return ret; | ||
} | ||
return semaid; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters