On 02/21/2017 05:48 PM, Timothy Arceri wrote:


On 22/02/17 09:59, Brian Paul wrote:
On 02/21/2017 03:57 PM, Brian Paul wrote:
Windows doesn't have dlfcn.h.  Protect the code in question
with #if ENABLE_SHADER_CACHE test.
---
  src/util/disk_cache.h | 26 ++++++++++++++++----------
  1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index 8b6fc0d..7f4da80 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -24,7 +24,9 @@
  #ifndef DISK_CACHE_H
  #define DISK_CACHE_H

+#ifdef ENABLE_SHADER_CACHE
  #include <dlfcn.h>
+#endif
  #include <stdint.h>
  #include <stdbool.h>
  #include <sys/stat.h>
@@ -43,16 +45,20 @@ struct disk_cache;
  static inline bool
  disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
  {
-    Dl_info info;
-    struct stat st;
-    if (!dladdr(ptr, &info) || !info.dli_fname) {
-        return false;
-    }
-    if (stat(info.dli_fname, &st)) {
-        return false;
-    }
-    *timestamp = st.st_mtim.tv_sec;
-    return true;
+#ifdef ENABLE_SHADER_CACHE
+   Dl_info info;
+   struct stat st;
+   if (!dladdr(ptr, &info) || !info.dli_fname) {
+      return false;
+   }
+   if (stat(info.dli_fname, &st)) {
+      return false;
+   }
+   *timestamp = st.st_mtim.tv_sec;
+   return true;
+#else
+   return false;
+#endif
  }

  /* Provide inlined stub functions if the shader cache is disabled. */



Timothy,

Does this function really need to be inlined?  AFAICT, it's not called
on a performance critical path.  Moving it into the .c file would seem
to be cleaner.

No not really, feel free to move it. Either way this patch is:

Reviewed-by: Timothy Arceri <tarc...@itsqueeze.com>

Thanks.  I pushed this patch as-is.

I also tried moving the function to the .c file but I get a link error that dladdr() is undefined. It's a _GNU_SOURCE extension. It looks like _GNU_SOURCE is defined, but something else is wrong. My WIP is attached if you want to take a crack at it.

-Brian


diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 2f138da..7b6b460 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -24,6 +24,7 @@
 #ifdef ENABLE_SHADER_CACHE
 
 #include <ctype.h>
+#include <dlfcn.h>
 #include <ftw.h>
 #include <string.h>
 #include <stdlib.h>
@@ -37,6 +38,7 @@
 #include <pwd.h>
 #include <errno.h>
 #include <dirent.h>
+#include <sys/stat.h>
 
 #include "util/u_atomic.h"
 #include "util/mesa-sha1.h"
@@ -187,6 +189,21 @@ create_mesa_cache_dir(void *mem_ctx, char *path, const char *timestamp,
    return new_path;
 }
 
+bool
+disk_cache_get_function_timestamp(void *ptr, uint32_t *timestamp)
+{
+   Dl_info info;
+   struct stat st;
+   if (!dladdr(ptr, &info) || !info.dli_fname) {
+      return false;
+   }
+   if (stat(info.dli_fname, &st)) {
+      return false;
+   }
+   *timestamp = st.st_mtim.tv_sec;
+   return true;
+}
+
 struct disk_cache *
 disk_cache_create(const char *gpu_name, const char *timestamp)
 {
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index 7f4da80..9623f95 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -24,12 +24,8 @@
 #ifndef DISK_CACHE_H
 #define DISK_CACHE_H
 
-#ifdef ENABLE_SHADER_CACHE
-#include <dlfcn.h>
-#endif
 #include <stdint.h>
 #include <stdbool.h>
-#include <sys/stat.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -42,29 +38,13 @@ typedef uint8_t cache_key[CACHE_KEY_SIZE];
 
 struct disk_cache;
 
-static inline bool
-disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
-{
-#ifdef ENABLE_SHADER_CACHE
-   Dl_info info;
-   struct stat st;
-   if (!dladdr(ptr, &info) || !info.dli_fname) {
-      return false;
-   }
-   if (stat(info.dli_fname, &st)) {
-      return false;
-   }
-   *timestamp = st.st_mtim.tv_sec;
-   return true;
-#else
-   return false;
-#endif
-}
-
 /* Provide inlined stub functions if the shader cache is disabled. */
 
 #ifdef ENABLE_SHADER_CACHE
 
+bool
+disk_cache_get_function_timestamp(void *ptr, uint32_t *timestamp);
+
 /**
  * Create a new cache object.
  *
@@ -162,6 +142,12 @@ disk_cache_has_key(struct disk_cache *cache, cache_key key);
 
 #else
 
+static inline bool
+disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
+{
+   return false;
+}
+
 static inline struct disk_cache *
 disk_cache_create(const char *gpu_name, const char *timestamp)
 {
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to