コード例 #1
0
ファイル: rwlock.c プロジェクト: 01org/android-bluez-glib
static void
test_rwlock3 (void)
{
  static GRWLock lock;
  gboolean ret;

  ret = g_rw_lock_writer_trylock (&lock);
  g_assert (ret);
  ret = g_rw_lock_writer_trylock (&lock);
  g_assert (!ret);

  g_rw_lock_writer_unlock (&lock);
}
コード例 #2
0
ファイル: rwlock.c プロジェクト: 01org/android-bluez-glib
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]);
}
コード例 #3
0
ファイル: fu-mutex.c プロジェクト: vathpela/fwupd
void
fu_mutex_lock_dbg (FuMutex *self, FuMutexAccess kind, const gchar *strloc, const gchar *strfunc)
{
	g_debug ("LOCK  \t%s\t%s\t%s\t%s",
		 self->id,
		 kind == FU_MUTEX_ACCESS_READ ? "READ" : "WRITE",
		 strloc,
		 strfunc);
	if (kind == FU_MUTEX_ACCESS_READ) {
		if (!g_rw_lock_reader_trylock (&self->rw_lock)) {
			g_debug ("failed to read lock, write lock held by %s",
				 self->writer->str);
		}
		g_string_printf (self->reader, "%s:%s", strloc, strfunc);
	} else {
		if (!g_rw_lock_writer_trylock (&self->rw_lock)) {
			g_debug ("failed to write lock, read lock held by %s, "
				 "write lock held by %s",
				 self->reader->str, self->writer->str);
		}
		g_string_printf (self->writer, "%s:%s", strloc, strfunc);
	}
}