Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nocache
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Danil Mikhailov
nocache
Commits
e15e0a9f
Commit
e15e0a9f
authored
Feb 04, 2012
by
Julius Plenz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make it thread safe
parent
2ebcf516
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
2 deletions
+9
-2
nocache.c
nocache.c
+9
-2
No files found.
nocache.c
View file @
e15e0a9f
...
...
@@ -7,6 +7,7 @@
#include <stdio.h>
#include <dlfcn.h>
#include <string.h>
#include <pthread.h>
int
(
*
_original_open
)(
const
char
*
pathname
,
int
flags
,
mode_t
mode
);
int
(
*
_original_close
)(
int
fd
);
...
...
@@ -30,6 +31,7 @@ struct fadv_info {
};
static
struct
fadv_info
fds
[
_MAX_FDS
];
static
size_t
PAGESIZE
;
static
pthread_mutex_t
lock
;
void
init
(
void
)
{
...
...
@@ -37,6 +39,7 @@ void init(void)
_original_open
=
(
int
(
*
)(
const
char
*
,
int
,
mode_t
))
dlsym
(
RTLD_NEXT
,
"open"
);
_original_close
=
(
int
(
*
)(
int
))
dlsym
(
RTLD_NEXT
,
"close"
);
pthread_mutex_init
(
&
lock
,
NULL
);
PAGESIZE
=
getpagesize
();
for
(
i
=
0
;
i
<
_MAX_FDS
;
i
++
)
fds
[
i
].
fd
=
-
1
;
...
...
@@ -45,14 +48,19 @@ void init(void)
int
open
(
const
char
*
pathname
,
int
flags
,
mode_t
mode
)
{
int
fd
;
if
((
fd
=
_original_open
(
pathname
,
flags
,
mode
))
!=
-
1
)
if
((
fd
=
_original_open
(
pathname
,
flags
,
mode
))
!=
-
1
)
{
pthread_mutex_lock
(
&
lock
);
store_pageinfo
(
fd
);
pthread_mutex_unlock
(
&
lock
);
}
return
fd
;
}
int
close
(
int
fd
)
{
pthread_mutex_lock
(
&
lock
);
free_unclaimed_pages
(
fd
);
pthread_mutex_unlock
(
&
lock
);
return
_original_close
(
fd
);
}
...
...
@@ -147,7 +155,6 @@ static void free_unclaimed_pages(int fd)
for
(
j
=
0
;
j
<
fds
[
i
].
nr_pages
;
j
++
)
{
if
(
!
(
fds
[
i
].
info
[
j
]
&
1
))
{
fadv_dontneed
(
fd
,
j
*
PAGESIZE
,
PAGESIZE
);
fadv_dontneed
(
fd
,
j
*
PAGESIZE
,
PAGESIZE
);
}
}
...
...
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