summaryrefslogtreecommitdiffhomepage
path: root/compat/shm.h
diff options
context:
space:
mode:
Diffstat (limited to 'compat/shm.h')
-rw-r--r--compat/shm.h85
1 files changed, 55 insertions, 30 deletions
diff --git a/compat/shm.h b/compat/shm.h
index 814ce90c..7cd7693d 100644
--- a/compat/shm.h
+++ b/compat/shm.h
@@ -1,41 +1,66 @@
-/* Copyright (c) 2013 Stanislaw Halik <sthalik@misaki.pl>
+#ifndef SHM_HEADER_GUARD
+#define SHM_HEADER_GUARD
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- */
-#pragma once
+#include "macros1.h"
-#if defined(_WIN32)
-#include <windows.h>
+#ifndef SHM_WIN32_INIT
+# ifdef _WIN32
+# define SHM_WIN32
+# else
+# undef SHM_WIN32
+# endif
#else
-#include <stdio.h>
-#include <string.h>
-#include <sys/file.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <unistd.h>
-#include <sys/types.h>
+# if SHM_WIN32_INIT
+# define SHM_WIN32
+# else
+# undef SHM_WIN32
+# endif
#endif
-#include "macros.hpp"
-#include "export.hpp"
+#ifndef SHM_TYPE_NAME
+# define SHM_TYPE_NAME shm_mem_impl
+#endif
+
+#ifndef SHM_FUN_PREFIX
+# define SHM_FUN_PREFIX shm_mem_impl_
+#endif
+
+#ifndef SHM_EXPORT
+# define SHM_EXPORT
+#endif
+
+#ifndef __cplusplus
+# define SHM_EXTERN
+# include <stdbool.h>
+struct SHM_TYPE_NAME;
+typedef struct SHM_TYPE_NAME SHM_TYPE_NAME;
+#else
+# define SHM_EXTERN extern "C"
+#endif
-class OTR_COMPAT_EXPORT shm_wrapper final
-{
+struct SHM_TYPE_NAME {
void* mem;
-#if defined(_WIN32)
- HANDLE mutex, mapped_file;
+#ifdef SHM_WIN32
+ void* mutex;
+ void* mapped_file;
#else
int fd, size;
#endif
-
-public:
- cc_noinline shm_wrapper(const char *shm_name, const char *mutex_name, int map_size);
- cc_noinline ~shm_wrapper();
- cc_noinline bool lock();
- cc_noinline bool unlock();
- cc_noinline bool success();
- inline void* ptr() { return mem; }
};
+
+#define SHM_FUN_NAME(f) PP_CAT(SHM_FUN_PREFIX, f)
+#define SHM_FUN(r, f, ...) SHM_EXTERN SHM_EXPORT r SHM_FUN_NAME(f)(SHM_TYPE_NAME* __restrict self, __VA_ARGS__)
+
+SHM_FUN(void, init, const char* shm_name, const char* mutex_name, int map_size);
+SHM_FUN(void, free);
+SHM_FUN(void, lock);
+SHM_FUN(void, unlock);
+SHM_FUN(void*,ptr);
+SHM_FUN(bool, success);
+
+#ifndef BUILD_SHM
+# undef SHM_FUN
+# undef SHM_FUN_NAME
+#endif
+
+#endif // SHM_HEADER_GUARD