mirror of
https://github.com/RPCSX/rpcsx.git
synced 2025-12-06 07:12:14 +01:00
rx: add process utility
This commit is contained in:
parent
715a7dfc5e
commit
e219bc4504
|
|
@ -8,6 +8,7 @@ add_library(${PROJECT_NAME} OBJECT
|
||||||
src/FileLock.cpp
|
src/FileLock.cpp
|
||||||
src/hexdump.cpp
|
src/hexdump.cpp
|
||||||
src/mem.cpp
|
src/mem.cpp
|
||||||
|
src/Process.cpp
|
||||||
src/SharedAtomic.cpp
|
src/SharedAtomic.cpp
|
||||||
src/SharedCV.cpp
|
src/SharedCV.cpp
|
||||||
src/SharedMutex.cpp
|
src/SharedMutex.cpp
|
||||||
|
|
@ -22,6 +23,10 @@ PRIVATE
|
||||||
include/${PROJECT_NAME}
|
include/${PROJECT_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||||
|
target_link_libraries(${PROJECT_NAME} PUBLIC synchronization kernel32 onecore)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
|
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
|
||||||
|
|
||||||
if (Git_FOUND)
|
if (Git_FOUND)
|
||||||
|
|
|
||||||
30
rx/include/rx/Process.hpp
Normal file
30
rx/include/rx/Process.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace rx {
|
||||||
|
using ProcessId = std::uint32_t;
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
using ThreadId = std::uint64_t;
|
||||||
|
#else
|
||||||
|
using ThreadId = ProcessId;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
using ProcessHandle = void *;
|
||||||
|
#else
|
||||||
|
using ProcessHandle = ProcessId;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(__APPLE__)
|
||||||
|
using ThreadHandle = void *;
|
||||||
|
#else
|
||||||
|
using ThreadHandle = ThreadId;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ProcessId getCurrentProcessId();
|
||||||
|
ThreadId getCurrentThreadId();
|
||||||
|
ProcessHandle getCurrentProcessHandle();
|
||||||
|
ThreadHandle getCurrentThreadHandle();
|
||||||
|
} // namespace rx
|
||||||
50
rx/src/Process.cpp
Normal file
50
rx/src/Process.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#include <rx/Process.hpp>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rx::ProcessId rx::getCurrentProcessId() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return ::GetCurrentProcessId();
|
||||||
|
#else
|
||||||
|
return ::getpid();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
rx::ThreadId rx::getCurrentThreadId() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return ::GetCurrentProcessId();
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
uint64_t tid = 0;
|
||||||
|
pthread_threadid_np(nullptr, &tid);
|
||||||
|
return tid;
|
||||||
|
#else
|
||||||
|
return ::gettid();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
rx::ProcessHandle rx::getCurrentProcessHandle() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return ::GetCurrentProcess();
|
||||||
|
#else
|
||||||
|
return getCurrentProcessId();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
rx::ThreadHandle rx::getCurrentThreadHandle() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
return ::GetCurrentThread();
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
return pthread_self();
|
||||||
|
#else
|
||||||
|
return getCurrentThreadId();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "debug.hpp"
|
#include "debug.hpp"
|
||||||
|
#include "Process.hpp"
|
||||||
#include "print.hpp"
|
#include "print.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
@ -73,7 +74,7 @@ void rx::waitForDebugger() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rx::println(stderr, "waiting for debugger, pid {}", ::getpid());
|
rx::println(stderr, "waiting for debugger, pid {}", getCurrentProcessId());
|
||||||
|
|
||||||
while (!isDebuggerPresent()) {
|
while (!isDebuggerPresent()) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue