libfoedus-core
FOEDUS Core Library
xct_mcs_impl.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_XCT_XCT_MCS_IMPL_HPP_
19 #define FOEDUS_XCT_XCT_MCS_IMPL_HPP_
20 
21 #include "foedus/compiler.hpp"
22 #include "foedus/xct/fwd.hpp"
23 #include "foedus/xct/xct_id.hpp"
24 
25 namespace foedus {
26 namespace xct {
27 
86 template<typename ADAPTOR, typename RW_BLOCK>
87 class McsImpl { // TODO(Hideaki) should be renamed to McsRwImpl
88  public:
89  explicit McsImpl(ADAPTOR adaptor) : adaptor_(adaptor) {}
92 
95 
97 
100 
103 
114  static bool does_support_try_rw_reader();
115 
122 
125 
136 
143  bool retry_async_rw_reader(McsRwLock* lock, McsBlockIndex block_index);
144  bool retry_async_rw_writer(McsRwLock* lock, McsBlockIndex block_index);
145 
151  void cancel_async_rw_reader(McsRwLock* lock, McsBlockIndex block_index);
152  void cancel_async_rw_writer(McsRwLock* lock, McsBlockIndex block_index);
153 
156 
160  void release_rw_reader(McsRwLock* lock, McsBlockIndex block_index);
165  void release_rw_writer(McsRwLock* lock, McsBlockIndex block_index);
168 
169  private:
170  ADAPTOR adaptor_;
171 };
172 
181 template<typename ADAPTOR>
182 class McsWwImpl {
183  public:
184  explicit McsWwImpl(ADAPTOR adaptor) : adaptor_(adaptor) {}
185 
188 
195  // We so far do not have asynchronous version of WW lock. probably we don't need it..
196 
203  void release(McsWwLock* lock, McsBlockIndex block_index);
204 
205  private:
206  ADAPTOR adaptor_;
207 };
208 
209 
219  public:
220  // only static methods
221  McsWwOwnerlessImpl() = delete;
222  ~McsWwOwnerlessImpl() = delete;
223 
225  static void ownerless_acquire_unconditional(McsWwLock* lock);
231  static bool ownerless_acquire_try(McsWwLock* lock);
232  static void ownerless_release(McsWwLock* lock);
233  static void ownerless_initial(McsWwLock* lock);
234  // No try/asynchronous versions for guests. Probably we don't need them.
235  // TBD So far no RW versions for guests. We might need them later..
236 };
237 
238 } // namespace xct
239 } // namespace foedus
240 #endif // FOEDUS_XCT_XCT_MCS_IMPL_HPP_
McsBlockIndex initial(McsWwLock *lock)
[WW] This doesn't use any atomic operation.
static void ownerless_release(McsWwLock *lock)
McsBlockIndex acquire_try_rw_reader(McsRwLock *lock)
Try-acquire.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
McsBlockIndex acquire_unconditional_rw_writer(McsRwLock *lock)
[RW] Unconditionally takes a writer lock.
void cancel_async_rw_reader(McsRwLock *lock, McsBlockIndex block_index)
[RW] Cancels the lock request.
Forward declarations of classes in transaction package.
void release(McsWwLock *lock, McsBlockIndex block_index)
[WW] Unlcok an MCS lock acquired by this thread.
AcquireAsyncRet acquire_async_rw_writer(McsRwLock *lock)
[RW] Asynchronously try to take a writer lock.
static void ownerless_initial(McsWwLock *lock)
bool retry_async_rw_reader(McsRwLock *lock, McsBlockIndex block_index)
[RW] Returns whether the lock requeust is now granted.
Return value of acquire_async_rw.
Definition: xct_id.hpp:161
Definitions of IDs in this package and a few related constant values.
An exclusive-only (WW) MCS lock data structure.
Definition: xct_id.hpp:324
Implements an MCS-locking Algorithm.
void release_rw_reader(McsRwLock *lock, McsBlockIndex block_index)
Release and other stuffs.
static bool ownerless_acquire_try(McsWwLock *lock)
[WW-Guest] Try to take an exclusive guest lock on the given MCSg lock.
McsBlockIndex acquire_unconditional(McsWwLock *lock)
[WW] Unconditionally takes exclusive-only MCS lock on the given lock.
A specialized/simplified implementation of an MCS-locking Algorithm for exclusive-only (WW) locks...
McsBlockIndex acquire_try_rw_writer(McsRwLock *lock)
[RW] Try to take a writer lock.
McsBlockIndex acquire_unconditional_rw_reader(McsRwLock *lock)
RW-lock methods: BEGIN.
static bool does_support_try_rw_reader()
McsWwImpl(ADAPTOR adaptor)
void release_rw_writer(McsRwLock *lock, McsBlockIndex block_index)
[RW] Releases a writer lock.
McsBlockIndex acquire_try(McsWwLock *lock)
[WW] Try to take an exclusive lock.
uint32_t McsBlockIndex
Index in thread-local MCS block.
Definition: xct_id.hpp:153
A ownerless (contextless) interface for McsWwImpl.
void cancel_async_rw_writer(McsRwLock *lock, McsBlockIndex block_index)
bool retry_async_rw_writer(McsRwLock *lock, McsBlockIndex block_index)
static void ownerless_acquire_unconditional(McsWwLock *lock)
[WW-Guest] Unconditionally takes exclusive-only guest lock on the given MCSg lock.
AcquireAsyncRet acquire_async_rw_reader(McsRwLock *lock)
Async-acquire trios (acquire, cancel, retry)
An MCS reader-writer lock data structure.
Definition: xct_id.hpp:795
McsImpl(ADAPTOR adaptor)