shm_mem.h 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. TOOLKIT_API int shm_getmem(int key, void** hint);
  11. TOOLKIT_API int shm_mem_init2(int key, void *hint, int newcreate);
  12. TOOLKIT_API void shm_mem_destroy();
  13. TOOLKIT_API char *shm_strdup(const char *str);
  14. TOOLKIT_API char *shm_strdup_printf(const char *format, ...);
  15. TOOLKIT_API char *shm_strdup_vprintf(const char *format, va_list args);
  16. TOOLKIT_API void shm_lock();
  17. TOOLKIT_API void shm_unlock();
  18. //
  19. TOOLKIT_API void shm_set_user_data(int idx, void *user_data);
  20. TOOLKIT_API void *shm_get_user_data(int idx);
  21. TOOLKIT_API void *shm_malloc_unsafe(unsigned int size);
  22. TOOLKIT_API void* shm_malloc(unsigned int size);
  23. TOOLKIT_API void shm_free_unsafe(void *_p);
  24. #define shm_free(_p) \
  25. do { \
  26. shm_lock(); \
  27. shm_free_unsafe( _p ); \
  28. shm_unlock(); \
  29. }while(0)
  30. #ifdef __cplusplus
  31. } // extern "C" {
  32. #endif
  33. #endif //__SHM_MEM_H__