eina: attempt to make the code more portable

This fixes the build on macOS.
This commit is contained in:
Jean Guyomarc'h 2017-06-05 19:00:22 +02:00
parent 50a103ee9d
commit cc4c40769d
3 changed files with 23 additions and 1 deletions

View File

@ -683,6 +683,8 @@ geteuid \
getuid \ getuid \
pause \ pause \
gmtime_r \ gmtime_r \
pthread_getcpuclockid \
clock_gettime \
]) ])
AC_FUNC_ALLOCA AC_FUNC_ALLOCA

View File

@ -153,15 +153,35 @@ _signal_handler(int sig EINA_UNUSED,
eina_semaphore_release(&_wait_for_bts_sem, 1); eina_semaphore_release(&_wait_for_bts_sem, 1);
return; return;
found: found:
/*
* Below is very non-portable code!
*
* - clock_gettime() is not implemented on macOS < 10.12
* - sched_getcpu() is not implemented on macOS
* - pthread_getcpuclockid() is not implemented on macOS
* - CLOCK_THREAD_CPUTIME_ID should be identical to pthread_getcpuclockid(),
* but it requires POSIX thingies to be defined.
*/
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_SCHED_GETCPU)
// store thread info like what cpu core we are on now (not reliable // store thread info like what cpu core we are on now (not reliable
// but hey - better than nothing), the amount of cpu time total // but hey - better than nothing), the amount of cpu time total
// we have consumed (it's cumulative so subtracing deltas can give // we have consumed (it's cumulative so subtracing deltas can give
// you an average amount of cpu time consumed between now and the // you an average amount of cpu time consumed between now and the
// previous time we looked) and also a full backtrace // previous time we looked) and also a full backtrace
_bt_cpu[slot] = sched_getcpu(); _bt_cpu[slot] = sched_getcpu();
# ifdef HAVE_PTHREAD_GETCPUCLOCKID
/* Try pthread_getcpuclockid() first */
pthread_getcpuclockid(self, &cid); pthread_getcpuclockid(self, &cid);
# elif defined(_POSIX_THREAD_CPUTIME)
/* Fallback to POSIX clock id. */
cid = CLOCK_THREAD_CPUTIME_ID;
# else
/* Boom, we lost */
# error Cannot determine the clock id for clock_gettime()
# endif
clock_gettime(cid, &(_bt_ts[slot])); clock_gettime(cid, &(_bt_ts[slot]));
_bt_buf_len[slot] = _eina_debug_unwind_bt(_bt_buf[slot], EINA_MAX_BT); _bt_buf_len[slot] = _eina_debug_unwind_bt(_bt_buf[slot], EINA_MAX_BT);
#endif /* HAVE_CLOCK_GETTIME && HAVE_SCHED_GETCPU */
// now wake up the monitor to let them know we are done collecting our // now wake up the monitor to let them know we are done collecting our
// backtrace info // backtrace info
eina_semaphore_release(&_wait_for_bts_sem, 1); eina_semaphore_release(&_wait_for_bts_sem, 1);

View File

@ -84,7 +84,7 @@ end:
static void * static void *
_monitor(void *_data EINA_UNUSED) _monitor(void *_data EINA_UNUSED)
{ {
#ifndef _WIN32 #ifdef HAVE_SYS_EPOLL_H
#define MAX_EVENTS 4 #define MAX_EVENTS 4
struct epoll_event event; struct epoll_event event;
struct epoll_event events[MAX_EVENTS]; struct epoll_event events[MAX_EVENTS];