From 6fe4baf1de938a7d70cef801194a62df4b154b05 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 1 Mar 2018 14:26:54 +0530 Subject: [PATCH] Move pthread includes into separate header --- kitty/child-monitor.c | 22 +--------------------- kitty/threading.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 kitty/threading.h diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 6c6cc69c2..8df832f78 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -5,16 +5,7 @@ * Distributed under terms of the GPL3 license. */ -#ifdef __APPLE__ -#include -// I cant figure out how to get pthread.h to include this definition on macOS. MACOSX_DEPLOYMENT_TARGET does not work. -extern int pthread_setname_np(const char *name); -#else -// Need _GNU_SOURCE for pthread_setname_np on linux -#define _GNU_SOURCE -#include -#undef _GNU_SOURCE -#endif +#include "threading.h" #include "state.h" #include "screen.h" #include @@ -78,17 +69,6 @@ static uint8_t drain_buf[1024]; static int signal_fds[2], wakeup_fds[2]; -static inline void -set_thread_name(const char *name) { - int ret = 0; -#ifdef __APPLE__ - ret = pthread_setname_np(name); -#else - ret = pthread_setname_np(pthread_self(), name); -#endif - if (ret != 0) perror("Failed to set thread name"); -} - // Main thread functions {{{ diff --git a/kitty/threading.h b/kitty/threading.h new file mode 100644 index 000000000..3d6d8894d --- /dev/null +++ b/kitty/threading.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2018 Kovid Goyal + * + * Distributed under terms of the GPL3 license. + */ + +#pragma once + +#ifdef __APPLE__ +#include +// I cant figure out how to get pthread.h to include this definition on macOS. MACOSX_DEPLOYMENT_TARGET does not work. +extern int pthread_setname_np(const char *name); +#else +// Need _GNU_SOURCE for pthread_setname_np on linux +#define _GNU_SOURCE +#include +#undef _GNU_SOURCE +#endif +#include + +static inline void +set_thread_name(const char *name) { + int ret = 0; +#ifdef __APPLE__ + ret = pthread_setname_np(name); +#else + ret = pthread_setname_np(pthread_self(), name); +#endif + if (ret != 0) perror("Failed to set thread name"); +}