Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
3405b7da
Commit
3405b7da
authored
Oct 15, 2012
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Android: use monotonic clock
parent
cc44bfb6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
25 deletions
+43
-25
include/vlc_threads.h
include/vlc_threads.h
+6
-2
src/android/thread.c
src/android/thread.c
+37
-23
No files found.
include/vlc_threads.h
View file @
3405b7da
...
...
@@ -124,8 +124,12 @@ typedef struct vlc_timer *vlc_timer_t;
typedef
struct
vlc_thread
*
vlc_thread_t
;
typedef
pthread_mutex_t
vlc_mutex_t
;
#define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER
typedef
pthread_cond_t
vlc_cond_t
;
#define VLC_STATIC_COND PTHREAD_COND_INITIALIZER
typedef
struct
{
pthread_cond_t
cond
;
unsigned
clock
;
}
vlc_cond_t
;
#define VLC_STATIC_COND { PTHREAD_COND_INITIALIZER, CLOCK_REALTIME }
typedef
pthread_key_t
vlc_threadvar_t
;
typedef
struct
vlc_timer
*
vlc_timer_t
;
...
...
src/android/thread.c
View file @
3405b7da
...
...
@@ -35,6 +35,7 @@
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <assert.h>
#include <sys/types.h>
#include <unistd.h>
/* fsync() */
...
...
@@ -44,10 +45,6 @@
#include <android/log.h>
#include <sys/syscall.h>
/* __NR_gettid */
/* FIXME: Android has a monotonic clock
* XXX : how to use it with pthread_cond_wait() ? */
# warning Monotonic clock not available. Expect timing issues.
/* helper */
static
struct
timespec
mtime_to_ts
(
mtime_t
date
)
{
...
...
@@ -186,44 +183,47 @@ void vlc_threads_setup (libvlc_int_t *p_libvlc)
/* cond */
void
vlc_cond_init
(
vlc_cond_t
*
p_
condvar
)
void
vlc_cond_init
(
vlc_cond_t
*
condvar
)
{
if
(
unlikely
(
pthread_cond_init
(
p_condvar
,
NULL
)))
if
(
unlikely
(
pthread_cond_init
(
&
condvar
->
cond
,
NULL
)))
abort
();
condvar
->
clock
=
CLOCK_MONOTONIC
;
}
void
vlc_cond_init_daytime
(
vlc_cond_t
*
p_
condvar
)
void
vlc_cond_init_daytime
(
vlc_cond_t
*
condvar
)
{
vlc_cond_init
(
p_condvar
);
if
(
unlikely
(
pthread_cond_init
(
&
condvar
->
cond
,
NULL
)))
abort
();
condvar
->
clock
=
CLOCK_REALTIME
;
}
void
vlc_cond_destroy
(
vlc_cond_t
*
p_
condvar
)
void
vlc_cond_destroy
(
vlc_cond_t
*
condvar
)
{
int
val
=
pthread_cond_destroy
(
p_condvar
);
int
val
=
pthread_cond_destroy
(
&
condvar
->
cond
);
VLC_THREAD_ASSERT
(
"destroying condition"
);
}
void
vlc_cond_signal
(
vlc_cond_t
*
p_
condvar
)
void
vlc_cond_signal
(
vlc_cond_t
*
condvar
)
{
int
val
=
pthread_cond_signal
(
p_condvar
);
int
val
=
pthread_cond_signal
(
&
condvar
->
cond
);
VLC_THREAD_ASSERT
(
"signaling condition variable"
);
}
void
vlc_cond_broadcast
(
vlc_cond_t
*
p_
condvar
)
void
vlc_cond_broadcast
(
vlc_cond_t
*
condvar
)
{
pthread_cond_broadcast
(
p_condvar
);
pthread_cond_broadcast
(
&
condvar
->
cond
);
}
void
vlc_cond_wait
(
vlc_cond_t
*
p_
condvar
,
vlc_mutex_t
*
p_mutex
)
void
vlc_cond_wait
(
vlc_cond_t
*
condvar
,
vlc_mutex_t
*
p_mutex
)
{
if
(
thread
)
{
vlc_testcancel
();
vlc_mutex_lock
(
&
thread
->
lock
);
thread
->
cond
=
p_condvar
;
thread
->
cond
=
&
condvar
->
cond
;
vlc_mutex_unlock
(
&
thread
->
lock
);
}
int
val
=
pthread_cond_wait
(
p_condvar
,
p_mutex
);
int
val
=
pthread_cond_wait
(
&
condvar
->
cond
,
p_mutex
);
if
(
thread
)
{
vlc_mutex_lock
(
&
thread
->
lock
);
...
...
@@ -235,19 +235,32 @@ void vlc_cond_wait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex)
VLC_THREAD_ASSERT
(
"waiting on condition"
);
}
int
vlc_cond_timedwait
(
vlc_cond_t
*
p_
condvar
,
vlc_mutex_t
*
p_mutex
,
int
vlc_cond_timedwait
(
vlc_cond_t
*
condvar
,
vlc_mutex_t
*
p_mutex
,
mtime_t
deadline
)
{
struct
timespec
ts
=
mtime_to_ts
(
deadline
);
int
(
*
cb
)(
pthread_cond_t
*
,
pthread_mutex_t
*
,
const
struct
timespec
*
);
if
(
thread
)
{
vlc_testcancel
();
vlc_mutex_lock
(
&
thread
->
lock
);
thread
->
cond
=
p_condvar
;
thread
->
cond
=
&
condvar
->
cond
;
vlc_mutex_unlock
(
&
thread
->
lock
);
}
int
val
=
pthread_cond_timedwait
(
p_condvar
,
p_mutex
,
&
ts
);
switch
(
condvar
->
clock
)
{
case
CLOCK_REALTIME
:
cb
=
pthread_cond_timedwait
;
break
;
case
CLOCK_MONOTONIC
:
cb
=
pthread_cond_timedwait_monotonic_np
;
break
;
default:
assert
(
0
);
}
int
val
=
cb
(
&
condvar
->
cond
,
p_mutex
,
&
ts
);
if
(
val
!=
ETIMEDOUT
)
VLC_THREAD_ASSERT
(
"timed-waiting on condition"
);
...
...
@@ -369,11 +382,12 @@ int vlc_set_priority (vlc_thread_t th, int priority)
void
vlc_cancel
(
vlc_thread_t
thread_id
)
{
pthread_cond_t
*
cond
;
vlc_atomic_set
(
&
thread_id
->
killed
,
true
);
vlc_mutex_lock
(
&
thread_id
->
lock
);
vlc_cond_t
*
cond
=
thread_id
->
cond
;
cond
=
thread_id
->
cond
;
if
(
cond
)
pthread_cond_broadcast
(
cond
);
vlc_mutex_unlock
(
&
thread_id
->
lock
);
...
...
@@ -438,7 +452,7 @@ mtime_t mdate (void)
{
struct
timespec
ts
;
if
(
unlikely
(
clock_gettime
(
CLOCK_
REALTIME
,
&
ts
)
!=
0
))
if
(
unlikely
(
clock_gettime
(
CLOCK_
MONOTONIC
,
&
ts
)
!=
0
))
abort
();
return
(
INT64_C
(
1000000
)
*
ts
.
tv_sec
)
+
(
ts
.
tv_nsec
/
1000
);
...
...
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