summaryrefslogtreecommitdiff
path: root/gtk/schedule.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-05-05 22:28:51 +0100
committerVincent Sanders <vince@kyllikki.org>2016-05-15 13:44:34 +0100
commitd21447d096a320a08b3efb2b8768fad0dcdcfd64 (patch)
tree1a83814b7c9e94b2f13c473261f23dd3a17dee64 /gtk/schedule.c
parent2cbb337756d9af5bda4d594964d446439f602551 (diff)
downloadnetsurf-d21447d096a320a08b3efb2b8768fad0dcdcfd64.tar.gz
netsurf-d21447d096a320a08b3efb2b8768fad0dcdcfd64.tar.bz2
move frontends into sub directory
Diffstat (limited to 'gtk/schedule.c')
-rw-r--r--gtk/schedule.c136
1 files changed, 0 insertions, 136 deletions
diff --git a/gtk/schedule.c b/gtk/schedule.c
deleted file mode 100644
index cf0333388..000000000
--- a/gtk/schedule.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright 2006-2007 Daniel Silverstone <dsilvers@digital-scurf.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf 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; version 2 of the License.
- *
- * NetSurf 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include <glib.h>
-#include <stdlib.h>
-#include <stdbool.h>
-
-#include "utils/errors.h"
-
-#include "gtk/schedule.h"
-
-#ifdef DEBUG_GTK_SCHEDULE
-#include "utils/log.h"
-#else
-#define LOG(format, args...) ((void) 0)
-#endif
-
-/** Killable callback closure embodiment. */
-typedef struct {
- void (*callback)(void *); /**< The callback function. */
- void *context; /**< The context for the callback. */
- bool callback_killed; /**< Whether or not this was killed. */
-} _nsgtk_callback_t;
-
-/** List of callbacks which have occurred and are pending running. */
-static GList *pending_callbacks = NULL;
-/** List of callbacks which are queued to occur in the future. */
-static GList *queued_callbacks = NULL;
-/** List of callbacks which are about to be run in this ::schedule_run. */
-static GList *this_run = NULL;
-
-static gboolean
-nsgtk_schedule_generic_callback(gpointer data)
-{
- _nsgtk_callback_t *cb = (_nsgtk_callback_t *)(data);
- if (cb->callback_killed) {
- /* This callback instance has been killed. */
- LOG("CB at %p already dead.", cb);
- }
- queued_callbacks = g_list_remove(queued_callbacks, cb);
- pending_callbacks = g_list_append(pending_callbacks, cb);
- return FALSE;
-}
-
-static void
-nsgtk_schedule_kill_callback(void *_target, void *_match)
-{
- _nsgtk_callback_t *target = (_nsgtk_callback_t *)_target;
- _nsgtk_callback_t *match = (_nsgtk_callback_t *)_match;
- if ((target->callback == match->callback) &&
- (target->context == match->context)) {
- LOG("Found match for %p(%p), killing.", target->callback, target->context);
- target->callback = NULL;
- target->context = NULL;
- target->callback_killed = true;
- }
-}
-
-static void
-schedule_remove(void (*callback)(void *p), void *p)
-{
- _nsgtk_callback_t cb_match = {
- .callback = callback,
- .context = p,
- };
-
- g_list_foreach(queued_callbacks,
- nsgtk_schedule_kill_callback, &cb_match);
- g_list_foreach(pending_callbacks,
- nsgtk_schedule_kill_callback, &cb_match);
- g_list_foreach(this_run,
- nsgtk_schedule_kill_callback, &cb_match);
-}
-
-/* exported interface documented in gtk/schedule.h */
-nserror nsgtk_schedule(int t, void (*callback)(void *p), void *p)
-{
- _nsgtk_callback_t *cb;
-
- /* Kill any pending schedule of this kind. */
- schedule_remove(callback, p);
-
- if (t < 0) {
- return NSERROR_OK;
- }
-
- cb = malloc(sizeof(_nsgtk_callback_t));
- cb->callback = callback;
- cb->context = p;
- cb->callback_killed = false;
- /* Prepend is faster right now. */
- queued_callbacks = g_list_prepend(queued_callbacks, cb);
- g_timeout_add(t, nsgtk_schedule_generic_callback, cb);
-
- return NSERROR_OK;
-}
-
-bool
-schedule_run(void)
-{
- /* Capture this run of pending callbacks into the list. */
- this_run = pending_callbacks;
-
- if (this_run == NULL)
- return false; /* Nothing to do */
-
- /* Clear the pending list. */
- pending_callbacks = NULL;
-
- LOG("Captured a run of %d callbacks to fire.", g_list_length(this_run));
-
- /* Run all the callbacks which made it this far. */
- while (this_run != NULL) {
- _nsgtk_callback_t *cb = (_nsgtk_callback_t *)(this_run->data);
- this_run = g_list_remove(this_run, this_run->data);
- if (!cb->callback_killed)
- cb->callback(cb->context);
- free(cb);
- }
- return true;
-}