Debian Codegraph @

tests/test-thread.c

raw
1 #include "test-thread.h"
2
3 enum {
4 /* methods */
5 SIGNAL_EMIT_SIGNAL,
6 SIGNAL_FROM_THREAD,
7 LAST_SIGNAL
8 };
9
10 static guint test_thread_signals[LAST_SIGNAL] = { 0 };
11
12 typedef enum { TEST_THREAD_A, TEST_THREAD_B } ThreadEnumType;
13
14 static GType
15 test_thread_enum_get_type (void)
16 {
17 static GType enum_type = 0;
18 static GEnumValue enum_values[] = {
19 { TEST_THREAD_A, "TEST_THREAD_A", "a as in apple" },
20 { 0, NULL, NULL },
21 };
22
23 if (!enum_type) {
24 enum_type = g_enum_register_static ("TestThreadEnum", enum_values);
25 }
26 return enum_type;
27 }
28
29 G_DEFINE_TYPE (TestThread, test_thread, G_TYPE_OBJECT);
30
31 static G_NORETURN void
32 other_thread_cb (TestThread *self)
33 {
34 g_signal_emit_by_name (self, "from-thread", 0, NULL);
35 g_thread_exit (0);
36 }
37
38 static void
39 test_thread_emit_signal (TestThread *self)
40 {
41 self->thread = g_thread_new ("t", (GThreadFunc)other_thread_cb, self);
42 }
43
44 static void
45 test_thread_init (TestThread *self)
46 {
47 }
48 static void
49 test_thread_class_init (TestThreadClass *klass)
50 {
51 test_thread_signals[SIGNAL_EMIT_SIGNAL] = g_signal_new (
52 "emit-signal", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
53 G_STRUCT_OFFSET (TestThreadClass, emit_signal), NULL, NULL,
54 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
55 test_thread_signals[SIGNAL_FROM_THREAD] = g_signal_new (
56 "from-thread", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
57 G_STRUCT_OFFSET (TestThreadClass, from_thread), NULL, NULL,
58 g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1,
59 test_thread_enum_get_type ());
60
61 klass->emit_signal = test_thread_emit_signal;
62 }