-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coreinit: add stopwatch.h and stopwatchatomic.h #370
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,92 @@ | ||||||
#pragma once | ||||||
|
||||||
#include <wut.h> | ||||||
#include "spinlock.h" | ||||||
#include "time.h" | ||||||
|
||||||
/** | ||||||
* \defgroup coreinit_stopwatch Lock-based Stopwatch | ||||||
* \ingroup coreinit | ||||||
* | ||||||
* @{ | ||||||
*/ | ||||||
#ifdef __cplusplus | ||||||
extern "C" { | ||||||
#endif | ||||||
|
||||||
typedef struct OSStopwatch OSStopwatch; | ||||||
|
||||||
struct OSStopwatch { | ||||||
//! Lock | ||||||
OSSpinLock lock; | ||||||
//! Tag | ||||||
char* name; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
//! Number of times the stopwatch has been stopped | ||||||
uint32_t hitCount; | ||||||
//! Total time from first start to last stop | ||||||
OSTime totalTime; | ||||||
//! Minimum time between stops | ||||||
OSTime minTime; | ||||||
//! Maximum time between stops | ||||||
OSTime maxTime; | ||||||
//! Last time the watch was started | ||||||
OSTime startTime; | ||||||
//! Whether the stopwatch is running | ||||||
BOOL running; | ||||||
WUT_PADDING_BYTES(0x4); | ||||||
}; | ||||||
WUT_CHECK_OFFSET(OSStopwatch, 0x00, lock); | ||||||
WUT_CHECK_OFFSET(OSStopwatch, 0x10, name); | ||||||
WUT_CHECK_OFFSET(OSStopwatch, 0x14, hitCount); | ||||||
WUT_CHECK_OFFSET(OSStopwatch, 0x18, totalTime); | ||||||
WUT_CHECK_OFFSET(OSStopwatch, 0x20, minTime); | ||||||
WUT_CHECK_OFFSET(OSStopwatch, 0x28, maxTime); | ||||||
WUT_CHECK_OFFSET(OSStopwatch, 0x30, startTime); | ||||||
WUT_CHECK_OFFSET(OSStopwatch, 0x38, running); | ||||||
WUT_CHECK_SIZE(OSStopwatch, 0x40); | ||||||
|
||||||
/** | ||||||
* Initialises the stopwatch, | ||||||
* stopwatches must be initialized before any other stopwatch functions are used | ||||||
*/ | ||||||
void | ||||||
OSInitStopwatch(OSStopwatch *stopwatch, | ||||||
const char* name); | ||||||
|
||||||
/** | ||||||
* Resets all stopwatch data | ||||||
*/ | ||||||
void | ||||||
OSResetStopWatch(OSStopwatch *stopwatch); | ||||||
capitalistspz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
/** | ||||||
* Starts the stopwatch. | ||||||
* if already started, will update the start time without resetting the total time | ||||||
*/ | ||||||
void | ||||||
OSStartStopwatch(OSStopwatch *stopwatch); | ||||||
|
||||||
/** | ||||||
* Stops the stopwatch and increments hit count. | ||||||
* Nothing happens if the stopwatch has already been stopped | ||||||
*/ | ||||||
void | ||||||
OSStopStopwatch(OSStopwatch *stopwatch); | ||||||
|
||||||
/** | ||||||
* Returns the total time the stopwatch has been running | ||||||
*/ | ||||||
OSTime | ||||||
OSCheckStopwatch(OSStopwatch *stopwatch); | ||||||
|
||||||
/** | ||||||
* Dumps stopwatch info to the Cafe OS warn log | ||||||
*/ | ||||||
void | ||||||
OSDumpStopwatch(OSStopwatch *stopwatch); | ||||||
|
||||||
#ifdef __cplusplus | ||||||
} | ||||||
#endif | ||||||
|
||||||
/** @} */ |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||||||
#pragma once | ||||||||
|
||||||||
#include <wut.h> | ||||||||
#include "time.h" | ||||||||
|
||||||||
/** | ||||||||
* \defgroup coreinit_stopwatchatomic Atomic Stopwatch | ||||||||
* \ingroup coreinit | ||||||||
* | ||||||||
* @{ | ||||||||
*/ | ||||||||
#ifdef __cplusplus | ||||||||
extern "C" { | ||||||||
#endif | ||||||||
|
||||||||
typedef struct OSStopWatchAtomic OSStopWatchAtomic; | ||||||||
|
||||||||
struct OSStopWatchAtomic { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
//! Last time the watch was started | ||||||||
OSTime startTime; | ||||||||
//! Total time from first start to last stop | ||||||||
OSTime totalTime; | ||||||||
}; | ||||||||
WUT_CHECK_OFFSET(OSStopWatchAtomic, 0x00, startTime); | ||||||||
WUT_CHECK_OFFSET(OSStopWatchAtomic, 0x08, totalTime); | ||||||||
WUT_CHECK_SIZE(OSStopWatchAtomic, 0x10); | ||||||||
|
||||||||
/** | ||||||||
* Start the stopwatch. | ||||||||
* Only updates the start time | ||||||||
* \returns total time on stopwatch | ||||||||
*/ | ||||||||
OSTime | ||||||||
OSStopWatchStart(OSStopWatchAtomic *stopWatch); | ||||||||
|
||||||||
/** | ||||||||
* Stop the stopwatch. | ||||||||
* Resets the start time to 0 | ||||||||
* \returns total time on stopwatch | ||||||||
*/ | ||||||||
OSTime | ||||||||
OSStopWatchStop(OSStopWatchAtomic *stopWatch); | ||||||||
|
||||||||
/** | ||||||||
* Get the current time on the stopwatch | ||||||||
* \returns current time on stopwatch | ||||||||
*/ | ||||||||
OSTime OSStopWatchLap(OSStopWatchAtomic *stopWatch); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing newline after the return type. |
||||||||
|
||||||||
|
||||||||
/** | ||||||||
* Stops and resets the stop watch. | ||||||||
* Clears start and total time | ||||||||
* \returns previous total time | ||||||||
*/ | ||||||||
OSTime | ||||||||
OSStopWatchReset(OSStopWatchAtomic *stopWatch); | ||||||||
|
||||||||
#ifdef __cplusplus | ||||||||
} | ||||||||
#endif | ||||||||
|
||||||||
/** @} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.