Commit de95d5f9 authored by Tingzhe Zhou's avatar Tingzhe Zhou Committed by Facebook Github Bot

Improve blocking and accuracy

Summary:
Blocking algorithm:
 Push:
1.  push
2.  increase the PTicket number
3.  put (PTicket << 1) to the corresponding place in futex array.
4.  if the original  futex value & 1  == 1,  wake up ()

Pop:
1.  increase the CTicket number
2.  spin if the corresponding CTicket futex is not ready
3.  set the right bit of the CTicket futex  to 1, wait on it.
4. pop

Add additional control to improve the accuracy:
For the top several levels (top 0 - 3 levels by default), it does not arbitrarily insert any node in the middle of the list. Thus guaranteeing no later coming lower priorities can be insert at the top levels (pruning strategy still valid for the top four levels). For the bottom levels (start from level 7 by default), if insertion requires to hold parent + child locks, it traverses the parent list to check whether the parent list has lower priority nodes than the new node. If the condition holds, insert the new node to the parent and get the last node in the parent list and insert it to the child list.

Reviewed By: magedm

Differential Revision: D9094903

fbshipit-source-id: fa4d31fb0c21da746570029e0e3b4b3fbeaa2024
parent 7f721452
......@@ -24,6 +24,8 @@
#include <folly/test/DeterministicSchedule.h>
#include <glog/logging.h>
using namespace folly;
DEFINE_int32(reps, 1, "number of reps");
DEFINE_int64(ops, 32, "number of operations per rep");
DEFINE_int64(elems, 64, "number of elements");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment