Exemple #1
1
int
main (int    argc,
      char **argv)
{
  GThread *thread1, *thread2;
  GClosure *closure;
  GTest *object;
  guint i;

  g_thread_init (NULL);
  g_print ("START: %s\n", argv[0]);
  g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
  g_type_init ();

  object = g_object_new (G_TYPE_TEST, NULL);
  closure = g_cclosure_new (G_CALLBACK (test_signal_handler), TEST_POINTER2, destroy_data);

  g_signal_connect_closure (object, "test-signal1", closure, FALSE);
  g_signal_connect_closure (object, "test-signal2", closure, FALSE);

  stopping = FALSE;

  thread1 = g_thread_create (thread1_main, closure, TRUE, NULL);
  thread2 = g_thread_create (thread2_main, closure, TRUE, NULL);

  for (i = 0; i < 1000000; i++)
    {
      static guint count = 0;
      test_emissions (object);
      if (++count % 10000 == 0)
        {
          g_printerr (".\n");
          g_thread_yield(); /* force context switch */
        }
    }

  stopping = TRUE;
  g_print ("\nstopping\n");

  /* wait for thread shutdown */
  g_thread_join (thread1);
  g_thread_join (thread2);

  /* finalize object, destroy signals, run cleanup code */
  g_object_unref (object);

  g_print ("stopped\n");

  g_assert (seen_thread1 != FALSE);
  g_assert (seen_thread2 != FALSE);
  g_assert (seen_test_int1 != FALSE);
  g_assert (seen_test_int2 != FALSE);
  g_assert (seen_signal_handler != FALSE);
  g_assert (seen_cleanup != FALSE);

  return 0;
}
Exemple #2
0
static void
acquire (gint nr)
{
  GThread *self;

  self = g_thread_self ();

  if (!g_rw_lock_writer_trylock (&locks[nr]))
    {
      if (g_test_verbose ())
        g_print ("thread %p going to block on lock %d\n", self, nr);

      g_rw_lock_writer_lock (&locks[nr]);
    }

  g_assert (owners[nr] == NULL);   /* hopefully nobody else is here */
  owners[nr] = self;

  /* let some other threads try to ruin our day */
  g_thread_yield ();
  g_thread_yield ();
  g_thread_yield ();

  g_assert (owners[nr] == self);   /* hopefully this is still us... */
  owners[nr] = NULL;               /* make way for the next guy */

  g_rw_lock_writer_unlock (&locks[nr]);
}
Exemple #3
0
/*
 * Test 2:
 */
static gpointer
test2_th (GdaConnection *cnc)
{
	/* setup main context */
	guint counter = 0;
	setup_main_context (cnc, 10, &counter);
#define LOCK_DELAY 50000
	gda_lockable_lock (GDA_LOCKABLE (cnc));
	/*g_print ("Locked by %p\n", g_thread_self());*/
	g_usleep (LOCK_DELAY);
	gda_lockable_unlock (GDA_LOCKABLE (cnc));
	g_thread_yield ();

	gda_lockable_lock (GDA_LOCKABLE (cnc));
	/*g_print ("Locked by %p\n", g_thread_self());*/
	g_usleep (LOCK_DELAY);
	gda_lockable_unlock (GDA_LOCKABLE (cnc));
	g_thread_yield ();

	gda_lockable_lock (GDA_LOCKABLE (cnc));
	/*g_print ("Locked by %p\n", g_thread_self());*/
	g_usleep (LOCK_DELAY);
	gda_lockable_unlock (GDA_LOCKABLE (cnc));
	g_thread_yield ();

	gda_lockable_lock (GDA_LOCKABLE (cnc));
	/*g_print ("Locked by %p\n", g_thread_self());*/
	g_usleep (LOCK_DELAY);
	gda_lockable_unlock (GDA_LOCKABLE (cnc));

	guint *ret;
	ret = g_new (guint, 1);
	*ret = counter;
	return ret;
}
Exemple #4
0
void glibcurl_cleanup() {
  D((stderr, "glibcurl_cleanup\n"));
  /* You must call curl_multi_remove_handle() and curl_easy_cleanup() for all
     requests before calling this. */
/*   assert(curlSrc->callPerform == 0); */

  /* All easy handles must be finished */

  /* Lock before accessing selectRunning/selectThread */
  g_mutex_lock(curlSrc->mutex);
  curlSrc->selectRunning = FALSE;
  while (curlSrc->selectThread != NULL) {
    g_mutex_unlock(curlSrc->mutex);
    g_thread_yield();
    g_cond_signal(curlSrc->cond); /* Make the select thread shut down */
    g_thread_yield();
    g_mutex_lock(curlSrc->mutex); /* Wait until it has shut down */
  }
  g_mutex_unlock(curlSrc->mutex);

  assert(curlSrc->selectThread == NULL);

  g_cond_free(curlSrc->cond);
  g_mutex_free(curlSrc->mutex);

  curl_multi_cleanup(curlSrc->multiHandle);
  curlSrc->multiHandle = 0;
  curl_global_cleanup();

  g_source_unref(&curlSrc->source);
  curlSrc = 0;
}
static gpointer
run_thread (GTest * test)
{
    gint i = 1;

#ifndef SYMBIAN
    while (!stopping)
    {
        if (TESTNUM == 1)
            g_test_do_signal1 (test);
        if (TESTNUM == 2)
            g_test_do_signal2 (test);
        if (TESTNUM == 3)
            g_test_do_prop (test);
        if ((i++ % 10000) == 0) {
            g_print (".");
            g_thread_yield();  /*force context switch */
        }
    }
#else

#ifdef MULTITHREAD
    while (!stopping)
    {
        if (TESTNUM == 1)
            g_test_do_signal1 (test);
        if (TESTNUM == 2)
            g_test_do_signal2 (test);
        if (TESTNUM == 3)
            g_test_do_prop (test);
        if ((i++ % 10/*000*/) == 0)
        {
#ifdef VERBOSE
            g_print (".");
#endif  /*VERBOSE*/
            g_thread_yield(); /* force context switch */
        }
    }
#else
    for(i=0; i <= LOOP; i++)
    {
        if (TESTNUM == 1)
            g_test_do_signal1 (test);
        if (TESTNUM == 2)
            g_test_do_signal2 (test);
        if (TESTNUM == 3)
            g_test_do_prop (test);

#ifdef 	VERBOSE
        g_print(".");
#endif
    }
#endif /*MULTITHREAD*/

#endif /*SYMBIAN*/

    return NULL;
}
Exemple #6
0
static void
iris_scheduler_iterate_real (IrisScheduler *scheduler) {
	/* No-op, this is only used by IrisGMainScheduler, but since this function
	 * is to be called while waiting for the scheduler to process something a
	 * yield won't go amiss. */
	g_thread_yield ();
}
Exemple #7
0
static void
release_thread (gpointer data,
                gpointer user_data)
{
	IrisThread    *thread = data;
	IrisScheduler *scheduler = IRIS_SCHEDULER (user_data);
	IrisQueue     *work_queue;

	g_mutex_lock (thread->mutex);

	/* thread->active could == NULL if the thread has been added but not yet
	 * started work */
	work_queue = thread->user_data;

	/* If the thread has stopped working for us it should have called
	 * iris_scheduler_remove_thread() already
	 */
	g_warn_if_fail (g_atomic_pointer_get (&thread->scheduler) == scheduler);

	iris_queue_close (work_queue);

	g_mutex_unlock (thread->mutex);

	/* Wait for the thread to recognise its removal, to avoid it accessing
	 * freed memory.
	 */
	while (g_atomic_pointer_get (&thread->scheduler) != NULL) {
		g_warn_if_fail (iris_queue_is_closed (work_queue));

		g_thread_yield ();
	}

	g_object_unref (work_queue);
}
Exemple #8
0
static int static_CallAndWait(int(*callback)(H3270 *session, void *), H3270 *session, void *parm)
{
	struct bgParameter p = { TRUE, session, -1, callback, parm };
	GThread	*thread;

	Trace("Starting auxiliary thread for callback %p",callback);

	p.running = TRUE;
    thread = g_thread_create( (GThreadFunc) BgCall, &p, 0, NULL);

    if(!thread)
    {
    	g_error("Can't start background thread");
    	return -1;
    }

	if(topwindow)
	{
		time_t start = ((time_t) -1);

		if(oia_timer < 0)
			start = time(0);

#ifdef MOUSE_POINTER_CHANGE
		if(terminal && terminal->window)
			gdk_window_set_cursor(terminal->window,wCursor[CURSOR_MODE_WAITING]);
#endif

		while(p.running && topwindow)
		{
			if(start != ((time_t) -1))
				oia_set_timer((long) (time(0)) - start);
			gtk_main_iteration();
		}

		if(start != ((time_t) -1))
			oia_set_timer(-1);

#ifdef MOUSE_POINTER_CHANGE
		if(terminal && terminal->window && drag_type == DRAG_TYPE_NONE && cursor_mode != -1)
			gdk_window_set_cursor(terminal->window,wCursor[cursor_mode]);
#endif

	}

	if(p.running)
	{
		Log("Waiting for background thread %p",thread);

		while(p.running)
			g_thread_yield();

		Log("Thread %p ends",thread);
	}

	Trace("Auxiliary thread for callback %p finished (rc=%d)",callback,p.rc);

    return p.rc;
}
Exemple #9
0
static void
toggle_passthrough (gpointer data, gpointer user_data)
{
  GstBaseTransform *basetrans = GST_BASE_TRANSFORM (user_data);

  gst_base_transform_set_passthrough (basetrans, TRUE);
  g_thread_yield ();
  gst_base_transform_set_passthrough (basetrans, FALSE);
}
Exemple #10
0
static void
acquire (int nr)
{
  GThread *self;

  self = g_thread_self ();

  g_bit_lock (&locks[nr], bits[nr]);
  g_assert (owners[nr] == NULL);   /* hopefully nobody else is here */
  owners[nr] = self;

  /* let some other threads try to ruin our day */
  g_thread_yield ();
  g_thread_yield ();
  g_thread_yield ();

  g_assert (owners[nr] == self);   /* hopefully this is still us... */
  owners[nr] = NULL;               /* make way for the next guy */
  g_bit_unlock (&locks[nr], bits[nr]);
}
static gpointer sync_thread_func(gpointer data)
{
    EeeAccountsManager *mgr = data;
    int i;

    g_return_val_if_fail(IS_EEE_ACCOUNTS_MANAGER(mgr), NULL);

    while (TRUE)
    {
loop:
        switch (g_atomic_int_get(&mgr->priv->sync_request))
        {
        case SYNC_REQ_PAUSE:
            g_usleep(1000000);
            g_thread_yield();
            break;

        case SYNC_REQ_START:
            g_usleep(5000000);
            g_atomic_int_set(&mgr->priv->sync_request, SYNC_REQ_RESTART);
            break;

        case SYNC_REQ_RUN:
            for (i = 0; i < 30; i++)
            {
                g_usleep(1000000);
                if (g_atomic_int_get(&mgr->priv->sync_request) != SYNC_REQ_RUN)
                {
                    goto loop;
                }
            }

        case SYNC_REQ_RESTART:
            g_atomic_int_set(&mgr->priv->sync_request, SYNC_REQ_RUN);
            run_idle(sync_starter, mgr);
            if (g_atomic_int_get(&mgr->priv->sync_request) != SYNC_REQ_RUN)
            {
                break;
            }
            eee_accounts_manager_sync_phase1(mgr);
            if (g_atomic_int_get(&mgr->priv->sync_request) != SYNC_REQ_RUN)
            {
                break;
            }
            run_idle(sync_completer, mgr);
            break;

        case SYNC_REQ_STOP:
            return NULL;
        }
    }

    return NULL;
}
gpointer
skype_read_thread(gpointer data)
{
	while(connected || in_progress)
	{
		read_function_cb(data, source_sock, PURPLE_INPUT_READ);
		g_thread_yield();
		sleep(1);
	}
	return data;
}
Exemple #13
0
static int
core_yield (lua_State *L)
{
  /* Perform yield with unlocked mutex; this might force another
     threads waiting on the mutex to perform what they need to do
     (i.e. enter Lua with callbacks). */
  gpointer state_lock = lgi_state_get_lock (L);
  lgi_state_leave (state_lock);
  g_thread_yield ();
  lgi_state_enter (state_lock);
  return 0;
}
Exemple #14
0
static void
call_counter_init (gpointer tclass)
{
    int i;
    for (i = 0; i < NUM_COUNTER_INCREMENTS; i++)
    {
        int saved_unsafe_call_counter = unsafe_call_counter;
        g_atomic_int_add (&mtsafe_call_counter, 1); /* real call count update */
        g_thread_yield(); /* let concurrent threads corrupt the unsafe_call_counter state */
        unsafe_call_counter = 1 + saved_unsafe_call_counter; /* non-atomic counter update */
    }
}
Exemple #15
0
int
main (int   argc,
      char *argv[])
{
  GThread *threads[N_THREADS];
  int i;
  void *p;
    #ifdef __SYMBIAN32__
  g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
  g_set_print_handler(mrtPrintHandler);
  #endif /*__SYMBIAN32__*/

  /* test simple initializer */
  initializer1();
  initializer1();
  /* test pointer initializer */
  /*void */p = initializer2();
  g_assert (p == &dummy_value);
  p = initializer2();
  g_assert (p == &dummy_value);
  /* setup threads */
  g_thread_init (NULL);
  tmutex = g_mutex_new ();
  tcond = g_cond_new ();
  /* start multiple threads for initializer3() */
  g_mutex_lock (tmutex);
  for (i = 0; i < N_THREADS; i++)
    threads[i] = g_thread_create (tmain_call_initializer3, 0, FALSE, NULL);
  g_mutex_unlock (tmutex);
  /* concurrently call initializer3() */
  g_cond_broadcast (tcond);
  /* loop until all threads passed the call to initializer3() */
  while (g_atomic_int_get (&thread_call_count) < i)
    {
      if (rand() % 2)
        g_thread_yield();   /* concurrent shuffling for single core */
      else
        g_usleep (1000);    /* concurrent shuffling for multi core */
      g_cond_broadcast (tcond);
    }
  /* call multiple (unoptimized) initializers from multiple threads */
  g_mutex_lock (tmutex);
  g_atomic_int_set (&thread_call_count, 0);
  for (i = 0; i < N_THREADS; i++)
    g_thread_create (stress_concurrent_initializers, 0, FALSE, NULL);
  g_mutex_unlock (tmutex);
  while (g_atomic_int_get (&thread_call_count) < 256 * 4 * N_THREADS)
    g_usleep (50 * 1000);       /* wait for all 5 threads to complete */
    #if __SYMBIAN32__
  testResultXml("onceinit");
  #endif /* EMULATOR */
  return 0;
}
Exemple #16
0
/** thread 2, set to val using g_atomic_int_set */
void* thread2(void* arg) {
    gint ii = 0;
    gint val=*(gint*)arg;
    GTimer* my_timer = g_timer_new();
    g_thread_yield();
    for (ii=0; ii<max_ctr; ii++) {
	set_old(&atomic_val, 1);
    }
    g_timer_stop(my_timer);
    printf("Thread %d elapsed=%lf\n", val, g_timer_elapsed(my_timer, NULL));
    return(NULL);
}
gpointer icvWindowThreadLoop(){
	while(1){
		g_mutex_lock(window_mutex);
		gtk_main_iteration_do(FALSE);
		g_mutex_unlock(window_mutex);

		// little sleep
		g_usleep(500);

		g_thread_yield();
	}
	return NULL;
}
static gpointer
mh_main_thread( gpointer data )
{
    XfceMailwatchMHMailbox  *mh = XFCE_MAILWATCH_MH_MAILBOX( data );

    while( !g_atomic_pointer_get( &mh->thread ) && g_atomic_int_get( &mh->running ) )
        g_thread_yield();

    if( g_atomic_int_get( &mh->running ) )
        mh_check_mail( mh );

    g_atomic_pointer_set( &mh->thread, NULL );
    return ( NULL );
}
Exemple #19
0
static gpointer usb_thread(gpointer data)
{
	struct sr_context *ctx = data;

	while (ctx->usb_thread_running) {
		g_mutex_lock(&ctx->usb_mutex);
		libusb_wait_for_event(ctx->libusb_ctx, NULL);
		SetEvent(ctx->usb_event);
		g_mutex_unlock(&ctx->usb_mutex);
		g_thread_yield();
	}

	return NULL;
}
static gpointer
mbox_check_mail_thread( gpointer data )
{
    XfceMailwatchMboxMailbox    *mbox = XFCE_MAILWATCH_MBOX_MAILBOX( data );

    while( !g_atomic_pointer_get( &mbox->thread ) && g_atomic_int_get( &mbox->running ) )
        g_thread_yield();

    if( g_atomic_int_get( &mbox->running ) )
        mbox_check_mail( mbox );

    g_atomic_pointer_set( &mbox->thread, NULL );
    return NULL;
}
Exemple #21
0
gpointer x11_event_thread(gpointer data)
{
    GCContext    *context = (GCContext*)data;
    GCX11Context *x11     = &context->X11_context;
    Movie        *movie   =  context->movie_context;

    long event_mask = KeyReleaseMask;

    XSelectInput(x11->display, x11->root_window, event_mask);

    do {
        XEvent event;

        if (XCheckMaskEvent(x11->display, event_mask, &event)) {
            XKeyEvent *keyEvent = (XKeyEvent*)&event;
            g_message("Key pressed: %d", keyEvent->keycode);

            g_mutex_lock(&context->movie_context->tick_lock);

            /*if (keyEvent->keycode == KEYCODE_RIGHT) {
               movie->ease_to_frame = get_frame_offset(context, GO_TO_NEXT_DAY, DAY_OFFSET_NOW); 
               movie->ease_to = TRUE;
               g_cond_broadcast(&context->movie_context->tick_cond);
            } else */
            if (keyEvent->keycode == KEYCODE_LEFT || keyEvent->keycode == KEYCODE_ESC) {
               exit(1);
               //movie->ease_to_frame = get_frame_offset(context, GO_TO_RAND_DAY, DAY_OFFSET_NOW); 
               //movie->ease_to = TRUE;
               //g_cond_broadcast(&context->movie_context->tick_cond);
            } else if (keyEvent->keycode == KEYCODE_UP) {
               movie->ease_to_frame = get_frame_offset(context, GO_TO_NEXT_DAY, DAY_OFFSET_NOW); 
               movie->ease_to = TRUE;
               g_cond_broadcast(&context->movie_context->tick_cond);
            } else if (keyEvent->keycode == KEYCODE_DOWN) {
               movie->ease_to_frame = get_frame_offset(context, GO_TO_PREV_DAY, DAY_OFFSET_NOW); 
               movie->ease_to = TRUE;
               g_cond_broadcast(&context->movie_context->tick_cond);
            }

            g_mutex_unlock(&context->movie_context->tick_lock);
        }

        g_thread_yield();
        delay_usec(10000);

    } while (!context->exit);

    return NULL;
}
static gpointer
maildir_main_thread( gpointer data ) {
    XfceMailwatchMaildirMailbox     *maildir = data;

    DBG( "-->>" );

    while( !g_atomic_pointer_get( &maildir->thread ) && g_atomic_int_get( &maildir->running ) )
        g_thread_yield();

    if( g_atomic_int_get( &maildir->running ) )
        maildir_check_mail( maildir );

    g_atomic_pointer_set( &maildir->thread, NULL );
    return ( NULL );
}
Exemple #23
0
// run as a separate thread
gpointer ti68k_engine(gpointer data)
{
	struct timeb tCurrentTime;
	struct timeb tLastTime;
	unsigned long int iCurrentTime;
	unsigned long int iLastTime; 
	gint res = 0;

    if(params.cpu_rate != -1)
        cpu_instr = params.cpu_rate;

	while (1) 
	{
		// Check engine status
		G_LOCK(running);
		if (!running) {
			G_UNLOCK(running);
			g_thread_yield ();			
			continue;
		}
		G_UNLOCK(running);
		
		ftime(&tLastTime);
      
		// Run emulator core
		res = ti68k_debug_do_instructions(NB_INSTRUCTIONS_PER_LOOP);
		if(res) {  
			// a bkpt has been encountered
			G_LOCK(running);
            running = 0;
			G_UNLOCK(running);

            debugger = res;
		} else { 
			// normal execution
			ftime(&tCurrentTime);
			
			iLastTime    = 1000 * tLastTime.time + tLastTime.millitm;
			iCurrentTime = 1000 * tCurrentTime.time + tCurrentTime.millitm;
			
			if((iCurrentTime - iLastTime) < TIME_LIMIT)
                //if((options.params)->restrict)
				    sleep((TIME_LIMIT - iCurrentTime + iLastTime));
		}
	}

	return GINT_TO_POINTER(0);
}
void*
thread_func (void *arg)
{
  struct ThreadData *td = arg;
  int i;
/*   g_print ("Thread %d starting\n", td->thread_id); */
  for (i = 0; i < N_ALLOCS; i++)
    {
      if (rand() % (N_ALLOCS / 20) == 0)
	g_print ("%c", 'a' - 1 + td->thread_id);

      /* allocate block of random size and randomly fill */
      int   bytes = rand() % MAX_BLOCK_SIZE + 1;
      char *mem = g_slice_alloc (bytes);
      int f;
      for (f = 0; f < bytes; f++)
	mem[f] = rand();

      /* associate block with random thread */
      int t = rand() % N_THREADS;
      g_mutex_lock (&tdata[t].to_free_mutex);
      tdata[t].to_free[tdata[t].n_to_free] = mem;
      tdata[t].bytes_to_free[tdata[t].n_to_free] = bytes;
      tdata[t].n_to_free++;
      g_mutex_unlock (&tdata[t].to_free_mutex);

      /* shuffle thread execution order every once in a while */
      if (rand() % 97 == 0)
        {
          if (rand() % 2)
            g_thread_yield();   /* concurrent shuffling for single core */
          else
            g_usleep (1000);    /* concurrent shuffling for multi core */
        }

      /* free a block associated with this thread */
      g_mutex_lock (&td->to_free_mutex);
      if (td->n_to_free > 0)
	{
	  td->n_to_free--;
	  g_slice_free1 (td->bytes_to_free[td->n_to_free], td->to_free[td->n_to_free]);
	  td->n_freed++;
	}
      g_mutex_unlock (&td->to_free_mutex);
    }

  return NULL;
}
static gpointer
run_thread (GTest * test)
{
  gint i = 1;
  
  while (!stopping) {
    my_test_do_property (test);
    if ((i++ % 10000) == 0)
      {
        g_print (".%c", 'a' + test->id);
        g_thread_yield(); /* force context switch */
      }
  }

  return NULL;
}
static void
mbox_free( XfceMailwatchMailbox *mailbox )
{
    XfceMailwatchMboxMailbox    *mbox = XFCE_MAILWATCH_MBOX_MAILBOX( mailbox );

    mbox_activate( mailbox, FALSE );
    while( g_atomic_pointer_get( &mbox->thread ) )
        g_thread_yield();
    
    g_mutex_free( mbox->settings_mutex );

    if ( mbox->fn ) {
        g_free( mbox->fn );
    }
    g_free( mbox );
}
Exemple #27
0
static PyObject *_viewer_str(PyObject *self, PyObject *args) {
  char *str_source = NULL;
  int str_size;
  if (!PyArg_ParseTuple(args, "es#", "utf-16", &str_source, &str_size)) {
    PyErr_SetString(PyExc_TypeError, "source must be an SVG string or Unicode object.");
    return NULL;
  }

  if (done) {
    GError *error = NULL;
    if (!g_thread_create(thread, NULL, FALSE, &error)) {
      PyErr_Format(PyExc_RuntimeError, "Could not create GDK thread: %s", error->message);
      PyMem_Free(str_source);
      return NULL;
    }
  }

  if (rsvg != NULL) {
    g_object_unref(rsvg);
    rsvg = NULL;
  }

  GError* error = NULL;
  rsvg = rsvg_handle_new_from_data((guint8*)(str_source), (gsize)(str_size), &error);
  if (rsvg == NULL) {
    PyErr_Format(PyExc_RuntimeError, "Couldn't parse SVG: %s", error->message);
    PyMem_Free(str_source);
    return NULL;
  }

  /* wait for the window to appear, and don't wait forever */
  /* if 5 seconds are reached, don't explicitly throw an error, let */
  /* GDK do that if it needs to */
  g_thread_yield();
  time_t start = time(NULL);
  while (!ready) {
    time_t now = time(NULL);
    if (difftime(now, start) > 5) break;
  }

  gdk_threads_enter();
  gtk_widget_queue_draw(drawing_area);
  gdk_threads_leave();

  PyMem_Free(str_source);
  return Py_BuildValue("O", Py_None);
}
static int gstreamer_open_file(struct input_handle* ih, const char* filename) {
  GTimeVal beg, end;

  ih->filename = filename;
  ih->quit_pipeline = TRUE;
  ih->main_loop_quit = FALSE;
  ih->ready = FALSE;
  ih->bin = NULL;
  ih->message_source = NULL;
  ih->gstreamer_loop = g_thread_create((GThreadFunc) gstreamer_loop, ih, TRUE, NULL);

  g_get_current_time(&beg);
  while (!ih->ready) {
    g_thread_yield();
    g_get_current_time(&end);
    if (end.tv_usec + end.tv_sec * G_USEC_PER_SEC
      - beg.tv_usec - beg.tv_sec * G_USEC_PER_SEC > 1 * G_USEC_PER_SEC) {
      break;
    }
  }

  if (!ih->quit_pipeline) {
    if (!query_data(ih)) {
      ih->quit_pipeline = TRUE;
    }
  }

  if (ih->quit_pipeline) {
    if (ih->bin) {
      GstBus *bus = gst_element_get_bus(ih->bin);
      gst_bus_post(bus, gst_message_new_eos(NULL));
      g_object_unref(bus);
    }
    g_thread_join(ih->gstreamer_loop);
    if (ih->message_source) g_source_destroy(ih->message_source);
    if (ih->bin) {
      /* cleanup */
      gst_element_set_state(ih->bin, GST_STATE_NULL);
      g_object_unref(ih->bin);
      ih->bin = NULL;
      g_main_loop_unref(ih->loop);
    }
    return 1;
  } else {
    return 0;
  }
}
Exemple #29
0
static void
load_image (gpointer  data, 
	    gpointer user_data)
{
  gchar *filename = data;
  FILE *file;
  int nbytes;
  char buf[1024];
  size_t bufsize = 1024;
  GdkPixbufLoader *loader;
  GError *error = NULL;
  GThread *self;

  self = g_thread_self ();
  loader = gdk_pixbuf_loader_new ();

  file = fopen (filename, "r");
  g_assert (file);

  if (verbose) g_print ("%p start image %s\n", self, filename);
  while (!feof (file)) 
    {
      nbytes = fread (buf, 1, bufsize, file);
      if (!gdk_pixbuf_loader_write (loader, buf, nbytes, &error)) 
	{
	  g_warning ("Error writing %s to loader: %s", filename, error->message);
	  g_error_free (error);
          error = NULL;
	  break;
	}
      if (verbose) g_print ("%p read %d bytes\n", self, nbytes);

      g_thread_yield ();      
    }

  fclose (file);

  if (verbose) g_print ("%p finish image %s\n", self, filename);

  if (!gdk_pixbuf_loader_close (loader, &error)) 
    {
      g_warning ("Error closing loader for %s: %s", filename, error->message);
      g_error_free (error);
    }

  g_object_unref (loader);
}
Exemple #30
0
static gpointer
thread2_main (gpointer data)
{
  GClosure *closure = data;
  while (!stopping)
    {
      static guint count = 0;
      test_closure (closure);
      if (++count % 10000 == 0)
        {
          g_printerr ("C");
          g_thread_yield(); /* force context switch */
          seen_thread2 = TRUE;
        }
    }
  return NULL;
}