"Fossies" - the Fresh Open Source Software Archive

Member "incubator-pagespeed-mod-1.14.36.1/pagespeed/kernel/base/abstract_shared_mem.h" (28 Feb 2020, 4945 Bytes) of package /linux/www/apache_httpd_modules/incubator-pagespeed-mod-1.14.36.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "abstract_shared_mem.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.13.35.2_vs_1.14.36.1.

    1 /*
    2  * Licensed to the Apache Software Foundation (ASF) under one
    3  * or more contributor license agreements.  See the NOTICE file
    4  * distributed with this work for additional information
    5  * regarding copyright ownership.  The ASF licenses this file
    6  * to you under the Apache License, Version 2.0 (the
    7  * "License"); you may not use this file except in compliance
    8  * with the License.  You may obtain a copy of the License at
    9  * 
   10  *   http://www.apache.org/licenses/LICENSE-2.0
   11  * 
   12  * Unless required by applicable law or agreed to in writing,
   13  * software distributed under the License is distributed on an
   14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15  * KIND, either express or implied.  See the License for the
   16  * specific language governing permissions and limitations
   17  * under the License.
   18  */
   19 
   20 
   21 #ifndef PAGESPEED_KERNEL_BASE_ABSTRACT_SHARED_MEM_H_
   22 #define PAGESPEED_KERNEL_BASE_ABSTRACT_SHARED_MEM_H_
   23 
   24 #include <cstddef>
   25 #include "pagespeed/kernel/base/basictypes.h"
   26 #include "pagespeed/kernel/base/string.h"
   27 
   28 namespace net_instaweb {
   29 
   30 class AbstractMutex;
   31 class MessageHandler;
   32 
   33 // This represents a region of memory shared between between multiple processes
   34 // that may contain mutexes.
   35 class AbstractSharedMemSegment {
   36  public:
   37   AbstractSharedMemSegment() {}
   38 
   39   // Destroying the segment object detaches from it, making all pointers into it
   40   // invalid.
   41   virtual ~AbstractSharedMemSegment();
   42 
   43   // Returns the base address of the segment. Note that there is no guarantee
   44   // that this address will be the same for other processes attached to the
   45   // same segment.
   46   virtual volatile char* Base() = 0;
   47 
   48   // Returns the number of bytes a mutex inside shared memory takes.
   49   virtual size_t SharedMutexSize() const = 0;
   50 
   51   // To use a mutex in shared memory, you first need to dedicate some
   52   // [offset, offset + SharedMutexSize()) chunk of memory to it. Then,
   53   // exactly one process must call InitializeSharedMutex(offset), and
   54   // all users must call AttachToSharedMutex(offset) afterwards.
   55   //
   56   // InitializeSharedMutex returns whether it succeeded or not.
   57   // AttachToSharedMutex returns a fresh object, giving ownership
   58   // to the caller. The object returned is outside shared memory,
   59   // and acts a helper for referring to the shared state.
   60   virtual bool InitializeSharedMutex(size_t offset,
   61                                      MessageHandler* handler) = 0;
   62   virtual AbstractMutex* AttachToSharedMutex(size_t offset) = 0;
   63 
   64  private:
   65   DISALLOW_COPY_AND_ASSIGN(AbstractSharedMemSegment);
   66 };
   67 
   68 // Interface for creating and attaching to named shared memory segments.
   69 // The expectation is that whichever implementation is used at runtime
   70 // will be able to handle the combination of threads & processes used by
   71 // the hosting environment.
   72 //
   73 // The basic flow here is as follows:
   74 //
   75 //            Single process/thread startup stage:
   76 //            CreateSegment
   77 //            InitializeSharedMutex -----+
   78 //           /                           |
   79 //          /                            |
   80 //    process/thread:                   process/thread:
   81 //    AttachToSegment                   AttachToSegment
   82 //    AttachToSharedMutex               AttachToSharedMutex
   83 //       |                                     |
   84 //       |                                     |
   85 //       |------------------------------------/
   86 //       |
   87 //    single process/thread cleanup stage:
   88 //    DestroySegment
   89 //
   90 class AbstractSharedMem {
   91  public:
   92   AbstractSharedMem() {}
   93   virtual ~AbstractSharedMem();
   94 
   95   // Size of mutexes inside shared memory segments.
   96   virtual size_t SharedMutexSize() const = 0;
   97 
   98   // This should be called upon main process/thread initialization to create
   99   // a shared memory segment that will be accessed by other processes/threads
  100   // as identified by a unique name (via AttachToSegment). It will remove
  101   // any previous segment with the same name. The memory will be zeroed out.
  102   //
  103   // May return NULL on failure.
  104   virtual AbstractSharedMemSegment* CreateSegment(
  105       const GoogleString& name, size_t size, MessageHandler* handler) = 0;
  106 
  107   // Attaches to an existing segment, which must have been created already.
  108   // May return NULL on failure
  109   virtual AbstractSharedMemSegment* AttachToSegment(
  110       const GoogleString& name, size_t size, MessageHandler* handler) = 0;
  111 
  112   // Cleans up the segment with given name. You should call this after there is
  113   // no longer any need for AttachToSegment to succeed.
  114   virtual void DestroySegment(const GoogleString& name,
  115                               MessageHandler* handler) = 0;
  116 
  117   // Implementors such as NullSharedMem that don't actually support shared
  118   // memory operations should return true.  All real implementations should
  119   // leave this as false.
  120   virtual bool IsDummy() { return false; }
  121 
  122  private:
  123   DISALLOW_COPY_AND_ASSIGN(AbstractSharedMem);
  124 };
  125 
  126 }  // namespace net_instaweb
  127 
  128 #endif  // PAGESPEED_KERNEL_BASE_ABSTRACT_SHARED_MEM_H_