idle: migrate from pthread to glib threads
This commit is contained in:
27
src/idle.c
27
src/idle.c
@@ -25,10 +25,10 @@
|
|||||||
#include "main_notify.h"
|
#include "main_notify.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <pthread.h>
|
#include <glib.h>
|
||||||
|
|
||||||
static unsigned idle_flags;
|
static unsigned idle_flags;
|
||||||
static pthread_mutex_t idle_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static GMutex *idle_mutex = NULL;
|
||||||
|
|
||||||
static const char *const idle_names[] = {
|
static const char *const idle_names[] = {
|
||||||
"database",
|
"database",
|
||||||
@@ -42,14 +42,29 @@ static const char *const idle_names[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
idle_init(void)
|
||||||
|
{
|
||||||
|
g_assert(idle_mutex == NULL);
|
||||||
|
idle_mutex = g_mutex_new();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
idle_deinit(void)
|
||||||
|
{
|
||||||
|
g_assert(idle_mutex != NULL);
|
||||||
|
g_mutex_free(idle_mutex);
|
||||||
|
idle_mutex = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
idle_add(unsigned flags)
|
idle_add(unsigned flags)
|
||||||
{
|
{
|
||||||
assert(flags != 0);
|
assert(flags != 0);
|
||||||
|
|
||||||
pthread_mutex_lock(&idle_mutex);
|
g_mutex_lock(idle_mutex);
|
||||||
idle_flags |= flags;
|
idle_flags |= flags;
|
||||||
pthread_mutex_unlock(&idle_mutex);
|
g_mutex_unlock(idle_mutex);
|
||||||
|
|
||||||
wakeup_main_task();
|
wakeup_main_task();
|
||||||
}
|
}
|
||||||
@@ -59,10 +74,10 @@ idle_get(void)
|
|||||||
{
|
{
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
|
|
||||||
pthread_mutex_lock(&idle_mutex);
|
g_mutex_lock(idle_mutex);
|
||||||
flags = idle_flags;
|
flags = idle_flags;
|
||||||
idle_flags = 0;
|
idle_flags = 0;
|
||||||
pthread_mutex_unlock(&idle_mutex);
|
g_mutex_unlock(idle_mutex);
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
12
src/idle.h
12
src/idle.h
@@ -48,6 +48,18 @@ enum {
|
|||||||
IDLE_OPTIONS = 0x40,
|
IDLE_OPTIONS = 0x40,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the mutex
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
idle_init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the mutex
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
idle_deinit(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds idle flag (with bitwise "or") and queues notifications to all
|
* Adds idle flag (with bitwise "or") and queues notifications to all
|
||||||
* clients.
|
* clients.
|
||||||
|
@@ -268,6 +268,7 @@ int main(int argc, char *argv[])
|
|||||||
/* enable GLib's thread safety code */
|
/* enable GLib's thread safety code */
|
||||||
g_thread_init(NULL);
|
g_thread_init(NULL);
|
||||||
|
|
||||||
|
idle_init();
|
||||||
initConf();
|
initConf();
|
||||||
|
|
||||||
parseOptions(argc, argv, &options);
|
parseOptions(argc, argv, &options);
|
||||||
@@ -382,6 +383,7 @@ int main(int argc, char *argv[])
|
|||||||
music_pipe_free();
|
music_pipe_free();
|
||||||
cleanUpPidFile();
|
cleanUpPidFile();
|
||||||
finishConf();
|
finishConf();
|
||||||
|
idle_deinit();
|
||||||
|
|
||||||
close_log_files();
|
close_log_files();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
Reference in New Issue
Block a user