don't mix tabs and spaces
[platform/upstream/gstreamer.git] / gst / gstthreaddummy.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <unistd.h>
21 #include <sys/time.h>
22 #include <glib.h>
23 #include "gstlog.h"
24
25 static GMutex *mutex = NULL;
26 static GCond *cond = NULL;
27
28 static GMutex *
29 gst_mutex_new_dummy_impl (void)
30 {
31   if (!mutex)
32     mutex = g_malloc (8);
33
34   return mutex;
35 }
36
37 static void
38 gst_mutex_dummy_impl (GMutex * mutex)
39 {                               /* NOP */
40 }
41
42 static gboolean
43 gst_mutex_trylock_dummy_impl (GMutex * mutex)
44 {
45   return TRUE;
46 }
47
48 static GCond *
49 gst_cond_new_dummy_impl (void)
50 {
51   if (!cond)
52     cond = g_malloc (8);
53
54   return cond;
55 }
56
57 static void
58 gst_cond_dummy_impl (GCond * cond)
59 {                               /* NOP */
60 }
61
62 static gboolean
63 gst_cond_timed_wait_dummy_impl (GCond * cond, GMutex * mutex,
64     GTimeVal * end_time)
65 {
66   struct timeval tvtarget;
67   GTimeVal tvnow;
68   guint64 now, target;
69   gint64 diff;
70
71   target = end_time->tv_sec * 1000000 + end_time->tv_usec;
72
73   g_get_current_time (&tvnow);
74   now = tvnow.tv_sec * 1000000 + tvnow.tv_usec;
75
76   diff = target - now;
77   if (diff > 1000) {
78     tvtarget.tv_usec = diff % 1000000;
79     tvtarget.tv_sec = diff / 1000000;
80
81     select (0, NULL, NULL, NULL, &tvtarget);
82   }
83
84   return TRUE;
85 }
86
87 static GPrivate *
88 gst_private_new_dummy_impl (GDestroyNotify destructor)
89 {
90   gpointer data;
91
92   data = g_new0 (gpointer, 1);
93
94   return (GPrivate *) data;
95 }
96
97 static gpointer
98 gst_private_get_dummy_impl (GPrivate * private_key)
99 {
100   gpointer *data = (gpointer) private_key;
101
102   return *data;
103 }
104
105 static void
106 gst_private_set_dummy_impl (GPrivate * private_key, gpointer data)
107 {
108   *((gpointer *) private_key) = data;
109 }
110
111 static void
112 gst_thread_create_dummy_impl (GThreadFunc func, gpointer data,
113     gulong stack_size, gboolean joinable, gboolean bound,
114     GThreadPriority priority, gpointer thread, GError ** error)
115 {
116   g_warning ("GStreamer configured to not use threads");
117 }
118
119 static void
120 gst_thread_dummy_impl (void)
121 {                               /* NOP */
122 }
123
124 static void
125 gst_thread_dummy_impl_1 (gpointer thread)
126 {                               /* NOP */
127 }
128
129 static void
130 gst_thread_set_priority_dummy_impl (gpointer thread, GThreadPriority priority)
131 {                               /* NOP */
132 }
133
134 static gboolean
135 gst_thread_equal_dummy_impl (gpointer thread1, gpointer thread2)
136 {
137   return (thread1 == thread2);
138 }
139
140 GThreadFunctions gst_thread_dummy_functions = {
141   gst_mutex_new_dummy_impl,
142   (void (*)(GMutex *)) gst_mutex_dummy_impl,
143   gst_mutex_trylock_dummy_impl,
144   (void (*)(GMutex *)) gst_mutex_dummy_impl,
145   gst_mutex_dummy_impl,
146   gst_cond_new_dummy_impl,
147   (void (*)(GCond *)) gst_cond_dummy_impl,
148   (void (*)(GCond *)) gst_cond_dummy_impl,
149   (void (*)(GCond *, GMutex *)) gst_cond_dummy_impl,
150   gst_cond_timed_wait_dummy_impl,
151   gst_cond_dummy_impl,
152   gst_private_new_dummy_impl,
153   gst_private_get_dummy_impl,
154   gst_private_set_dummy_impl,
155   gst_thread_create_dummy_impl,
156   gst_thread_dummy_impl,
157   gst_thread_dummy_impl_1,
158   gst_thread_dummy_impl,
159   gst_thread_set_priority_dummy_impl,
160   gst_thread_dummy_impl_1, gst_thread_equal_dummy_impl
161 };