-
Notifications
You must be signed in to change notification settings - Fork 42
/
copy_on_write.h
92 lines (78 loc) · 2.25 KB
/
copy_on_write.h
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
/*
* File: copy_on_write.h
* Author: Vasileios Trigonakis <vasileios.trigonakis@epfl.ch>
* Description: Similar to Java's CopyOnWriteArrayList. One array per bucket.
* http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CopyOnWriteArrayList.html
* copy_on_write.h is part of ASCYLIB
*
* Copyright (c) 2014 Vasileios Trigonakis <vasileios.trigonakis@epfl.ch>,
* Tudor David <tudor.david@epfl.ch>
* Distributed Programming Lab (LPD), EPFL
*
* ASCYLIB is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 2
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _COPY_ON_WRITE_H_
#define _COPY_ON_WRITE_H_
#include <assert.h>
#include <getopt.h>
#include <limits.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <stdint.h>
#include <atomic_ops.h>
#include "lock_if.h"
#include "common.h"
#include "utils.h"
#include "measurements.h"
#include "ssalloc.h"
#include "ssmem.h"
#define DEFAULT_ALTERNATE 0
#define DEFAULT_EFFECTIVE 1
#define DEFAULT_LOAD 1
#define CPY_ON_WRITE_READ_ONLY_FAIL RO_FAIL
static volatile int stop;
extern __thread ssmem_allocator_t* alloc;
extern size_t array_ll_fixed_size;
typedef volatile struct kv
{
skey_t key;
sval_t val;
} kv_t;
typedef struct array_ll
{
size_t size;
kv_t* kvs;
} array_ll_t;
typedef ALIGNED(CACHE_LINE_SIZE) struct copy_on_write
{
union
{
struct
{
size_t num_buckets;
size_t hash;
volatile ptlock_t* lock;
volatile array_ll_t** array;
};
uint8_t padding[CACHE_LINE_SIZE];
};
} copy_on_write_t;
copy_on_write_t* copy_on_write_new();
size_t copy_on_write_size(copy_on_write_t* set);
sval_t cpy_search(copy_on_write_t* set, skey_t key);
int cpy_insert(copy_on_write_t* set, skey_t key, sval_t val);
sval_t cpy_delete(copy_on_write_t* set, skey_t key);
#endif /* _COPY_ON_WRITE_H_ */