libfoedus-core
FOEDUS Core Library
shared_rendezvous.cpp
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  */
19 
20 #include "foedus/assert_nd.hpp"
23 
24 namespace foedus {
25 namespace soc {
26 
28  uninitialize();
29  signaled_ = false;
30  initialized_ = true;
31  cond_.initialize();
32 }
33 
35  if (!is_initialized()) {
36  return;
37  }
38 }
39 
41  if (is_signaled_weak()) { // just an optimization.
42  return;
43  }
44 
45  uint64_t demand = cond_.acquire_ticket();
46  if (is_signaled()) {
47  return;
48  }
49  cond_.wait(demand);
51 }
52 
53 bool SharedRendezvous::wait_for(uint64_t timeout_nanosec) {
54  if (is_signaled_weak()) { // just an optimization.
55  return true;
56  }
57 
58  uint64_t demand = cond_.acquire_ticket();
59  if (is_signaled()) {
60  return true;
61  }
62  bool received = cond_.timedwait(demand, timeout_nanosec / 1000);
63  ASSERT_ND(!received || is_signaled());
64  return is_signaled();
65 }
66 
68  signaled_ = true;
69  cond_.signal();
70 }
71 
72 } // namespace soc
73 } // namespace foedus
bool is_signaled() const
returns whether the even has signaled.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
bool wait_for(uint64_t timeout_nanosec)
Block until the event happens or the given period elapses.
void wait(uint64_t demanded_ticket, uint64_t polling_spins=kDefaultPollingSpins, uint64_t max_interval_us=kDefaultPollingMaxIntervalUs) const
Unconditionally wait for signal.
void signal()
Notify all waiters that the event has happened.
uint64_t acquire_ticket() const
Gives the ticket to.
bool is_signaled_weak() const
weak version without fence.
Atomic fence methods and load/store with fences that work for both C++11/non-C++11 code...
void wait()
Block until the event happens.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
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.