libfoedus-core
FOEDUS Core Library
shared_polling.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_SOC_SHARED_POLLING_HPP_
19 #define FOEDUS_SOC_SHARED_POLLING_HPP_
20 
21 #include <stdint.h>
22 
23 #include "foedus/cxx11.hpp"
24 
25 namespace foedus {
26 namespace soc {
27 
29 const uint64_t kDefaultPollingSpins = (1ULL << 10);
31 const uint64_t kDefaultPollingMaxIntervalUs = (1ULL << 15);
33 const uint64_t kInitialPollingIntervalUs = (1ULL << 8);
34 
64  public:
66 
67  // Disable copy constructors
69  SharedPolling& operator=(const SharedPolling&) CXX11_FUNC_DELETE;
70 
71  void initialize();
72 
79  uint64_t acquire_ticket() const;
80 
87  void wait(
88  uint64_t demanded_ticket,
89  uint64_t polling_spins = kDefaultPollingSpins,
90  uint64_t max_interval_us = kDefaultPollingMaxIntervalUs) const;
91 
100  bool timedwait(
101  uint64_t demanded_ticket,
102  uint64_t timeout_microsec,
103  uint64_t polling_spins = kDefaultPollingSpins,
104  uint64_t max_interval_us = kDefaultPollingMaxIntervalUs) const;
105 
112  void signal();
113 
114  private:
119  uint64_t cur_ticket_;
120 
121  void spin_poll(uint64_t demanded_ticket, uint64_t polling_spins) const;
122 };
123 } // namespace soc
124 } // namespace foedus
125 #endif // FOEDUS_SOC_SHARED_POLLING_HPP_
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
void wait(uint64_t demanded_ticket, uint64_t polling_spins=kDefaultPollingSpins, uint64_t max_interval_us=kDefaultPollingMaxIntervalUs) const
Unconditionally wait for signal.
A polling-wait mechanism that can be placed in shared memory and used from multiple processes...
uint64_t acquire_ticket() const
Gives the ticket to.
const uint64_t kInitialPollingIntervalUs
Initial value of sleep interval in us.
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
Definition: cxx11.hpp:131
#define CXX11_FUNC_DELETE
Used in public headers in place of " = delete" of C++11.
Definition: cxx11.hpp:128
const uint64_t kDefaultPollingMaxIntervalUs
Default value of max_interval_us.
bool timedwait(uint64_t demanded_ticket, uint64_t timeout_microsec, uint64_t polling_spins=kDefaultPollingSpins, uint64_t max_interval_us=kDefaultPollingMaxIntervalUs) const
Wait for signal up to the given timeout.
void signal()
Signal it to let waiters exit.
const uint64_t kDefaultPollingSpins
Default value of polling_spins.