Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GNASH_SHM_H
00020 #define GNASH_SHM_H
00021
00022 #ifdef HAVE_CONFIG_H
00023 # include "gnashconfig.h"
00024 #endif
00025
00026 #include <boost/cstdint.hpp>
00027
00028 #include <sys/types.h>
00029 #if !defined(HAVE_WINSOCK_H) && !defined(__riscos__) && !defined(__OS2__) && !defined(__HAIKU__)
00030 # include <sys/ipc.h>
00031 #ifdef _ANDROID
00032 # include <linux/shm.h>
00033 #else
00034 # include <sys/shm.h>
00035 #endif
00036 #elif !defined(__riscos__) && !defined(__OS2__) && !defined(__HAIKU__)
00037 # include <windows.h>
00038 # include <process.h>
00039 # include <fcntl.h>
00040 # include <io.h>
00041 #endif
00042
00043 #include "dsodefs.h"
00044
00045
00046 namespace gnash {
00047 class fn_call;
00048 }
00049
00050 namespace gnash {
00051
00052 #ifndef MAP_INHERIT
00053 const int MAP_INHERIT = 0;
00054 #endif
00055 #ifndef MAP_HASSEMAPHORE
00056 const int MAP_HASSEMAPHORE = 0;
00057 #endif
00058
00059 const int MAX_SHM_NAME_SIZE = 48;
00060
00061 class SharedMem
00062 {
00063 public:
00064
00065 typedef boost::uint8_t* iterator;
00066
00068
00071 iterator begin() const {
00072 return _addr;
00073 }
00074
00076
00078 iterator end() const {
00079 return _addr + _size;
00080 }
00081
00083
00087 DSOEXPORT SharedMem(size_t size);
00088
00090 DSOEXPORT ~SharedMem();
00091
00093
00096 DSOEXPORT bool attach();
00097
00099 class Lock
00100 {
00101 public:
00102 Lock(SharedMem& s) : _s(s), _locked(s.lock()) {}
00103 ~Lock() { if (_locked) _s.unlock(); }
00104 bool locked() const {
00105 return _locked;
00106 }
00107 private:
00108 SharedMem& _s;
00109 bool _locked;
00110 };
00111
00112 private:
00113
00115
00117 DSOEXPORT bool lock();
00118
00120
00122 DSOEXPORT bool unlock();
00123
00124 iterator _addr;
00125
00126 const size_t _size;
00127
00128
00129 int _semid;
00130
00131
00132 int _shmid;
00133
00134 #if !defined(HAVE_WINSOCK_H) || defined(__OS2__)
00135 key_t _shmkey;
00136 #else
00137 long _shmkey;
00138 HANDLE _shmhandle;
00139 #endif
00140 };
00141
00143
00148 inline bool
00149 attached(const SharedMem& mem) {
00150 return (mem.begin());
00151 }
00152
00153 }
00154
00155 #endif
00156
00157
00158
00159
00160