shmem.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. // platform-independent interface to shared memory
  18. #ifndef BOINC_SHMEM_H
  19. #define BOINC_SHMEM_H
  20. #ifndef _WIN32
  21. #include <sys/types.h>
  22. #ifndef ANDROID
  23. #include <sys/shm.h>
  24. #endif
  25. #endif
  26. // create_shmem(): create a shared-memory segment of the given size.
  27. // attach_shmem(): attach to a shared-memory segment
  28. // detach_shmem(): detach from a shared-mem segment.
  29. // Once all processes have detached, the segment is destroyed
  30. // The above with _mmap: V6 mmap() shared memory for Unix/Linux/Mac
  31. #ifdef _WIN32
  32. HANDLE create_shmem(
  33. LPCTSTR seg_name, int size, void** pp, bool try_global=true
  34. );
  35. HANDLE attach_shmem(LPCTSTR seg_name, void** pp);
  36. int detach_shmem(HANDLE hSharedMem, void* p);
  37. #else
  38. #ifndef __EMX__
  39. #define MMAPPED_FILE_NAME "boinc_mmap_file"
  40. extern int create_shmem_mmap(const char *path, size_t size, void** pp);
  41. extern int attach_shmem_mmap(const char *path, void** pp);
  42. extern int detach_shmem_mmap(void* p, size_t size);
  43. #endif
  44. extern int create_shmem(key_t, int size, gid_t gid, void**);
  45. extern int attach_shmem(key_t, void**);
  46. extern int detach_shmem(void*);
  47. extern int shmem_info(key_t key);
  48. // Destroy a shared-memory segment.
  49. // If there are attachments to it,
  50. // print a message in a loop until the attachments are gone
  51. //
  52. extern int destroy_shmem(key_t);
  53. #endif // !defined(_WIN32)
  54. #endif // BOINC_SHMEM_H