Пример #1
0
BTranslatorRoster*
BTranslatorRoster::Default()
{
	static int32 lock = 0;

	if (sDefaultRoster != NULL)
		return sDefaultRoster;

	if (atomic_add(&lock, 1) != 0) {
		// Just wait for the default translator to be instantiated
		while (sDefaultRoster == NULL)
			snooze(10000);

		atomic_add(&lock, -1);
		return sDefaultRoster;
	}

	// If the default translators have not been loaded,
	// create a new BTranslatorRoster for them, and load them.
	if (sDefaultRoster == NULL) {
		BTranslatorRoster* roster = new BTranslatorRoster();
		roster->AddTranslators(NULL);

		sDefaultRoster = roster;
			// this will unlock any other threads waiting for
			// the default roster to become available
	}

	atomic_add(&lock, -1);
	return sDefaultRoster;
}