23 #include "precompiled.h"
61 static HANDLE prof_target_thread;
67 static const int PROFILE_INTERVAL_MS = 1;
70 static uintptr_t get_target_pc()
73 HANDLE hThread = prof_target_thread;
75 ret = SuspendThread(hThread);
96 context.ContextFlags = CONTEXT_CONTROL;
97 if(GetThreadContext(hThread, &context))
102 ret = ResumeThread(hThread);
111 static sem_t exit_flag;
113 static void* prof_thread_func(
void*
UNUSED(data))
117 const long _1e6 = 1000000;
118 const long _1e9 = 1000000000;
125 abs_timeout.tv_nsec += PROFILE_INTERVAL_MS *
_1e6;
127 if(abs_timeout.tv_nsec >= _1e9)
129 abs_timeout.tv_nsec -=
_1e9;
130 abs_timeout.tv_sec++;
141 uintptr_t pc = get_target_pc();
159 const DWORD access = THREAD_GET_CONTEXT|THREAD_SUSPEND_RESUME;
160 HANDLE hThread = OpenThread(access, FALSE, GetCurrentThreadId());
161 if(hThread == INVALID_HANDLE_VALUE)
164 prof_target_thread = hThread;
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
int clock_gettime(clockid_t clock, struct timespec *ts)
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
LIB_API void debug_SetThreadName(const char *name)
inform the debugger of the current thread's name.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
int pthread_create(pthread_t *thread_id, const void *attr, void *(*func)(void *), void *arg)
int sem_init(sem_t *sem, int pshared, unsigned value)
i64 Status
Error handling system.
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
#define WARN_IF_FALSE(expression)
#define WARN_RETURN(status)