[gimp] app: add gimp-atomic
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add gimp-atomic
- Date: Sun, 13 May 2018 19:21:58 +0000 (UTC)
commit 398474ff58cff1158b0d3cb42c745fed0c935d9d
Author: Ell <ell_se yahoo com>
Date: Sun May 13 14:36:53 2018 -0400
app: add gimp-atomic
... which provides a set of higher-level lock-free atomic
operations.
Currently, the only two operations are
gimp_atomic_slist_push_head() and gimp_atomic_slist_pop_head(),
which atomically push/pop the first element of a GSList.
app/core/Makefile.am | 2 +
app/core/gimp-atomic.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++
app/core/gimp-atomic.h | 32 ++++++++++++++++
3 files changed, 132 insertions(+), 0 deletions(-)
---
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index 8be742d..495ad06 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -39,6 +39,8 @@ libappcore_a_sources = \
core-types.h \
gimp.c \
gimp.h \
+ gimp-atomic.c \
+ gimp-atomic.h \
gimp-batch.c \
gimp-batch.h \
gimp-cairo.c \
diff --git a/app/core/gimp-atomic.c b/app/core/gimp-atomic.c
new file mode 100644
index 0000000..7def570
--- /dev/null
+++ b/app/core/gimp-atomic.c
@@ -0,0 +1,98 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimp-atomic.c
+ * Copyright (C) 2018 Ell
+ *
+ * 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 3 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.
+ *
+ * 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 "config.h"
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
+
+#include "core-types.h"
+
+#include "gimp-atomic.h"
+
+
+/* GSList */
+
+
+static GSList gimp_atomic_slist_sentinel;
+
+
+void
+gimp_atomic_slist_push_head (GSList **list,
+ gpointer data)
+{
+ GSList *old_head;
+ GSList *new_head;
+
+ g_return_if_fail (list != NULL);
+
+ new_head = g_slist_alloc ();
+
+ new_head->data = data;
+
+ do
+ {
+ do
+ {
+ old_head = g_atomic_pointer_get (list);
+ }
+ while (old_head == &gimp_atomic_slist_sentinel);
+
+ new_head->next = old_head;
+ }
+ while (! g_atomic_pointer_compare_and_exchange (list, old_head, new_head));
+}
+
+gpointer
+gimp_atomic_slist_pop_head (GSList **list)
+{
+ GSList *old_head;
+ GSList *new_head = NULL;
+ gpointer data = NULL;
+
+ g_return_val_if_fail (list != NULL, NULL);
+
+ do
+ {
+ do
+ {
+ old_head = g_atomic_pointer_get (list);
+ }
+ while (old_head == &gimp_atomic_slist_sentinel);
+ }
+ while (! g_atomic_pointer_compare_and_exchange (list,
+ old_head,
+ &gimp_atomic_slist_sentinel));
+
+ g_warn_if_fail (old_head != NULL);
+
+ if (old_head)
+ {
+ new_head = old_head->next;
+ data = old_head->data;
+ }
+
+ g_atomic_pointer_set (list, new_head);
+
+ if (old_head)
+ g_slist_free1 (old_head);
+
+ return data;
+}
diff --git a/app/core/gimp-atomic.h b/app/core/gimp-atomic.h
new file mode 100644
index 0000000..fa7306f
--- /dev/null
+++ b/app/core/gimp-atomic.h
@@ -0,0 +1,32 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimp-atomic.h
+ * Copyright (C) 2018 Ell
+ *
+ * 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 3 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_ATOMIC_H__
+#define __GIMP_ATOMIC_H__
+
+
+/* GSList */
+
+void gimp_atomic_slist_push_head (GSList **list,
+ gpointer data);
+gpointer gimp_atomic_slist_pop_head (GSList **list);
+
+
+#endif /* __GIMP_ATOMIC_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]