• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

SharedMem.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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" //For DSOEXPORT
00044 
00045 // Forward declarations
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     // Semaphore ID.
00129     int _semid;
00130 
00131     // Shared memory ID.
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 } // end of gnash namespace
00154 
00155 #endif
00156 
00157 // Local Variables:
00158 // mode: C++
00159 // indent-tabs-mode: t
00160 // End:

Generated on Fri Mar 16 2012 15:46:12 for Gnash by  doxygen 1.7.1