root/trunk/libtinymailui-gtk/tny-gtk-lockable.c

Revision 3666 (checked in by jdapena, 7 months ago)

* Use GOnce registering all types in tinymail to make

registering thread-safe.

Line 
1 /* libtinymailui-gtk - The Tiny Mail UI library for Gtk+
2  * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with self library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /**
21  * TnyGtkLockable:
22  *
23  * A #TnyLockable that has its tny_lockable_lock() and tny_lockable_ulock()
24  * implemented using gdk_threads_enter() and gdk_threads_leave().
25  *
26  * free-function: g_object_unref
27  **/
28
29 #include <config.h>
30 #include <glib.h>
31 #include <glib/gi18n-lib.h>
32
33 #include <tny-gtk-lockable.h>
34
35 static GObjectClass *parent_class = NULL;
36
37 static void
38 tny_gtk_lockable_lock (TnyLockable *self)
39 {
40         gdk_threads_enter ();
41 }
42
43 static void
44 tny_gtk_lockable_unlock (TnyLockable *self)
45 {
46         gdk_threads_leave ();
47 }
48
49 static void
50 tny_gtk_lockable_finalize (GObject *object)
51 {
52         parent_class->finalize (object);
53 }
54
55 static void
56 tny_lockable_init (TnyLockableIface *klass)
57 {
58         klass->lock= tny_gtk_lockable_lock;
59         klass->unlock= tny_gtk_lockable_unlock;
60 }
61
62 static void
63 tny_gtk_lockable_class_init (TnyGtkLockableClass *klass)
64 {
65         GObjectClass *object_class;
66
67         parent_class = g_type_class_peek_parent (klass);
68         object_class = (GObjectClass*) klass;
69         object_class->finalize = tny_gtk_lockable_finalize;
70 }
71
72 static void
73 tny_gtk_lockable_instance_init (GTypeInstance *instance, gpointer g_class)
74 {
75         return;
76 }
77
78 /**
79  * tny_gtk_lockable_new:
80  *
81  * Create a #TnyLockable that uses gdk_threads_enter() and gdk_threads_leave()
82  * as lock and unlock implementations.
83  *
84  * returns: (caller-owns): a new #TnyLockable
85  * since: 1.0
86  * audience: application-developer
87  **/
88 TnyLockable*
89 tny_gtk_lockable_new (void)
90 {
91         TnyGtkLockable *self = g_object_new (TNY_TYPE_GTK_LOCKABLE, NULL);
92         return TNY_LOCKABLE (self);
93 }
94
95
96 static gpointer
97 tny_gtk_lockable_register_type (gpointer notused)
98 {
99         GType type = 0;
100         static const GTypeInfo info =
101                 {
102                         sizeof (TnyGtkLockableClass),
103                         NULL,   /* base_init */
104                         NULL,   /* base_finalize */
105                         (GClassInitFunc) tny_gtk_lockable_class_init,   /* class_init */
106                         NULL,   /* class_finalize */
107                         NULL,   /* class_data */
108                         sizeof (TnyGtkLockable),
109                         0,      /* n_preallocs */
110                         tny_gtk_lockable_instance_init,    /* instance_init */
111                         NULL
112                 };
113
114
115         static const GInterfaceInfo tny_lockable_info =
116                 {
117                         (GInterfaceInitFunc) tny_lockable_init, /* interface_init */
118                         NULL,         /* interface_finalize */
119                         NULL          /* interface_data */
120                 };
121
122         type = g_type_register_static (G_TYPE_OBJECT,
123                                        "TnyGtkLockable",
124                                        &info, 0);
125
126         g_type_add_interface_static (type, TNY_TYPE_LOCKABLE,
127                                      &tny_lockable_info);
128
129         return GUINT_TO_POINTER (type);
130 }
131
132 GType
133 tny_gtk_lockable_get_type (void)
134 {
135         static GOnce once = G_ONCE_INIT;
136         g_once (&once, tny_gtk_lockable_register_type, NULL);
137         return GPOINTER_TO_UINT (once.retval);
138 }
Note: See TracBrowser for help on using the browser.