Page Speed Optimization Libraries
1.3.25.1
|
00001 /* 00002 * Copyright 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_LOCK_MANAGER_H_ 00020 #define NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_LOCK_MANAGER_H_ 00021 00022 #include <cstddef> 00023 00024 #include "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/named_lock_manager.h" 00026 #include "net/instaweb/util/public/scoped_ptr.h" 00027 #include "net/instaweb/util/public/string.h" 00028 #include "net/instaweb/util/public/string_util.h" 00029 00030 namespace net_instaweb { 00031 00032 class AbstractSharedMem; 00033 class AbstractSharedMemSegment; 00034 class Hasher; 00035 class MessageHandler; 00036 class Scheduler; 00037 00038 namespace SharedMemLockData { 00039 00040 struct Bucket; 00041 00042 } 00043 00048 class SharedMemLockManager : public NamedLockManager { 00049 public: 00054 SharedMemLockManager( 00055 AbstractSharedMem* shm, const GoogleString& path, Scheduler* scheduler, 00056 Hasher* hasher, MessageHandler* handler); 00057 virtual ~SharedMemLockManager(); 00058 00061 bool Initialize(); 00062 00065 bool Attach(); 00066 00072 static void GlobalCleanup(AbstractSharedMem* shm, const GoogleString& path, 00073 MessageHandler* message_handler); 00074 00075 virtual NamedLock* CreateNamedLock(const StringPiece& name); 00076 00077 private: 00078 friend class SharedMemLock; 00079 00080 SharedMemLockData::Bucket* Bucket(size_t bucket); 00081 00083 size_t MutexOffset(SharedMemLockData::Bucket*); 00084 00085 AbstractSharedMem* shm_runtime_; 00086 GoogleString path_; 00087 00088 scoped_ptr<AbstractSharedMemSegment> seg_; 00089 Scheduler* scheduler_; 00090 Hasher* hasher_; 00091 MessageHandler* handler_; 00092 size_t lock_size_; 00093 00094 DISALLOW_COPY_AND_ASSIGN(SharedMemLockManager); 00095 }; 00096 00097 } 00098 00099 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_LOCK_MANAGER_H_