diff options
Diffstat (limited to 'compat/shm.h')
| -rw-r--r-- | compat/shm.h | 87 | 
1 files changed, 30 insertions, 57 deletions
| diff --git a/compat/shm.h b/compat/shm.h index 856b9c8c..814ce90c 100644 --- a/compat/shm.h +++ b/compat/shm.h @@ -1,68 +1,41 @@ -#ifndef SHM_HEADER_GUARD -#define SHM_HEADER_GUARD +/* Copyright (c) 2013 Stanislaw Halik <sthalik@misaki.pl> -#include "macros1.h" + * 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 -#ifndef SHM_WIN32_INIT -#   ifdef _WIN32 -#       define SHM_WIN32 -#   else -#       undef SHM_WIN32 -#   endif +#if defined(_WIN32) +#include <windows.h>  #else -#   if SHM_WIN32_INIT -#       define SHM_WIN32 -#   else -#       undef SHM_WIN32 -#   endif +#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>  #endif -#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 +#include "macros.hpp" +#include "export.hpp" -struct SHM_TYPE_NAME { +class OTR_COMPAT_EXPORT shm_wrapper final +{      void* mem; -#ifdef SHM_WIN32 -    void* mutex; -    void* mapped_file; +#if defined(_WIN32) +    HANDLE mutex, mapped_file;  #else      int fd, size;  #endif -}; - -#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) -#define SHM_FUN(r, f, ...) SHM_FUN_(r, f)(SHM_TYPE_NAME* self, __VA_ARGS__) -#define SHM_FUN0(r, f) SHM_FUN_(r, f)(SHM_TYPE_NAME* self) - -SHM_FUN(void, init, const char* shm_name, const char* mutex_name, int map_size); -SHM_FUN0(void, free); -SHM_FUN0(void, lock); -SHM_FUN0(void, unlock); -SHM_FUN0(void*,ptr); -SHM_FUN0(bool, success); -#ifndef BUILD_SHM -#   undef SHM_FUN -#   undef SHM_FUN_NAME -#endif - -#endif // SHM_HEADER_GUARD +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; } +}; | 
