shm_mem.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef __SHM_MEM_H__
  2. #define __SHM_MEM_H__
  3. #pragma once
  4. #include "config.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #include <stdarg.h>
  9. #define SHM_MEM_SIZE 16 /* MB */
  10. #ifndef INVALID_MAP
  11. #define INVALID_MAP ((void *)-1)
  12. #endif // !INVALID_MAP
  13. /* allocates the memory (mmap or sysv shmap) */
  14. TOOLKIT_API void* osips_shm_getmem(int, void*, unsigned long);
  15. /* deallocates the memory allocated by shm_getmem() */
  16. TOOLKIT_API void osips_shm_relmem(void*, unsigned long);
  17. TOOLKIT_API void osips_shm_mem_destroy();
  18. TOOLKIT_API int shm_getmem_addr(void** hint);
  19. TOOLKIT_API int shm_getmem(int key, void** hint, int);
  20. TOOLKIT_API void* shm_mem_init(void* hint, int newcreate);
  21. TOOLKIT_API int shm_mem_init2(int key, void *hint, int newcreate);
  22. TOOLKIT_API void shm_mem_destroy();
  23. TOOLKIT_API void shm_mem_destroy2(int newcreate);
  24. TOOLKIT_API char *shm_strdup(const char *str);
  25. TOOLKIT_API char *shm_strdup_printf(const char *format, ...);
  26. TOOLKIT_API char *shm_strdup_vprintf(const char *format, va_list args);
  27. TOOLKIT_API void shm_lock();
  28. TOOLKIT_API void shm_unlock();
  29. //
  30. TOOLKIT_API void shm_set_user_data(int idx, void *user_data);
  31. TOOLKIT_API void *shm_get_user_data(int idx);
  32. TOOLKIT_API void *shm_malloc_unsafe(unsigned int size);
  33. TOOLKIT_API void* shm_malloc(unsigned int size);
  34. TOOLKIT_API void shm_free_unsafe(void *_p);
  35. #define shm_free(_p) \
  36. do { \
  37. shm_lock(); \
  38. shm_free_unsafe( _p ); \
  39. shm_unlock(); \
  40. }while(0)
  41. #ifdef __cplusplus
  42. } // extern "C" {
  43. #endif
  44. #endif //__SHM_MEM_H__