util/radv: move *_get_function_timestamp() to utils
authorTimothy Arceri <tarceri@itsqueeze.com>
Fri, 10 Feb 2017 02:02:22 +0000 (13:02 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Tue, 21 Feb 2017 21:40:00 +0000 (08:40 +1100)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/amd/vulkan/radv_device.c
src/util/disk_cache.h

index 783ab12760fc5a1b0f4ec62f8deae19892577636..7b8132989c51c109ca9909b8717b201767fec515 100644 (file)
  * IN THE SOFTWARE.
  */
 
-#include <dlfcn.h>
 #include <stdbool.h>
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/stat.h>
 #include "radv_private.h"
 #include "radv_cs.h"
+#include "util/disk_cache.h"
 #include "util/strtod.h"
 
 #include <xf86drm.h>
 #include "sid.h"
 #include "util/debug.h"
 
-static int
-radv_get_function_timestamp(void *ptr, uint32_t* timestamp)
-{
-       Dl_info info;
-       struct stat st;
-       if (!dladdr(ptr, &info) || !info.dli_fname) {
-               return -1;
-       }
-       if (stat(info.dli_fname, &st)) {
-               return -1;
-       }
-       *timestamp = st.st_mtim.tv_sec;
-       return 0;
-}
-
 static int
 radv_device_get_cache_uuid(enum radeon_family family, void *uuid)
 {
        uint32_t mesa_timestamp, llvm_timestamp;
        uint16_t f = family;
        memset(uuid, 0, VK_UUID_SIZE);
-       if (radv_get_function_timestamp(radv_device_get_cache_uuid, &mesa_timestamp) ||
-           radv_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo, &llvm_timestamp))
+       if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid, &mesa_timestamp) ||
+           !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo, &llvm_timestamp))
                return -1;
 
        memcpy(uuid, &mesa_timestamp, 4);
index 7c15aa180de7aa1e02cbde1b0875e239489f5e0b..8b6fc0ddcbf0b5d29c6aee584c64bf3c3b33d193 100644 (file)
 #ifndef DISK_CACHE_H
 #define DISK_CACHE_H
 
+#include <dlfcn.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <sys/stat.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,6 +40,21 @@ typedef uint8_t cache_key[CACHE_KEY_SIZE];
 
 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;
+}
+
 /* Provide inlined stub functions if the shader cache is disabled. */
 
 #ifdef ENABLE_SHADER_CACHE