shared_memory.h

Go to the documentation of this file.
00001 #ifndef SHARED_MEMORY_CLASS
00002 #define SHARED_MEMORY_CLASS
00003 
00004 #ifndef EMBEDDED_BUILD
00005 
00006 /*****************************************************************************\
00007 *                                                                             *
00008 *  Name   : shared_memory                                                     *
00009 *  Author : Chris Koeritz                                                     *
00010 *                                                                             *
00011 *******************************************************************************
00012 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
00013 * redistribute it and/or modify it under the terms of the GNU General Public  *
00014 * License as published by the Free Software Foundation; either version 2 of   *
00015 * the License or (at your option) any later version.  This is online at:      *
00016 *     http://www.fsf.org/copyleft/gpl.html                                    *
00017 * Please send any updates to: fred@gruntose.com                               *
00018 \*****************************************************************************/
00019 
00020 #include <basis/object_base.h>
00021 
00022 // forward.
00023 class byte_filer;
00024 class rendezvous;
00025 
00027 
00032 class OPSYSTEM_CLASS_STYLE shared_memory : public virtual object_base
00033 {
00034 public:
00035   shared_memory(int size, const char *identity);
00037 
00043   virtual ~shared_memory();
00045 
00048   IMPLEMENT_CLASS_NAME("shared_memory");
00049 
00050   bool valid() const { return _valid; }
00052 
00054   int size() const { return _size; }
00056 
00057   const istring &identity() const;
00059 
00060   bool first_usage(byte *locked_memory, int max_compare);
00062 
00068   byte *lock();
00070 
00074   void unlock(byte * &to_unlock);
00076 
00078   static istring unique_shared_mem_identifier(int sequencer);
00080 
00085 private:
00086   rendezvous *_locking;  
00087 #ifdef __UNIX__
00088   int _the_memory;  
00089 #elif defined(__WIN32__)
00090   void *_the_memory;  
00091 #endif
00092   bool _valid;  
00093   istring *_identity;  
00094   int _size;  
00095 
00096   // these do the actual work of getting the memory.
00097   byte *locked_grab_memory();
00098   void locked_release_memory(byte * &to_unlock);
00099 
00100   static istring special_filename(const istring &identity);
00102 
00103   // forbidden.
00104   shared_memory(const shared_memory &);
00105   shared_memory &operator =(const shared_memory &);
00106 };
00107 
00108 #endif // embedded.
00109 
00110 #endif  // outer guard.
00111 

Generated on Fri Nov 21 04:29:55 2008 for HOOPLE Libraries by  doxygen 1.5.1