Skip to content

Commit 7fd5ec4

Browse files
committed
util: drop POSIX/pthread dependencies to enable MSVC builds
Remove POSIX and pthread calls from util.cpp to avoid relying on MinGW's POSIX compatibility layer. This lets code be compiled with MSVC.
1 parent 4f58c8c commit 7fd5ec4

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/mp/util.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,27 @@
1212
#include <kj/common.h>
1313
#include <kj/debug.h>
1414
#include <kj/string-tree.h>
15-
#include <pthread.h>
1615
#include <sstream>
1716
#include <string>
1817
#include <system_error>
1918
#include <thread> // NOLINT(misc-include-cleaner) // IWYU pragma: keep
20-
#include <unistd.h>
2119
#include <utility>
2220
#include <vector>
2321

2422
#ifdef WIN32
2523
#include <atomic>
24+
#include <process.h>
2625
#include <windows.h>
2726
#include <winsock2.h>
2827
#else
2928
#include <fcntl.h>
29+
#include <pthread.h>
3030
#include <sys/resource.h>
3131
#include <sys/socket.h>
3232
#include <sys/types.h>
3333
#include <sys/wait.h>
34+
#include <unistd.h>
35+
#define _getpid getpid
3436
#endif
3537

3638
#ifdef __linux__
@@ -80,12 +82,12 @@ size_t MaxFd()
8082
std::string ThreadName(const char* exe_name)
8183
{
8284
char thread_name[16] = {0};
83-
#ifdef HAVE_PTHREAD_GETNAME_NP
85+
#if defined(HAVE_PTHREAD_GETNAME_NP) && !defined(WIN32)
8486
pthread_getname_np(pthread_self(), thread_name, sizeof(thread_name));
8587
#endif // HAVE_PTHREAD_GETNAME_NP
8688

8789
std::ostringstream buffer;
88-
buffer << (exe_name ? exe_name : "") << "-" << getpid() << "/";
90+
buffer << (exe_name ? exe_name : "") << "-" << _getpid() << "/";
8991

9092
if (thread_name[0] != '\0') {
9193
buffer << thread_name << "-";

0 commit comments

Comments
 (0)