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 #include "base/scoped_ptr.h" 00024 #include "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/named_lock_manager.h" 00026 #include "net/instaweb/util/public/string.h" 00027 #include "net/instaweb/util/public/string_util.h" 00028 00029 namespace net_instaweb { 00030 00031 class AbstractSharedMem; 00032 class AbstractSharedMemSegment; 00033 class Hasher; 00034 class MessageHandler; 00035 class Scheduler; 00036 00037 namespace SharedMemLockData { 00038 00039 struct Bucket; 00040 00041 } 00042 00047 class SharedMemLockManager : public NamedLockManager { 00048 public: 00053 SharedMemLockManager( 00054 AbstractSharedMem* shm, const GoogleString& path, Scheduler* scheduler, 00055 Hasher* hasher, MessageHandler* handler); 00056 virtual ~SharedMemLockManager(); 00057 00060 bool Initialize(); 00061 00064 bool Attach(); 00065 00071 static void GlobalCleanup(AbstractSharedMem* shm, const GoogleString& path, 00072 MessageHandler* message_handler); 00073 00074 virtual NamedLock* CreateNamedLock(const StringPiece& name); 00075 00076 private: 00077 friend class SharedMemLock; 00078 00079 SharedMemLockData::Bucket* Bucket(size_t bucket); 00080 00082 size_t MutexOffset(SharedMemLockData::Bucket*); 00083 00084 AbstractSharedMem* shm_runtime_; 00085 GoogleString path_; 00086 00087 scoped_ptr<AbstractSharedMemSegment> seg_; 00088 Scheduler* scheduler_; 00089 Hasher* hasher_; 00090 MessageHandler* handler_; 00091 size_t lock_size_; 00092 00093 DISALLOW_COPY_AND_ASSIGN(SharedMemLockManager); 00094 }; 00095 00096 } 00097 00098 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_LOCK_MANAGER_H_