diff --git a/CMakeLists.txt b/CMakeLists.txt index 360f4e86..df28a3bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,11 +29,14 @@ include_directories(${PROJECT_SOURCE_DIR} "${PROJECT_SOURCE_DIR}/dns") set_source_files_properties(dns/dns.c PROPERTIES COMPILE_FLAGS -std=c99) add_library(dill ${sources}) +find_package(Threads REQUIRED) +target_link_libraries(dill PUBLIC Threads::Threads) + # check and enable rt if available list(APPEND CMAKE_REQUIRED_LIBRARIES rt) check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME) if(HAVE_CLOCK_GETTIME) - target_link_libraries(dill rt) + target_link_libraries(dill PUBLIC rt) endif() # Installation (https://github.com/forexample/package-example) @@ -118,12 +121,12 @@ set(CMAKE_REQUIRED_DEFINITIONS ) check_function_exists(mprotect HAVE_MPROTECT) if(HAVE_MPROTECT) - add_definitions(-DHAVE_MPROTECT) + target_compile_definitions(dill PUBLIC HAVE_MPROTECT) endif() check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN) if(HAVE_POSIX_MEMALIGN) - add_definitions(-DHAVE_POSIX_MEMALIGN) + target_compile_definitions(dill PUBLIC HAVE_POSIX_MEMALIGN) endif() # tests diff --git a/perf/chan.c b/perf/chan.c index 2e0bca17..e9ed24e6 100644 --- a/perf/chan.c +++ b/perf/chan.c @@ -65,8 +65,10 @@ int main(int argc, char *argv[]) { printf("done %ldM roundtrips in %f seconds\n", (long)(count / 1000000), ((float)duration) / 1000); printf("duration of passing a single message: %ld ns\n", ns); - printf("message passes per second: %fM\n", - (float)(1000000000 / ns) / 1000000); + if (ns > 0) { + printf("message passes per second: %fM\n", + (float)(1000000000 / ns) / 1000000); + } return 0; } diff --git a/perf/choose.c b/perf/choose.c index 38940bfc..6900fe77 100644 --- a/perf/choose.c +++ b/perf/choose.c @@ -67,8 +67,10 @@ int main(int argc, char *argv[]) { printf("done %ldM roundtrips in %f seconds\n", (long)(count / 1000000), ((float)duration) / 1000); printf("duration of passing a single message: %ld ns\n", ns); - printf("message passes per second: %fM\n", + if (ns > 0) { + printf("message passes per second: %fM\n", (float)(1000000000 / ns) / 1000000); + } return 0; } diff --git a/perf/ctxswitch.c b/perf/ctxswitch.c index 9a2504d1..700f457a 100644 --- a/perf/ctxswitch.c +++ b/perf/ctxswitch.c @@ -57,8 +57,10 @@ int main(int argc, char *argv[]) { printf("performed %ldM context switches in %f seconds\n", (long)(count * 2 / 1000000), ((float)duration) / 1000); printf("duration of one context switch: %ld ns\n", ns); - printf("context switches per second: %fM\n", + if (ns > 0) { + printf("context switches per second: %fM\n", (float)(1000000000 / ns) / 1000000); + } return 0; } diff --git a/perf/go.c b/perf/go.c index f1c8f13e..a45b2d77 100644 --- a/perf/go.c +++ b/perf/go.c @@ -55,8 +55,10 @@ int main(int argc, char *argv[]) { printf("executed %ldM coroutines in %f seconds\n", (long)(count / 1000000), ((float)duration) / 1000); printf("duration of one coroutine creation+termination: %ld ns\n", ns); - printf("coroutine creations+terminations per second: %fM\n", - (float)(1000000000 / ns) / 1000000); + if (ns > 0) { + printf("coroutine creations+terminations per second: %fM\n", + (float)(1000000000 / ns) / 1000000); + } return 0; } diff --git a/perf/hdone.c b/perf/hdone.c index 1afe001a..414c79ae 100644 --- a/perf/hdone.c +++ b/perf/hdone.c @@ -65,8 +65,10 @@ int main(int argc, char *argv[]) { printf("done %ldM coroutine/channel cancellations in %f seconds\n", (long)(count / 1000000), ((float)duration) / 1000); printf("duration of coroutine/channel cancellation: %ld ns\n", ns); - printf("coroutine/channel cancellations per second: %fM\n", - (float)(1000000000 / ns) / 1000000); + if (ns > 0) { + printf("coroutine/channel cancellations per second: %fM\n", + (float)(1000000000 / ns) / 1000000); + } return 0; } diff --git a/perf/whispers.c b/perf/whispers.c index d1f3487e..e509ca07 100644 --- a/perf/whispers.c +++ b/perf/whispers.c @@ -68,8 +68,10 @@ int main(int argc, char *argv[]) { printf("took %f seconds\n", (float)duration / 1000); printf("performed %ld whispers in %f seconds\n", count, ((float)duration) / 1000); printf("duration of one whisper: %ld ns\n", ns); - printf("whispers per second: %fM\n", + if (ns > 0) { + printf("whispers per second: %fM\n", (float)(1000000000 / ns) / 1000000); + } return 0; }