notify.c 1.55 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2011 The Music Player Daemon Project
3
 * http://www.musicpd.org
4 5 6 7 8 9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 19
 */

20
#include "config.h"
21 22
#include "notify.h"

23
void notify_init(struct notify *notify)
24
{
25 26
	notify->mutex = g_mutex_new();
	notify->cond = g_cond_new();
27
	notify->pending = false;
28 29
}

30 31
void notify_deinit(struct notify *notify)
{
32 33
	g_mutex_free(notify->mutex);
	g_cond_free(notify->cond);
34 35
}

36
void notify_wait(struct notify *notify)
37
{
38
	g_mutex_lock(notify->mutex);
39
	while (!notify->pending)
40
		g_cond_wait(notify->cond, notify->mutex);
41
	notify->pending = false;
42
	g_mutex_unlock(notify->mutex);
43 44
}

45
void notify_signal(struct notify *notify)
46
{
47
	g_mutex_lock(notify->mutex);
48
	notify->pending = true;
49 50
	g_cond_signal(notify->cond);
	g_mutex_unlock(notify->mutex);
51
}
52 53 54 55 56 57 58

void notify_clear(struct notify *notify)
{
	g_mutex_lock(notify->mutex);
	notify->pending = false;
	g_mutex_unlock(notify->mutex);
}