]> git.alsa-project.org Git - alsa-lib.git/commitdiff
check availability of CLOCK_MONOTONIC
authorClemens Ladisch <clemens@ladisch.de>
Mon, 14 Jan 2008 07:51:45 +0000 (08:51 +0100)
committerClemens Ladisch <clemens@ladisch.de>
Mon, 14 Jan 2008 07:51:45 +0000 (08:51 +0100)
Use monotonic timestamps only after checking that CLOCK_MONOTONIC is
actually supported by the C library.

src/pcm/pcm_file.c
src/pcm/pcm_hw.c

index 89f8b75177150443a15b3ced0f46f1e0061123ac..4b8eaa5c6efb0b540a7cbf835aa8249adef8d98c 100644 (file)
@@ -412,7 +412,9 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
        snd_pcm_t *pcm;
        snd_pcm_file_t *file;
        snd_pcm_file_format_t format;
+       struct timespec timespec;
        int err;
+
        assert(pcmp);
        if (fmt == NULL ||
            strcmp(fmt, "raw") == 0)
@@ -467,7 +469,11 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
        pcm->poll_fd = slave->poll_fd;
        pcm->poll_events = slave->poll_events;
        pcm->mmap_shadow = 1;
-       pcm->monotonic = 1;
+#ifdef HAVE_CLOCK_GETTIME
+       pcm->monotonic = clock_gettime(CLOCK_MONOTONIC, &timespec) == 0;
+#else
+       pcm->monotonic = 0;
+#endif
        snd_pcm_link_hw_ptr(pcm, slave);
        snd_pcm_link_appl_ptr(pcm, slave);
        *pcmp = pcm;
index e5de76825fc6fa2fa446addd0f3dc4214a9bb1af..8495f71b49237de381b8b89081331ea74c22c5d9 100644 (file)
@@ -996,13 +996,16 @@ int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
 
 #ifdef HAVE_CLOCK_GETTIME
        if (SNDRV_PROTOCOL_VERSION(2, 0, 9) <= ver) {
-               int on = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
-               if (ioctl(fd, SNDRV_PCM_IOCTL_TTSTAMP, &on) < 0) {
-                       ret = -errno;
-                       SNDMSG("TTSTAMP failed\n");
-                       return ret;
+               struct timespec timespec;
+               if (clock_gettime(CLOCK_MONOTONIC, &timespec) == 0) {
+                       int on = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
+                       if (ioctl(fd, SNDRV_PCM_IOCTL_TTSTAMP, &on) < 0) {
+                               ret = -errno;
+                               SNDMSG("TTSTAMP failed\n");
+                               return ret;
+                       }
+                       monotonic = 1;
                }
-               monotonic = 1;
        }
 #endif
          else if (SNDRV_PROTOCOL_VERSION(2, 0, 5) <= ver) {