futex_map.hh (13642:253cda14088e) futex_map.hh (13650:93efc0143eb7)
1/*
2 * Copyright (c) 2017 Advanced Micro Devices, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 207 unchanged lines hidden (view full) ---

216 }
217 }
218
219 if (waiterList.empty())
220 erase(it);
221
222 return woken_up;
223 }
1/*
2 * Copyright (c) 2017 Advanced Micro Devices, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 207 unchanged lines hidden (view full) ---

216 }
217 }
218
219 if (waiterList.empty())
220 erase(it);
221
222 return woken_up;
223 }
224
225 /**
226 * This operation wakes a given number (val) of waiters. If there are
227 * more threads waiting than woken, they are removed from the wait
228 * queue of the futex pointed to by addr1 and added to the wait queue
229 * of the futex pointed to by addr2. The number of waiter moved is
230 * capped by count2 (misused timeout parameter).
231 *
232 * The return value is the number of waiters that are woken or
233 * requeued.
234 */
235 int
236 requeue(Addr addr1, uint64_t tgid, int count, int count2, Addr addr2)
237 {
238 FutexKey key1(addr1, tgid);
239 auto it1 = find(key1);
240
241 if (it1 == end())
242 return 0;
243
244 int woken_up = 0;
245 auto &waiterList1 = it1->second;
246
247 while (!waiterList1.empty() && woken_up < count) {
248 waiterList1.front().tc->activate();
249 waiterList1.pop_front();
250 woken_up++;
251 }
252
253 WaiterList tmpList;
254 int requeued = 0;
255
256 while (!waiterList1.empty() && requeued < count2) {
257 auto w = waiterList1.front();
258 waiterList1.pop_front();
259 tmpList.push_back(w);
260 requeued++;
261 }
262
263 FutexKey key2(addr2, tgid);
264 auto it2 = find(key2);
265
266 if (it2 == end() && requeued > 0) {
267 insert({key2, tmpList});
268 } else {
269 it2->second.insert(it2->second.end(),
270 tmpList.begin(), tmpList.end());
271 }
272
273 if (waiterList1.empty())
274 erase(it1);
275
276 return woken_up + requeued;
277 }
224};
225
226#endif // __FUTEX_MAP_HH__
278};
279
280#endif // __FUTEX_MAP_HH__