harden macros

This commit is contained in:
Lephenixnoir 2022-08-16 09:07:12 +02:00
parent 6d82009532
commit 5b669e5529
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

@ -58,7 +58,7 @@ extern uint32_t volatile *prof_tcnt;
function was already executing then the deepest instance in the stack is function was already executing then the deepest instance in the stack is
used instead of creating a new counter. */ used instead of creating a new counter. */
#define prof_enter(prof) { \ #define prof_enter(prof) { \
if(!prof.rec++) prof.elapsed += *prof_tcnt; \ if(!(prof).rec++) (prof).elapsed += *prof_tcnt; \
} }
/* prof_leave(): Stop counting time for a function /* prof_leave(): Stop counting time for a function
@ -67,15 +67,15 @@ extern uint32_t volatile *prof_tcnt;
are not as exactly as many prof_leave()'s as prof_enter()'s then the are not as exactly as many prof_leave()'s as prof_enter()'s then the
resulting time measure will not be relevant at all. */ resulting time measure will not be relevant at all. */
#define prof_leave(prof) { \ #define prof_leave(prof) { \
if(!--prof.rec) prof.elapsed -= *prof_tcnt; \ if(!--(prof).rec) (prof).elapsed -= *prof_tcnt; \
} }
/* Variant of prof_enter()/prof_leave() for non-recursive contexts */ /* Variant of prof_enter()/prof_leave() for non-recursive contexts */
#define prof_enter_norec(prof) { \ #define prof_enter_norec(prof) { \
prof.elapsed += *prof_tcnt; \ (prof).elapsed += *prof_tcnt; \
} }
#define prof_leave_norec(prof) { \ #define prof_leave_norec(prof) { \
prof.elapsed -= *prof_tcnt; \ (prof).elapsed -= *prof_tcnt; \
} }
/* prof_exec(): Measure a single block of code /* prof_exec(): Measure a single block of code
@ -87,11 +87,11 @@ extern uint32_t volatile *prof_tcnt;
exec_code(); exec_code();
}); */ }); */
#define prof_exec(code) ({ \ #define prof_exec(code) ({ \
prof_t prof = prof_make(); \ prof_t _prof = prof_make(); \
prof_enter(prof); \ prof_enter(_prof); \
code; \ code; \
prof_leave(prof); \ prof_leave(_prof); \
prof_time(prof); \ prof_time(_prof); \
}) })
//--- //---