projects
/
model-checker-benchmarks.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ms-queue: cleanups
[model-checker-benchmarks.git]
/
ms-queue
/
my_queue.c
diff --git
a/ms-queue/my_queue.c
b/ms-queue/my_queue.c
index eb5d54ad7352f9be434bd9b76b06063963d81727..33a62925c7a6a195fc0002cd54b2d3ce8807553a 100644
(file)
--- a/
ms-queue/my_queue.c
+++ b/
ms-queue/my_queue.c
@@
-1,31
+1,31
@@
#include <threads.h>
#include <threads.h>
+#include <stdlib.h>
#include "my_queue.h"
#include "my_queue.h"
-extern private_t private;
-
-void init_private(int pid)
-{
- private.node = 2 + pid;
-}
+static unsigned int *node_nums;
static unsigned int new_node()
{
static unsigned int new_node()
{
- return
private.node
;
+ return
node_nums[get_thread_num()]
;
}
static void reclaim(unsigned int node)
{
}
static void reclaim(unsigned int node)
{
-
private.node
= node;
+
node_nums[get_thread_num()]
= node;
}
}
-void init_queue(queue_t *q)
+void init_queue(queue_t *q
, int num_threads
)
{
unsigned int i;
pointer head;
pointer tail;
pointer next;
{
unsigned int i;
pointer head;
pointer tail;
pointer next;
+ node_nums = malloc(num_threads * sizeof(*node_nums));
+ for (i = 0; i < num_threads; i++)
+ node_nums[i] = 2 + i;
+
/* initialize queue */
head = MAKE_POINTER(1, 0);
tail = MAKE_POINTER(1, 0);
/* initialize queue */
head = MAKE_POINTER(1, 0);
tail = MAKE_POINTER(1, 0);
@@
-66,18
+66,16
@@
void enqueue(queue_t *q, unsigned int val)
next = atomic_load(&q->nodes[get_ptr(tail)].next);
if (tail == atomic_load(&q->tail)) {
if (get_ptr(next) == 0) { // == NULL
next = atomic_load(&q->nodes[get_ptr(tail)].next);
if (tail == atomic_load(&q->tail)) {
if (get_ptr(next) == 0) { // == NULL
- pointer val = MAKE_POINTER(node, get_count(next) + 1);
+ pointer val
ue
= MAKE_POINTER(node, get_count(next) + 1);
success = atomic_compare_exchange_weak(&q->nodes[get_ptr(tail)].next,
success = atomic_compare_exchange_weak(&q->nodes[get_ptr(tail)].next,
- &next,
- val);
+ &next, value);
}
if (!success) {
unsigned int ptr = get_ptr(atomic_load(&q->nodes[get_ptr(tail)].next));
}
if (!success) {
unsigned int ptr = get_ptr(atomic_load(&q->nodes[get_ptr(tail)].next));
- pointer val = MAKE_POINTER(ptr,
+ pointer val
ue
= MAKE_POINTER(ptr,
get_count(tail) + 1);
atomic_compare_exchange_strong(&q->tail,
get_count(tail) + 1);
atomic_compare_exchange_strong(&q->tail,
- &tail,
- val);
+ &tail, value);
thrd_yield();
}
}
thrd_yield();
}
}
@@
-104,7
+102,7
@@
unsigned int dequeue(queue_t *q)
if (get_ptr(next) == 0) { // NULL
return 0; // NULL
}
if (get_ptr(next) == 0) { // NULL
return 0; // NULL
}
- atomic_compare_exchange_
weak
(&q->tail,
+ atomic_compare_exchange_
strong
(&q->tail,
&tail,
MAKE_POINTER(get_ptr(next), get_count(tail) + 1));
thrd_yield();
&tail,
MAKE_POINTER(get_ptr(next), get_count(tail) + 1));
thrd_yield();