mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 07:00:53 +00:00
Simplify this file a bit, and make it not rely on atomic pointer writes.
2006-07-30 Soren Sandmann <sandmann@redhat.com> * signal-handler.c: Simplify this file a bit, and make it not rely on atomic pointer writes.
This commit is contained in:
committed by
Søren Sandmann Pedersen
parent
144e440ff2
commit
5efd06051c
@ -1,3 +1,8 @@
|
|||||||
|
2006-07-30 Soren Sandmann <sandmann@redhat.com>
|
||||||
|
|
||||||
|
* signal-handler.c: Simplify this file a bit, and make it not rely
|
||||||
|
on atomic pointer writes.
|
||||||
|
|
||||||
2006-07-18 Bastien Nocera <hadess@hadess.net>
|
2006-07-18 Bastien Nocera <hadess@hadess.net>
|
||||||
|
|
||||||
* configure.ac: we need at least glib 2.6.0 for the gstdio.h functions
|
* configure.ac: we need at least glib 2.6.0 for the gstdio.h functions
|
||||||
|
|||||||
@ -402,7 +402,7 @@ profile_list_callers (Profile *profile,
|
|||||||
GHashTable *all_ancestors;
|
GHashTable *all_ancestors;
|
||||||
GList *all, *list;
|
GList *all, *list;
|
||||||
|
|
||||||
/* Build a list of those ancestor that should get assigned
|
/* Build a list of those ancestors that should get assigned
|
||||||
* totals. If this callee does not have any recursive calls
|
* totals. If this callee does not have any recursive calls
|
||||||
* higher up, that means all of it's ancestors. If it does
|
* higher up, that means all of it's ancestors. If it does
|
||||||
* have a recursive call, only the one between this node
|
* have a recursive call, only the one between this node
|
||||||
|
|||||||
102
signal-handler.c
102
signal-handler.c
@ -31,14 +31,14 @@ struct SignalWatch
|
|||||||
SignalFunc handler;
|
SignalFunc handler;
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
|
|
||||||
int read_end;
|
|
||||||
int write_end;
|
|
||||||
struct sigaction old_action;
|
struct sigaction old_action;
|
||||||
|
|
||||||
SignalWatch * next;
|
SignalWatch * next;
|
||||||
};
|
};
|
||||||
|
|
||||||
static SignalWatch *signal_watches;
|
static int read_end = -1;
|
||||||
|
static int write_end = -1;
|
||||||
|
static SignalWatch *signal_watches = NULL;
|
||||||
|
|
||||||
static SignalWatch *
|
static SignalWatch *
|
||||||
lookup_signal_watch (int signo)
|
lookup_signal_watch (int signo)
|
||||||
@ -54,45 +54,27 @@ lookup_signal_watch (int signo)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* These two functions might be interrupted by a signal handler that is
|
|
||||||
* going to run lookup_signal_watch(). Assuming that pointer writes are
|
|
||||||
* atomic, the code below should be ok.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
add_signal_watch (SignalWatch *watch)
|
|
||||||
{
|
|
||||||
g_return_if_fail (lookup_signal_watch (watch->signo) == NULL);
|
|
||||||
|
|
||||||
watch->next = signal_watches;
|
|
||||||
signal_watches = watch;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
remove_signal_watch (SignalWatch *watch)
|
remove_signal_watch (SignalWatch *watch)
|
||||||
{
|
{
|
||||||
|
SignalWatch *prev, *w;
|
||||||
|
|
||||||
g_return_if_fail (watch != NULL);
|
g_return_if_fail (watch != NULL);
|
||||||
|
|
||||||
/* It's either the first one in the list, or it is the ->next
|
prev = NULL;
|
||||||
* for some other watch
|
for (w = signal_watches; w != NULL; w = w->next)
|
||||||
*/
|
|
||||||
if (watch == signal_watches)
|
|
||||||
{
|
{
|
||||||
signal_watches = watch->next;
|
if (w == watch)
|
||||||
watch->next = NULL;
|
{
|
||||||
}
|
if (prev)
|
||||||
else
|
prev->next = w->next;
|
||||||
{
|
else
|
||||||
SignalWatch *w;
|
signal_watches = w->next;
|
||||||
|
|
||||||
for (w = signal_watches; w && w->next; w = w->next)
|
break;
|
||||||
{
|
}
|
||||||
if (watch == w->next)
|
|
||||||
{
|
prev = w;
|
||||||
w->next = w->next->next;
|
|
||||||
watch->next = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,25 +83,25 @@ signal_handler (int signo,
|
|||||||
siginfo_t *info,
|
siginfo_t *info,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
SignalWatch *watch;
|
/* FIXME: I suppose we should handle short
|
||||||
char x = 'x';
|
* and non-successful writes ...
|
||||||
|
*/
|
||||||
watch = lookup_signal_watch (signo);
|
write (write_end, &signo, sizeof (int));
|
||||||
write (watch->write_end, &x, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_read (gpointer data)
|
on_read (gpointer data)
|
||||||
{
|
{
|
||||||
SignalWatch *watch = data;
|
SignalWatch *watch;
|
||||||
char x;
|
int signo;
|
||||||
|
|
||||||
read (watch->read_end, &x, 1);
|
/* FIXME: handle short read I suppose */
|
||||||
|
read (read_end, &signo, sizeof (int));
|
||||||
|
|
||||||
/* This is a callback to the application, so things like
|
watch = lookup_signal_watch (signo);
|
||||||
* signal_unset_handler() can be called here.
|
|
||||||
*/
|
if (watch)
|
||||||
watch->handler (watch->signo, watch->user_data);
|
watch->handler (signo, watch->user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -135,6 +117,7 @@ create_pipe (int *read_end,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* FIXME: We should probably make the fd's non-blocking */
|
||||||
if (read_end)
|
if (read_end)
|
||||||
*read_end = p[0];
|
*read_end = p[0];
|
||||||
|
|
||||||
@ -169,11 +152,6 @@ install_signal_handler (int signo,
|
|||||||
static void
|
static void
|
||||||
signal_watch_free (SignalWatch *watch)
|
signal_watch_free (SignalWatch *watch)
|
||||||
{
|
{
|
||||||
fd_remove_watch (watch->read_end);
|
|
||||||
|
|
||||||
close (watch->write_end);
|
|
||||||
close (watch->read_end);
|
|
||||||
|
|
||||||
remove_signal_watch (watch);
|
remove_signal_watch (watch);
|
||||||
|
|
||||||
g_free (watch);
|
g_free (watch);
|
||||||
@ -186,25 +164,25 @@ signal_set_handler (int signo,
|
|||||||
GError **err)
|
GError **err)
|
||||||
{
|
{
|
||||||
SignalWatch *watch;
|
SignalWatch *watch;
|
||||||
int read_end, write_end;
|
|
||||||
|
|
||||||
g_return_val_if_fail (lookup_signal_watch (signo) == NULL, FALSE);
|
g_return_val_if_fail (lookup_signal_watch (signo) == NULL, FALSE);
|
||||||
|
|
||||||
if (!create_pipe (&read_end, &write_end, err))
|
if (read_end == -1)
|
||||||
return FALSE;
|
{
|
||||||
|
if (!create_pipe (&read_end, &write_end, err))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
fd_add_watch (read_end, NULL);
|
||||||
|
fd_set_read_callback (read_end, on_read);
|
||||||
|
}
|
||||||
|
|
||||||
watch = g_new0 (SignalWatch, 1);
|
watch = g_new0 (SignalWatch, 1);
|
||||||
|
|
||||||
watch->signo = signo;
|
watch->signo = signo;
|
||||||
watch->handler = handler;
|
watch->handler = handler;
|
||||||
watch->user_data = data;
|
watch->user_data = data;
|
||||||
watch->read_end = read_end;
|
watch->next = signal_watches;
|
||||||
watch->write_end = write_end;
|
signal_watches = watch;
|
||||||
|
|
||||||
fd_add_watch (watch->read_end, watch);
|
|
||||||
fd_set_read_callback (watch->read_end, on_read);
|
|
||||||
|
|
||||||
add_signal_watch (watch);
|
|
||||||
|
|
||||||
if (!install_signal_handler (signo, &watch->old_action, err))
|
if (!install_signal_handler (signo, &watch->old_action, err))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user