From 91722c7663f002ad149ebe985ca55dd58152e902 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 25 Apr 2008 08:39:32 +0000 Subject: [PATCH] add our barrier --- .../Prefetch/Moldyn/dsm/Barrier.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Robust/src/Benchmarks/Prefetch/Moldyn/dsm/Barrier.java diff --git a/Robust/src/Benchmarks/Prefetch/Moldyn/dsm/Barrier.java b/Robust/src/Benchmarks/Prefetch/Moldyn/dsm/Barrier.java new file mode 100644 index 00000000..482b695a --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/Moldyn/dsm/Barrier.java @@ -0,0 +1,52 @@ +public class Barrier { + int numthreads; + int entercount; + boolean cleared; + + public Barrier(int n) { + numthreads=n; + cleared = false; + entercount = 0; + } + + public Barrier() { + } + + public void reset() { + cleared = false; + entercount = 0; + } + + public static void enterBarrier(Barrier b) { + int tmp; + boolean retry=true; + + do { + atomic { + if (!b.cleared) { + b.entercount++; + tmp = b.entercount; + if (tmp==b.numthreads) { + if(b.numthreads > 1) + b.cleared=true; + b.entercount--; + return; + } + retry=false; + } + } + } while(retry); + + while(true) { + atomic { + if (b.cleared) { + b.entercount--; + int count = b.entercount; + if (count==0) + b.cleared=false; + return; + } + } + } + } +} -- 2.34.1