[Mesa-dev,2/2] egl: use CLOCK_MONOTONIC only when available

Submitted by Mauro Rossi on May 31, 2016, midnight

Details

Message ID 1464652845-23744-3-git-send-email-issor.oruam@gmail.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Mauro Rossi May 31, 2016, midnight
Fixes the following building error:

external/mesa/src/egl/drivers/dri2/egl_dri2.c:2476: error: undefined reference to 'pthread_condattr_setclock'
collect2: error: ld returned 1 exit status

Cc: <mesa-stable@lists.freedesktop.org>
---
 src/egl/drivers/dri2/egl_dri2.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index f954cd5..9201f5b 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2421,7 +2421,9 @@  dri2_create_sync(_EGLDriver *drv, _EGLDisplay *dpy,
    struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
    struct dri2_egl_sync *dri2_sync;
    EGLint ret;
+#if defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined(HAVE_CLOCK_MONOTONIC)
    pthread_condattr_t attr;
+#endif
 
    dri2_sync = calloc(1, sizeof(struct dri2_egl_sync));
    if (!dri2_sync) {
@@ -2466,6 +2468,7 @@  dri2_create_sync(_EGLDriver *drv, _EGLDisplay *dpy,
       break;
 
    case EGL_SYNC_REUSABLE_KHR:
+#if defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined(HAVE_CLOCK_MONOTONIC)
       /* intialize attr */
       ret = pthread_condattr_init(&attr);
 
@@ -2491,6 +2494,15 @@  dri2_create_sync(_EGLDriver *drv, _EGLDisplay *dpy,
          free(dri2_sync);
          return NULL;
       }
+#else
+      ret = pthread_cond_init(&dri2_sync->cond, NULL);
+
+      if (ret) {
+         _eglError(EGL_BAD_ACCESS, "eglCreateSyncKHR");
+         free(dri2_sync);
+         return NULL;
+      }
+#endif
 
       /* initial status of reusable sync must be "unsignaled" */
       dri2_sync->base.SyncStatus = EGL_UNSIGNALED_KHR;
@@ -2594,7 +2606,11 @@  dri2_client_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync,
       } else {
          /* if reusable sync has not been yet signaled */
          if (dri2_sync->base.SyncStatus != EGL_SIGNALED_KHR) {
+#if defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined(HAVE_CLOCK_MONOTONIC)
             clock_gettime(CLOCK_MONOTONIC, &current);
+#else
+            clock_gettime(CLOCK_REALTIME, &current);
+#endif
 
             /* calculating when to expire */
             expire.nsec = timeout % 1000000000L;

Comments

On 31 May 2016 at 01:00, Mauro Rossi <issor.oruam@gmail.com> wrote:
> Fixes the following building error:
>
> external/mesa/src/egl/drivers/dri2/egl_dri2.c:2476: error: undefined reference to 'pthread_condattr_setclock'
> collect2: error: ld returned 1 exit status
>
> Cc: <mesa-stable@lists.freedesktop.org>
> ---
Afaict this doesn't seems right:
 - I cannot see anyone that defines the HAVE_PTHREAD_CONDATTR_SETCLOCK
and HAVE_CLOCK_MONOTONIC macros, Thus this change forces the new
codepath for everyone - android, scons, automake.
 - Various other places in mesa (that Android builds) already use
clock_gettime(CLOCK_MONOTONIC...) so that should not be an issue,
right ?
 - About the undefined pthread_condattr_setclock symbol... Is this an
issue with Android 4.4 only ? I would imagine that other programs use
the symbol, so one could port the functionality (from say Android 5.x)
 within Android itself ?

Regards,
Emil