33 #ifndef __FUTEX_MAP_HH__ 34 #define __FUTEX_MAP_HH__ 36 #include <unordered_map> 50 : addr(addr_in), tgid(tgid_in)
57 return addr == in.
addr && tgid == in.
tgid;
73 for (
int i = 0;
i <
sizeof(uint64_t) /
sizeof(
size_t);
i++) {
74 hash ^= (size_t)(in.
addr >>
sizeof(
size_t) *
i) ^
75 (
size_t)(in.
tgid >>
sizeof(size_t) *
i);
95 : tc(_tc), bitmask(_bitmask)
102 : tc(_tc), bitmask(0xffffffff)
112 return bitmask & wakeup_bitmask;
121 class FutexMap :
public std::unordered_map<FutexKey, WaiterList>
133 insert({key, waiterList});
153 auto &waiterList = it->second;
155 while (!waiterList.empty() && woken_up <
count) {
160 auto& tc = waiterList.front().tc;
165 waiterList.pop_front();
168 if (waiterList.empty())
187 insert({key, waiterList});
211 auto &waiterList = it->second;
212 auto iter = waiterList.begin();
214 while (iter != waiterList.end()) {
219 iter = waiterList.erase(iter);
226 if (waiterList.empty())
246 auto it1 = find(key1);
252 auto &waiterList1 =
it1->second;
254 while (!waiterList1.empty() && woken_up <
count) {
255 waiterList1.front().tc->activate();
256 waiterList1.pop_front();
263 while (!waiterList1.empty() && requeued < count2) {
264 auto w = waiterList1.front();
265 waiterList1.pop_front();
266 tmpList.push_back(
w);
271 auto it2 = find(key2);
273 if (
it2 == end() && requeued > 0) {
274 insert({key2, tmpList});
276 it2->second.insert(
it2->second.end(),
277 tmpList.begin(), tmpList.end());
280 if (waiterList1.empty())
283 return woken_up + requeued;
287 #endif // __FUTEX_MAP_HH__
bool operator==(const FutexKey &in) const
std::list< WaiterState > WaiterList
size_t operator()(const FutexKey &in) const
WaiterState defines internal state of a waiter thread.
Overload hash function for BasicBlockRange type.
bool checkMask(int wakeup_bitmask) const
return true if the bit-wise AND of the wakeup_bitmask given by a waking thread and this thread's inte...
ThreadContext is the external interface to all thread state for anything outside of the CPU...
int requeue(Addr addr1, uint64_t tgid, int count, int count2, Addr addr2)
This operation wakes a given number (val) of waiters.
int wakeup(Addr addr, uint64_t tgid, int count)
Wakes up at most count waiting threads on a futex.
virtual void suspend()=0
Set the status to Suspended.
virtual void activate()=0
Set the status to Active.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
WaiterState(ThreadContext *_tc)
if bitset is not defined, just set bitmask to 0xffffffff
WaiterState(ThreadContext *_tc, int _bitmask)
this constructor is used if futex ops with bitset are used
void suspend_bitset(Addr addr, uint64_t tgid, ThreadContext *tc, int bitmask)
inserts a futex into the map with one waiting TC associates the waiter with a given bitmask ...
int wakeup_bitset(Addr addr, uint64_t tgid, int bitmask)
Wakes up all waiters waiting on the addr and associated with the given bitset.
FutexKey(uint64_t addr_in, uint64_t tgid_in)
void suspend(Addr addr, uint64_t tgid, ThreadContext *tc)
Inserts a futex into the map with one waiting TC.
FutexMap class holds a map of all futexes used in the system.
FutexKey class defines an unique identifier for a particular futex in the system. ...