Recursive locks in Vala and D-Bus service support for Vala interfaces

I have been whining about features that I want in Vala to Jürg. To make up for all the time he lost listening to me I decided to fix two Vala bugs.

The first bug I fixed was using a recursive mutex for lock statements. Code like this will work as expected now:

public class LockMe : GLib.Object { }
public class Executer : GLib.Object {
	LockMe o { get; set; }
	construct { o = new LockMe (); }
	void Internal () {
		lock (o) { }
	}
	public void Method () {
		lock (o) { Internal (); }
	}
}
public class App : GLib.Object {
	static void main (string[] args) {
		Executer e = new Executer ();
		e.Method ();
	}
}

Here’s a gdb session that most GLib programmers will recognize:

Breakpoint 1, 0x08048a87 in executer_Method ()
(gdb) break g_static_rec_mutex_lock
Breakpoint 2 at 0xb7e4d0e6
(gdb) cont
Continuing.
Breakpoint 2, 0xb7e4d0e6 in g_static_rec_mutex_lock ()
   from /usr/lib/libglib-2.0.so.0
(gdb) bt
#0  0xb7e4d0e6 in g_static_rec_mutex_lock () from /usr/lib/libglib-2.0.so.0
#1  0x08048b04 in executer_Method ()
#2  0x08049046 in app_main ()
#3  0x0804908a in main ()
(gdb) cont
Continuing.
Breakpoint 2, 0xb7e4d0e6 in g_static_rec_mutex_lock ()
   from /usr/lib/libglib-2.0.so.0
(gdb) bt
#0  0xb7e4d0e6 in g_static_rec_mutex_lock () from /usr/lib/libglib-2.0.so.0
#1  0x08048a6e in executer_Internal ()
#2  0x08048b0f in executer_Method ()
#3  0x08049046 in app_main ()
#4  0x0804908a in main ()
(gdb) cont
Continuing.
Program exited normally.
(gdb)

The second bug is supporting interfaces for D-Bus services in Vala. It goes like this:

using GLib;
[DBus (name = "org.gnome.TestServer")]
public interface TestServerAPI {
	public abstract int64 ping (string msg);
}
public class TestServer : Object, TestServerAPI {
	int64 counter;
	public int64 ping (string msg) {
		message (msg);
		return counter++;
	}
}
void main () {
	MainLoop loop = new MainLoop (null, false);
	try {
		var conn = DBus.Bus.get (DBus.BusType.SESSION);
		dynamic DBus.Object bus = conn.get_object (
			"org.freedesktop.DBus", "/org/freedesktop/DBus",
			"org.freedesktop.DBus");
		uint request_name_result = bus.RequestName ("org.gnome.TestService", 0);
		if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER) {
			// start server
			var server = new TestServer ();
			conn.register_object ("/org/gnome/test", server);
			loop.run ();
		} else {  // client
			dynamic DBus.Object test_server_object =
				conn.get_object ("org.gnome.TestService",
					"/org/gnome/test", "org.gnome.TestServer");
			int64 pong = test_server_object.ping ("Hello from Vala");
			message (pong.to_string ());
		}
        } catch (Error foo) { }
}

Implementing your Vala interfaces in GObject/C

In Vala you can define interfaces just like in C# and Java. Interfaces imply that you can have class types that implement one or more such interfaces. Vala does not force you to implement its interfaces in Vala. You can also implement them in good-old GObject C.

Here’s a detailed example how you implement a type that implements two Vala interfaces in GObject/C:

Switching to multiple threads, with a non-thread-safe resource

Your application used to be single threaded and is consuming a resource that is not thread-safe. You’re splitting your application up into two or more threads. Both threads want to consume the non-thread-safe resource.

In this GNOME-Live item I explain how to use GThreadPool for this.

It’s a wiki so if you find any discrepancies in the sample and or text, just correct them. I’m subscribed so I’ll review it that way.

The GNOME-Live item is done in a similar way to the item about using asynchronous DBus bindings and the AsyncWorker item.

On the act of subverting the British nation

A few days ago I made a completely correct analysis of how the Schuko standard for power sockets and plugs, used on the continent of Europe, is superior to the British BS1363 standard.

Today I noticed the fruits of our hard work of trying to convert the British people to the fine uses and traditions of the people who live on the European continent. I saw a carton “Gezeefde Tomaten / Purée de Tomates” at a supermarket in Durham UK.

Just like how politics in Belgium work we have started applying the principle of divide and conqueror: instead of using their native language English, we are now sending them products with dual language branding and descriptions. Just like in our own country. This introduces doubt about their English identity. To divide you first need to generate fear and doubt (Am I really English? I’m not Welsh either? Maybe I’m Dutch? Maybe French!! Wouh!). Then you conqueror them by telling them, with a soft voice:

No no, you are Europe.

Works great! Just make them believe those Belgian “Purée de Tomates or Gezeefde Tomaten” are good. Once they grasped that, tell them: “but the tomatoes and the brand itself (Valfrutta) actually comes from Italy”. That’ll completely confuse them! Then relax them by softly putting your hand on their forehead and say: you are European, don’t be afraid child.

ps. Dear people who don’t live in Europe: this post is sarcasm, irony, a joke.

God save the Queen

People living somewhere on the British Islands.

This is a device that produces static electricity

You plug a power plug in a power socket

I have marked on this image of the power plug where the static electricity gets delivered into the power socket

Let me clarify my point:

  • Washing machines produce static electricity
  • Walls and sockets don’t produce static electricity

Let me add another point that I’m trying to make here

  • The dangerous looking pin in European sockets is not dangerous at all

Also note that the Germans and the Dutch use sockets that don’t have the dangerous looking pin. Both types of sockets and both types of plugs are compatible with each other. European continental standardisation is very useful sometimes.

Let’s take a look at the European plug and the location where it delivers the static electricity to the wall socket.

Let’s now compare that with an actual photo of a British Island’s (Irish guys use it too) plug.

My adult male finger (I have very thick fingers compared to Tinne’s skinny fingers and Tinne has thick fingers compared to a small child’s fingers) fitted in the space. It was possible for me to fully touch the static electricity pin. The device was powered on so the two pins for delivering the actual electricity where completely connected.

Now let’s see some actual photos of the European plug in action. Decide for yourself.



The solution is to convert those crazy English, Irish, Northern Irish, Scotts and Welshman (boy, I do hope I didn’t forget anybody) to the European system :-)

Dear English-only speaking audience

We receive messages like this quite frequently:

Please only post in English on planet gnome or at least make non-english posts contain english translations.

If you don’t wish that posts like this are syndicated, please have the planet gnome administrator (jdub) pull a certain tag from your blog.

Thanks for understanding.

Note that Jeff Waugh (maintainer of planet-gnome) has indicated several times that he wants planet-gnome to be a window into the world, work and lives of GNOME hackers and contributors (top-right of the site). That includes “lives”, not just “work”, and for that reason planet-gnome does not filter based on tags like “GNOME”.

This however means that you get to read the personal blogs of the people who are syndicated. Very often they asked specifically about the use of non-English languages and about the fact that content is not always going to be related to GNOME at all. Very often it has been pointed out that is precisely the very idea of planet-gnome.

This means that planet-gnome is meant to have posts in different languages, is meant to have posts that are not about GNOME at all. If that’s not comfortable for you, then please either read another website or install filters.

I’m not planning to change my personal blog because planet-gnome doesn’t use my categories. Although I agree with and like its policies, I didn’t decide them. Please don’t complain to the non-English speaking blog writers who are syndicated on planet-gnome.