Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
86
Issues
86
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Switch - Software
Commits
035da384
Commit
035da384
authored
Feb 19, 2016
by
Adam Wujek
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
userspace/libwr: use get_monotonic_* instead of clock_gettime in shmem
Signed-off-by:
Adam Wujek
<
adam.wujek@cern.ch
>
parent
291a32c7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
+7
-12
shmem.c
userspace/libwr/shmem.c
+7
-12
No files found.
userspace/libwr/shmem.c
View file @
035da384
...
...
@@ -11,6 +11,7 @@
#include <sys/mman.h>
#include <libwr/shmem.h>
#include <libwr/util.h>
#define SHM_LOCK_TIMEOUT_MS 50
/* in ms */
/* Get wrs shared memory */
/* return NULL and set errno on error */
...
...
@@ -18,7 +19,7 @@ void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
{
struct
wrs_shm_head
*
head
;
struct
stat
stbuf
;
struct
timespec
tv1
,
tv2
;
uint64_t
tv1
,
tv2
;
void
*
map
;
char
fname
[
64
];
int
write_access
=
flags
&
WRS_SHM_WRITE
;
...
...
@@ -54,7 +55,7 @@ void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
if
(
!
(
flags
&
WRS_SHM_LOCKED
))
return
map
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
tv1
);
tv1
=
get_monotonic_tics
(
);
while
(
1
)
{
/* Releasing does not mean initial data is in place! */
/* Read data with wrs_shm_seqbegin and
...
...
@@ -63,10 +64,8 @@ void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags)
return
map
;
usleep
(
10
*
1000
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
tv2
);
if
((
tv2
.
tv_sec
*
1000
+
tv2
.
tv_nsec
/
1000000
)
-
(
tv1
.
tv_sec
*
1000
+
tv1
.
tv_nsec
/
1000000
)
<
SHM_LOCK_TIMEOUT_MS
)
tv2
=
get_monotonic_tics
();
if
(((
tv2
-
tv1
)
*
1000
)
<
SHM_LOCK_TIMEOUT_MS
)
continue
;
errno
=
ETIMEDOUT
;
...
...
@@ -178,12 +177,10 @@ void *wrs_shm_follow(void *headptr, void *ptr)
void
wrs_shm_write
(
void
*
headptr
,
int
flags
)
{
struct
wrs_shm_head
*
head
=
headptr
;
struct
timespec
tv
;
if
(
flags
==
WRS_SHM_WRITE_END
)
{
/* At end-of-writing update the timestamp too */
clock_gettime
(
CLOCK_MONOTONIC
,
&
tv
);
head
->
stamp
=
tv
.
tv_sec
;
head
->
stamp
=
get_monotonic_sec
();
}
head
->
sequence
++
;
return
;
...
...
@@ -211,10 +208,8 @@ int wrs_shm_seqretry(void *headptr, unsigned start)
int
wrs_shm_age
(
void
*
headptr
)
{
struct
wrs_shm_head
*
head
=
headptr
;
struct
timespec
tv
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
tv
);
return
tv
.
tv_sec
-
head
->
stamp
;
return
get_monotonic_sec
()
-
head
->
stamp
;
}
/* A reader can get the information pointer, for a specific version, or NULL */
...
...
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