2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 Free Software Foundation, Inc
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program 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. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 # include "gnashconfig.h"
26 #include <boost/cstdint.hpp>
33 #include <sys/types.h>
36 #include "dsodefs.h" //For DSOEXPORT
38 // Forward declarations
49 typedef boost::uint8_t* iterator
;
51 /// The beginning of the SharedMem section.
53 /// This is only valid after attach() has returned true. You can check
54 /// with the function attached().
55 iterator
begin() const {
59 /// The end of the SharedMem section.
61 /// This is only valid after attach() has returned true.
62 iterator
end() const {
66 /// Construct a SharedMem with the requested size.
68 /// @param size The size of the shared memory section. If successfully
69 /// created, the segment will be exactly this size and
71 DSOEXPORT
SharedMem(size_t size
);
74 DSOEXPORT
~SharedMem();
76 /// Initialize the shared memory segment
78 /// This is called by LocalConnection when either connect() or send()
80 DSOEXPORT
bool attach();
82 /// Use to get a scoped semaphore lock on the shared memory.
86 Lock(const SharedMem
& s
) : _s(s
), _locked(s
.lock()) {}
87 ~Lock() { if (_locked
) _s
.unlock(); }
98 /// Get a semaphore lock if possible
100 /// @return true if successful, false if not.
101 DSOEXPORT
bool lock() const;
103 /// Release a semaphore lock if possible
105 /// @return true if successful, false if not.
106 DSOEXPORT
bool unlock() const;
126 /// Check if the SharedMem has been attached.
128 /// This only checks whether the attach operation was successful, not whether
129 /// the shared memory still exists and is still attached where it was
130 /// initially. It is always possible for other processes to remove it while
131 /// Gnash is using it, but there is nothing we can do about this.
133 attached(const SharedMem
& mem
) {
134 return (mem
.begin());
137 } // end of gnash namespace
143 // indent-tabs-mode: t