C++ in the kernel

Alfred Perlstein alfred at freebsd.org
Tue Oct 30 13:12:30 PDT 2007


* Bakul Shah <bakul at bitblocks.com> [071030 11:11] wrote:
> > * Bakul Shah <bakul at bitblocks.com> [071030 09:36] wrote:
> > > 
> > > The structured macro paper referenced on the K wiki page also
> > > seems rather interesting.  A powerful macro facility needs to
> > > be well integrated with the language (much like Lisp or
> > > Scheme's macros) so that you can write for instance
> > > 
> > >     critical_section(lock) {
> > > 	...
> > > 	bar:
> > > 	...
> > > 	if (cond1) break;
> > > 	...
> > > 	if (cond2) goto foo;
> > > 	...
> > > 	if (cond3) goto bar;
> > > 	...
> > > 	if (cond4) return; // from enclosing function
> > > 	...
> > >     }
> > >     ...
> > >     foo:
> > 
> > 
> > do you mean like C++:
> > 
> > do {
> > 	critical_object critical_instance();
> > 
> > 
> > 
> > 
> > }
> 
> No idea but I can not see how that will do what I had in mind. A purely
> lexical translation of the snippet I gave above would be something like:

You can create an object on the stack that locks the mutex given
to it  like so:

do {
	mtx_lock_object mtx_locker(&lock);

}

When the object is destroyed by stack popping, the lock will be freed.

It's the same thing.

-Alfred


More information about the freebsd-arch mailing list