-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfifo_adt_test.c
107 lines (85 loc) · 2.19 KB
/
fifo_adt_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <ucontext.h>
#include <signal.h>
#include <sched.h>
#include <limits.h>
#include <assert.h>
#include <stdarg.h>
/* for mutex testing */
#include <pthread.h>
#include "portable_defns.h"
#include "fifo_queue_adt.h"
#include "ptst.h"
#define SENTINEL_KEYMIN ( 1UL)
#define SENTINEL_KEYMAX (~0UL)
static struct {
CACHE_PAD(0);
osi_queue_t *q1;
CACHE_PAD(1);
osi_queue_t *q2;
CACHE_PAD(2);
} shared;
const int n_threads = 8;
typedef struct harness_ulong {
unsigned long val;
} harness_ulong_t;
typedef struct harness_range {
unsigned long tid;
unsigned long start_ix;
unsigned long n_inserts;
} harness_range_t;
void *
thread_do_test(void *arg)
{
unsigned long ix, max_ix;
harness_ulong_t *node;
harness_range_t *hr;
hr = (harness_range_t *) arg;
printf("Starting thread %d, will perf. %d enqueues from %d\n", hr->tid,
hr->n_inserts, hr->start_ix);
/* Allocate nodes and insert in skip queue */
max_ix = hr->start_ix + hr->n_inserts;
for (ix = hr->start_ix; ix < max_ix; ++ix) {
node = (harness_ulong_t *) malloc(sizeof(harness_ulong_t));
memset(node, 0, sizeof(harness_ulong_t));
node->val = ix;
osi_fifo_enqueue(shared.q1, node);
printf("inserted: %d\n", ix);
}
out:
return (NULL);
}
int
main(int argc, char **argv)
{
int ix;
harness_ulong_t *node;
pthread_t thrd[n_threads];
harness_range_t hr[n_threads];
printf("Starting ADT Test\n");
/* do this once, 1st thread */
_init_ptst_subsystem();
_init_gc_subsystem();
_init_fifo_queue_subsystem();
shared.q1 = osi_fifo_queue_alloc();
for (ix = 0; ix < n_threads; ++ix) {
(hr[ix]).tid = ix;
(hr[ix]).start_ix = ix * 5000;
(hr[ix]).n_inserts = 5000;
pthread_create (&(thrd[ix]), NULL, thread_do_test, (void *) &(hr[ix]));
}
for (ix = 0; ix < n_threads; ++ix)
pthread_join(thrd[ix], NULL);
return 0;
}