Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 02 Apr 2002 17:19:04 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Jake Burkholder <jake@locore.ca>
Cc:        John Baldwin <jhb@FreeBSD.ORG>, smp@FreeBSD.ORG, "Andrew R. Reiter" <arr@FreeBSD.ORG>
Subject:   Re: Where to initialize certain locks...
Message-ID:  <3CAA5888.11E9406E@mindspring.com>
References:  <XFMail.20020402110910.jhb@FreeBSD.org> <3CAA422A.4CAF1CAE@mindspring.com> <20020402192144.Q207@locore.ca>

next in thread | previous in thread | raw e-mail | index | archive | help
Jake Burkholder wrote:
> The reason they need to be initialized is to insert them into an all_mtx
> list which is used for debugging.  Otherwise there's no problem; the lock
> for said list is statically initialized.
> 
> This is the kernel.  This is not pthreads.  Arguably anything that depends
> on them needing to be statically initialized to unlocked and usable is
> broken.

So it should be "#ifdef DEBUG".

In the non-debug case, this should be done using linker sets.
Here is some sample code:

	struct foo {
		int		some_data;
		struct foo *next;
	};

	#define FOOINIT(uniquifier, data)			\
		static struct foo uniquifier ## _foo_init = {	\
			data,					\
			0					\
		};						\
		DATA_SET(foo_set,uniquifier ## _foo_init);

	void
	foo_startup( void)
	{
		register struct foo **foopp;

		/*
		 * Turn sysinit list into linked list so we can
		 * extend it later by linking things onto the
		 * next pointer.
		 */
		for( foopp = foo; *foopp != NULL; foopp++) {
			if ( *(foopp + 1) != NULL)
				(*foopp)->next = *(foopp + 1);
		}
	}

Voila'.  You now have a linked list, like that used for debugging,
built out of linker set entries, and the list is runtime extensible,
unlike, say, the VOP descriptor list.

You can now statically declare mutex instances, and they will be
immediately ready for use, after the statup that does the linkage
runs.

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-smp" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3CAA5888.11E9406E>