From 5e14258a9d30c6d7b88013a0066e208b7ea42291 Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Tue, 11 Nov 2003 21:25:24 +0000 Subject: guard against multiple threads here by using a mutex. also, always remove 2003-11-11 Chris Toshok * src/server.c (queue_termination): guard against multiple threads here by using a mutex. also, always remove the terminal_handler_id if one exists and reinstate it afterward. This gives us the behavior of always lasting EXIT_TIMEOUT milliseconds after the most recent book/calendar shutdown. Before there was a potential for shutting down EXIT_TIMEOUT milliseconds after the *first* book/calendar shutdown. --- src/server.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/server.c b/src/server.c index 1c974f2f9..12a04c62a 100644 --- a/src/server.c +++ b/src/server.c @@ -1,8 +1,23 @@ -/* Server personal information server - main file +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* server.c * - * Author: Nat Friedman + * Copyright (C) 2000-2003, Ximian, Inc. * - * Copyright 2000, Ximian, Inc. + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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. + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Nat Friedman (nat@ximian.com) */ #ifdef HAVE_CONFIG_H @@ -58,6 +73,8 @@ static EDataBookFactory *e_data_book_factory; /* Timeout ID for termination handler */ static guint termination_handler_id; +static GStaticMutex termination_lock = G_STATIC_MUTEX_INIT; + /* Termination */ @@ -82,10 +99,12 @@ termination_handler (gpointer data) static void queue_termination (void) { + g_static_mutex_lock (&termination_lock); if (termination_handler_id) - return; + g_source_remove (termination_handler_id); termination_handler_id = g_timeout_add (EXIT_TIMEOUT, termination_handler, NULL); + g_static_mutex_unlock (&termination_lock); } -- cgit v1.2.1