~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/pagespeed/kernel/sharedmem/shared_mem_lock_manager.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2011 Google Inc.
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
// Author: morlovich@google.com (Maksim Orlovich)
18
 
 
19
 
#ifndef PAGESPEED_KERNEL_SHAREDMEM_SHARED_MEM_LOCK_MANAGER_H_
20
 
#define PAGESPEED_KERNEL_SHAREDMEM_SHARED_MEM_LOCK_MANAGER_H_
21
 
 
22
 
#include <cstddef>
23
 
 
24
 
#include "pagespeed/kernel/base/basictypes.h"
25
 
#include "pagespeed/kernel/base/named_lock_manager.h"
26
 
#include "pagespeed/kernel/base/scoped_ptr.h"
27
 
#include "pagespeed/kernel/base/string.h"
28
 
#include "pagespeed/kernel/base/string_util.h"
29
 
 
30
 
namespace net_instaweb {
31
 
 
32
 
class AbstractSharedMem;
33
 
class AbstractSharedMemSegment;
34
 
class Hasher;
35
 
class MessageHandler;
36
 
class Scheduler;
37
 
 
38
 
namespace SharedMemLockData {
39
 
 
40
 
struct Bucket;
41
 
 
42
 
}  // namespace SharedMemLockData
43
 
 
44
 
// A simple shared memory named locking manager, which uses scheduler alarms
45
 
// (via SchedulerBasedAbstractLock) when it needs to block.
46
 
//
47
 
// TODO(morlovich): Implement condvars?
48
 
class SharedMemLockManager : public NamedLockManager {
49
 
 public:
50
 
  // Note that you must call Initialize() in the root process, and Attach in
51
 
  // child processes to finish the initialization.
52
 
  //
53
 
  // Locks created by this object must not live after it dies.
54
 
  SharedMemLockManager(
55
 
      AbstractSharedMem* shm, const GoogleString& path, Scheduler* scheduler,
56
 
      Hasher* hasher, MessageHandler* handler);
57
 
  virtual ~SharedMemLockManager();
58
 
 
59
 
  // Sets up our shared state for use of all child processes. Returns
60
 
  // whether successful.
61
 
  bool Initialize();
62
 
 
63
 
  // Connects to already initialized state from a child process.
64
 
  // Returns whether successful.
65
 
  bool Attach();
66
 
 
67
 
  // This should be called from the root process as it is about to exit,
68
 
  // with the same value as were passed to the constructor of any
69
 
  // instance on which Initialize() was called, except the message_handler
70
 
  // may be different (if for example the original one is no longer available
71
 
  // due to the cleanup sequence).
72
 
  static void GlobalCleanup(AbstractSharedMem* shm, const GoogleString& path,
73
 
                            MessageHandler* message_handler);
74
 
 
75
 
  virtual NamedLock* CreateNamedLock(const StringPiece& name);
76
 
 
77
 
 private:
78
 
  friend class SharedMemLock;
79
 
 
80
 
  SharedMemLockData::Bucket* Bucket(size_t bucket);
81
 
 
82
 
  // Offset of mutex wrt to segment base.
83
 
  size_t MutexOffset(SharedMemLockData::Bucket*);
84
 
 
85
 
  AbstractSharedMem* shm_runtime_;
86
 
  GoogleString path_;
87
 
 
88
 
  scoped_ptr<AbstractSharedMemSegment> seg_;
89
 
  Scheduler* scheduler_;
90
 
  Hasher* hasher_;
91
 
  MessageHandler* handler_;
92
 
  size_t lock_size_;
93
 
 
94
 
  DISALLOW_COPY_AND_ASSIGN(SharedMemLockManager);
95
 
};
96
 
 
97
 
}  // namespace net_instaweb
98
 
 
99
 
#endif  // PAGESPEED_KERNEL_SHAREDMEM_SHARED_MEM_LOCK_MANAGER_H_