~ubuntu-branches/debian/squeeze/glib2.0/squeeze

« back to all changes in this revision

Viewing changes to gobject/tests/threadtests.c

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-02-15 13:00:43 UTC
  • mfrom: (1.3.1 upstream) (69.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20090215130043-q47fbt3owmt42m2f
Tags: 2.18.4-2
* Release to unstable
* debian/rules:
- bump SHVER, since we are already forcing a 2.18.0 dependecy on the
  symbols introduced in the development versions
* debian/control.in:
- added Homepage and Vcs-* control fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
static void my_tester2_init (MyTester2*t) {}
110
110
static void my_tester2_class_init (MyTester2Class*c) { call_counter_init (c); }
111
111
 
 
112
static GCond *sync_cond = NULL;
112
113
static GMutex *sync_mutex = NULL;
113
114
 
114
115
static gpointer
138
139
{
139
140
  GThread *threads[3] = { NULL, };
140
141
  /* pause newly created threads */
141
 
  sync_mutex = g_mutex_new();
142
142
  g_mutex_lock (sync_mutex);
143
143
  /* create threads */
144
144
  threads[0] = g_thread_create (tester_init_thread, (gpointer) my_tester0_get_type(), TRUE, NULL);
158
158
  g_assert_cmpint (g_atomic_int_get (&mtsafe_call_counter), ==, unsafe_call_counter);
159
159
}
160
160
 
 
161
typedef struct {
 
162
  GObject parent;
 
163
  char   *name;
 
164
} PropTester;
 
165
typedef GObjectClass    PropTesterClass;
 
166
G_DEFINE_TYPE (PropTester, prop_tester, G_TYPE_OBJECT);
 
167
#define PROP_NAME 1
 
168
static void
 
169
prop_tester_init (PropTester* t)
 
170
{
 
171
  if (t->name == NULL)
 
172
    ; // neds unit test framework initialization: g_test_bug ("race initializing properties");
 
173
}
 
174
static void
 
175
prop_tester_set_property (GObject        *object,
 
176
                          guint           property_id,
 
177
                          const GValue   *value,
 
178
                          GParamSpec     *pspec)
 
179
{}
 
180
static void
 
181
prop_tester_class_init (PropTesterClass *c)
 
182
{
 
183
  int i;
 
184
  GParamSpec *param;
 
185
  GObjectClass *gobject_class = G_OBJECT_CLASS (c);
 
186
 
 
187
  gobject_class->set_property = prop_tester_set_property; /* silence GObject checks */
 
188
 
 
189
  g_mutex_lock (sync_mutex);
 
190
  g_cond_signal (sync_cond);
 
191
  g_mutex_unlock (sync_mutex);
 
192
 
 
193
  for (i = 0; i < 100; i++) /* wait a bit. */
 
194
    g_thread_yield();
 
195
 
 
196
  call_counter_init (c);
 
197
  param = g_param_spec_string ("name", "name_i18n",
 
198
                               "yet-more-wasteful-i18n",
 
199
                               NULL,
 
200
                               G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE |
 
201
                               G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB |
 
202
                               G_PARAM_STATIC_NICK);
 
203
  g_object_class_install_property (gobject_class, PROP_NAME, param);
 
204
}
 
205
 
 
206
static gpointer
 
207
object_create (gpointer data)
 
208
{
 
209
  GObject *obj = g_object_new (prop_tester_get_type(), "name", "fish", NULL);
 
210
  g_object_unref (obj);
 
211
  return NULL;
 
212
}
 
213
 
 
214
static void
 
215
test_threaded_object_init (void)
 
216
{
 
217
  GThread *creator;
 
218
  g_mutex_lock (sync_mutex);
 
219
 
 
220
  creator = g_thread_create (object_create, NULL, TRUE, NULL);
 
221
  /* really provoke the race */
 
222
  g_cond_wait (sync_cond, sync_mutex);
 
223
 
 
224
  object_create (NULL);
 
225
  g_mutex_unlock (sync_mutex);
 
226
 
 
227
  g_thread_join (creator);
 
228
}
 
229
 
161
230
int
162
231
main (int   argc,
163
232
      char *argv[])
166
235
  g_test_init (&argc, &argv, NULL);
167
236
  g_type_init ();
168
237
 
 
238
  sync_cond = g_cond_new();
 
239
  sync_mutex = g_mutex_new();
 
240
 
169
241
  g_test_add_func ("/GObject/threaded-class-init", test_threaded_class_init);
 
242
  g_test_add_func ("/GObject/threaded-object-init", test_threaded_object_init);
170
243
 
171
244
  return g_test_run();
172
245
}