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 
18 // platform-independent interface to shared memory
19 
20 #ifndef BOINC_SHMEM_H
21 #define BOINC_SHMEM_H
22 
23 #ifndef _WIN32
24 #include <sys/types.h>
25 #ifndef ANDROID
26 #include <sys/shm.h>
27 #endif
28 #endif
29 
30 // create_shmem(): create a shared-memory segment of the given size.
31 // attach_shmem(): attach to a shared-memory segment
32 // detach_shmem(): detach from a shared-mem segment.
33 //    Once all processes have detached, the segment is destroyed
34 // The above with _mmap: V6 mmap() shared memory for Unix/Linux/Mac
35 
36 #ifdef _WIN32
37 HANDLE create_shmem(
38     LPCTSTR seg_name, int size, void** pp, bool try_global=true
39 );
40 HANDLE attach_shmem(LPCTSTR seg_name, void** pp);
41 int detach_shmem(HANDLE hSharedMem, void* p);
42 #else
43 #ifndef __EMX__
44 #define MMAPPED_FILE_NAME    "boinc_mmap_file"
45 extern int create_shmem_mmap(const char *path, size_t size, void** pp);
46 extern int attach_shmem_mmap(const char *path, void** pp);
47 extern int detach_shmem_mmap(void* p, size_t size);
48 #endif
49 extern int create_shmem(key_t, int size, gid_t gid, void**);
50 extern int attach_shmem(key_t, void**);
51 extern int detach_shmem(void*);
52 extern int shmem_info(key_t key);
53 // Destroy a shared-memory segment.
54 // If there are attachments to it,
55 // print a message in a loop until the attachments are gone
56 //
57 extern int destroy_shmem(key_t);
58 #endif      // !defined(_WIN32)
59 
60 #endif      // BOINC_SHMEM_H
61