Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
key-value-store
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Samarth Joshi
key-value-store
Commits
a4ff33f0
Commit
a4ff33f0
authored
Oct 31, 2020
by
Shivaji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added xchange atomic
parent
4b423db7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
LRU.c
LRU.c
+13
-7
No files found.
LRU.c
View file @
a4ff33f0
...
...
@@ -5,9 +5,11 @@
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdatomic.h>
#define MAX_SIZE 10
#define ALLOTMEMORY (KV *)malloc(sizeof(KV)*MAX_SIZE)
#define ALLOTMEMORY (KV *)malloc(sizeof(KV)*MAX_SIZE)
// static unsigned _Atomic active[10];
typedef
enum
{
FALSE
,
TRUE
}
bool
;
...
...
@@ -18,7 +20,10 @@ struct KV{
bool
valid
;
bool
modified
;
int
lock
;
// unsigned _Atomic lock;
};
int
lockers
[
10
];
typedef
struct
KV
KV
;
struct
queue
{
...
...
@@ -104,10 +109,10 @@ void delet(char *key)
{
if
(
array
[
i
]
->
key
==
key
)
{
while
(
cas
(
&
(
array
[
i
]
->
lock
),
0
,
1
)
==
FALSE
)
;
while
(
atomic_exchange_explicit
(
&
(
array
[
i
]
->
lock
),
1
,
0
)
==
1
)
;
remove_element_from_deque
(
key
);
array
[
i
]
->
valid
=
FALSE
;
cas
(
&
(
array
[
i
]
->
lock
),
1
,
0
);
atomic_exchange_explicit
(
&
(
array
[
i
]
->
lock
),
0
,
1
);
break
;
}
}
...
...
@@ -134,13 +139,13 @@ void put(char *key, char *value)
// replacment from cache
}
while
(
cas
(
&
(
array
[
indx
]
->
lock
),
0
,
1
)
==
FALSE
)
;
while
(
atomic_exchange_explicit
(
&
(
array
[
indx
]
->
lock
),
1
,
0
)
==
1
)
;
array
[
indx
]
->
key
=
key
;
array
[
indx
]
->
value
=
value
;
array
[
indx
]
->
valid
=
TRUE
;
array
[
indx
]
->
modified
=
TRUE
;
insert_into_queue
(
key
);
cas
(
&
(
array
[
indx
]
->
lock
),
1
,
0
);
atomic_exchange_explicit
(
&
(
array
[
indx
]
->
lock
),
0
,
1
);
}
char
*
get
(
char
*
key
)
...
...
@@ -149,10 +154,10 @@ char* get(char *key)
{
if
(
array
[
i
]
->
key
==
key
)
{
while
(
cas
(
&
(
array
[
i
]
->
lock
),
0
,
1
)
==
FALSE
);
while
(
atomic_exchange_explicit
(
&
(
array
[
i
]
->
lock
),
1
,
0
)
==
1
);
remove_element_from_deque
(
key
);
insert_into_queue
(
key
);
cas
(
&
(
array
[
i
]
->
lock
),
1
,
0
);
atomic_exchange_explicit
(
&
(
array
[
i
]
->
lock
),
0
,
1
);
return
array
[
i
]
->
value
;
}
}
...
...
@@ -166,6 +171,7 @@ int main()
{
array
[
j
]
=
(
KV
*
)
malloc
(
sizeof
(
KV
));
array
[
j
]
->
valid
=
FALSE
;
array
[
j
]
->
lock
=
0
;
}
char
key1
[
250
]
=
"Hello world1"
;
char
value1
[
256
]
=
"THIS IS Vlaue1"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment