Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_EXAMPLES "Build example executables" ON)
option(ASAN "Use AddressSanitizer for debug builds to detect memory issues" OFF)


include(CheckIncludeFile)
check_include_file(pthread.h HAVE_PTHREAD)
if(HAVE_PTHREAD)
add_definitions(-DHAVE_PTHREAD)
message(STATUS "pthread.h found, using POSIX thread support")
endif()
Comment on lines +13 to +17

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not use FindThreads and evaluate Threads_FOUND here?

# gettimeofday
check_include_file(sys/time.h HAVE_SYS_TIME_H)
if(HAVE_SYS_TIME_H)
add_definitions(-DHAVE_SYS_TIME_H)
message(STATUS "sys/time.h found, using gettimeofday()")
else()
message(WARNING "sys/time.h not found, gettimeofday() will not be available")
endif()



if (ASAN)
set(ASAN_FLAGS "\
-fsanitize=address \
Expand Down
11 changes: 9 additions & 2 deletions common/pthreads_cross.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ SOFTWARE.

#include "common/pthreads_cross.h"

#ifdef _WIN32


#if defined(_WIN32) && !defined(HAVE_PTHREAD)

typedef struct {
SRWLOCK lock;
Expand Down Expand Up @@ -238,14 +240,19 @@ unsigned int timespec_to_ms(const struct timespec *abstime)
return ((abstime->tv_sec - time(NULL)) * 1000) + (abstime->tv_nsec / 1000000);
}

#endif


#if defined(_WIN32)
#include <windows.h>

unsigned int pcthread_get_num_procs()
{
SYSTEM_INFO sysinfo;

GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
}

#else

#include <unistd.h>
Expand Down
4 changes: 2 additions & 2 deletions common/pthreads_cross.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SOFTWARE.
#ifndef __CPTHREAD_H__
#define __CPTHREAD_H__

#ifdef _WIN32
#if defined(_WIN32) && !defined(HAVE_PTHREAD)
#include <stdbool.h>
#include <windows.h>
#else
Expand All @@ -32,7 +32,7 @@ SOFTWARE.
#endif
#include <time.h>

#ifdef _WIN32
#if defined(_WIN32) && !defined(HAVE_PTHREAD)

typedef CRITICAL_SECTION pthread_mutex_t;
typedef void pthread_mutexattr_t;
Expand Down
8 changes: 7 additions & 1 deletion common/time_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ either expressed or implied, of the Regents of The University of Michigan.
#include <stdint.h>
#include <time.h>

#ifdef _WIN32
#if defined(_WIN32)
#if !defined(HAVE_SYS_TIME_H)
#include <Winsock2.h>
#endif

#include <windows.h>
#define sleep(x) Sleep((x)*1000)
typedef long long suseconds_t;
#endif
Comment on lines 34 to 42

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related to pthread? Maybe place this in a separate commit if it is an unrelated change.



Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required.

#ifdef _MSC_VER

inline int gettimeofday(struct timeval* tp, void* tzp)
Expand Down
Loading