mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 20:31:17 +00:00
audacious thread timing the correct way -- texeci's to follow
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@766 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
428526ba48
commit
e6af47a76f
@ -21,6 +21,7 @@
|
|||||||
* --------------------------------------------------------------------------- */
|
* --------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -69,9 +70,7 @@ int create_audacious_thread(void)
|
|||||||
pthread_mutex_init(&info.audacious.item_mutex, NULL);
|
pthread_mutex_init(&info.audacious.item_mutex, NULL);
|
||||||
pthread_mutex_init(&info.audacious.runnable_mutex, NULL);
|
pthread_mutex_init(&info.audacious.runnable_mutex, NULL);
|
||||||
/* Init runnable condition for worker thread */
|
/* Init runnable condition for worker thread */
|
||||||
pthread_mutex_lock(&info.audacious.runnable_mutex);
|
pthread_cond_init(&info.audacious.runnable_cond, NULL);
|
||||||
info.audacious.runnable=1;
|
|
||||||
pthread_mutex_unlock(&info.audacious.runnable_mutex);
|
|
||||||
if (pthread_create(&info.audacious.thread, &info.audacious.thread_attr, audacious_thread_func, NULL))
|
if (pthread_create(&info.audacious.thread, &info.audacious.thread_attr, audacious_thread_func, NULL))
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
@ -91,15 +90,18 @@ int destroy_audacious_thread(void)
|
|||||||
|
|
||||||
/* Signal audacious thread to terminate */
|
/* Signal audacious thread to terminate */
|
||||||
pthread_mutex_lock (&info.audacious.runnable_mutex);
|
pthread_mutex_lock (&info.audacious.runnable_mutex);
|
||||||
info.audacious.runnable=0;
|
pthread_cond_signal (&info.audacious.runnable_cond);
|
||||||
pthread_mutex_unlock (&info.audacious.runnable_mutex);
|
pthread_mutex_unlock (&info.audacious.runnable_mutex);
|
||||||
|
|
||||||
/* Destroy thread attribute and wait for thread */
|
/* Destroy thread attribute and wait for thread */
|
||||||
pthread_attr_destroy(&info.audacious.thread_attr);
|
pthread_attr_destroy(&info.audacious.thread_attr);
|
||||||
if (pthread_join(info.audacious.thread, NULL))
|
if (pthread_join(info.audacious.thread, NULL))
|
||||||
return(-1);
|
return(-1);
|
||||||
/* Destroy mutexes */
|
|
||||||
|
/* Destroy mutexes and cond */
|
||||||
pthread_mutex_destroy(&info.audacious.item_mutex);
|
pthread_mutex_destroy(&info.audacious.item_mutex);
|
||||||
pthread_mutex_destroy(&info.audacious.runnable_mutex);
|
pthread_mutex_destroy(&info.audacious.runnable_mutex);
|
||||||
|
pthread_cond_destroy(&info.audacious.runnable_cond);
|
||||||
|
|
||||||
info.audacious.thread=(pthread_t)0;
|
info.audacious.thread=(pthread_t)0;
|
||||||
return 0;
|
return 0;
|
||||||
@ -110,22 +112,18 @@ int destroy_audacious_thread(void)
|
|||||||
* --------------------------------------------------- */
|
* --------------------------------------------------- */
|
||||||
void *audacious_thread_func(void *pvoid)
|
void *audacious_thread_func(void *pvoid)
|
||||||
{
|
{
|
||||||
int runnable;
|
int runnable=1;
|
||||||
static audacious_t items;
|
static audacious_t items;
|
||||||
gint session,playpos,frames,length;
|
gint session,playpos,frames,length;
|
||||||
gint rate,freq,chans;
|
gint rate,freq,chans;
|
||||||
gchar *psong,*pfilename;
|
gchar *psong,*pfilename;
|
||||||
|
struct timespec abstime;
|
||||||
|
|
||||||
pvoid=(void *)pvoid; /* avoid warning */
|
pvoid=(void *)pvoid; /* avoid warning */
|
||||||
session=0;
|
session=0;
|
||||||
psong=NULL;
|
psong=NULL;
|
||||||
pfilename=NULL;
|
pfilename=NULL;
|
||||||
|
|
||||||
/* Grab the runnable signal. Should be non-zero here or we do nothing. */
|
|
||||||
pthread_mutex_lock(&info.audacious.runnable_mutex);
|
|
||||||
runnable=info.audacious.runnable;
|
|
||||||
pthread_mutex_unlock(&info.audacious.runnable_mutex );
|
|
||||||
|
|
||||||
/* Loop until the main thread sets the runnable signal to 0. */
|
/* Loop until the main thread sets the runnable signal to 0. */
|
||||||
while(runnable) {
|
while(runnable) {
|
||||||
|
|
||||||
@ -207,12 +205,19 @@ void *audacious_thread_func(void *pvoid)
|
|||||||
memcpy(&audacious_items,items,sizeof(items));
|
memcpy(&audacious_items,items,sizeof(items));
|
||||||
pthread_mutex_unlock(&info.audacious.item_mutex);
|
pthread_mutex_unlock(&info.audacious.item_mutex);
|
||||||
|
|
||||||
/* Grab the runnable signal for next loop. */
|
/* Get absolute time 1 sec in the future. */
|
||||||
pthread_mutex_lock(&info.audacious.runnable_mutex);
|
clock_gettime (CLOCK_REALTIME, &abstime);
|
||||||
runnable=info.audacious.runnable;
|
abstime.tv_sec += 1;
|
||||||
pthread_mutex_unlock(&info.audacious.runnable_mutex);
|
|
||||||
|
/* Wait for a second before looping or until signalled to stop. */
|
||||||
|
if (pthread_cond_timedwait (&info.audacious.runnable_cond,
|
||||||
|
&info.audacious.runnable_mutex,
|
||||||
|
&abstime) != ETIMEDOUT)
|
||||||
|
{
|
||||||
|
runnable=0;
|
||||||
|
(void) pthread_mutex_unlock (&info.audacious.runnable_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
sleep(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
|
@ -172,11 +172,11 @@ struct xmms2_s {
|
|||||||
#ifdef AUDACIOUS
|
#ifdef AUDACIOUS
|
||||||
struct audacious_s {
|
struct audacious_s {
|
||||||
audacious_t items; /* e.g. items[AUDACIOUS_STATUS] */
|
audacious_t items; /* e.g. items[AUDACIOUS_STATUS] */
|
||||||
int runnable; /* used to signal worker thread to stop */
|
|
||||||
pthread_t thread; /* worker thread */
|
pthread_t thread; /* worker thread */
|
||||||
pthread_attr_t thread_attr; /* thread attributes */
|
pthread_attr_t thread_attr; /* thread attributes */
|
||||||
pthread_mutex_t item_mutex; /* mutex for item array */
|
pthread_mutex_t item_mutex; /* mutex for item array */
|
||||||
pthread_mutex_t runnable_mutex; /* mutex for runnable flag */
|
pthread_mutex_t runnable_mutex; /* mutex for runnable */
|
||||||
|
pthread_cond_t runnable_cond; /* cond for runnable */
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user