Messages in this thread | | | Date | Sat, 16 Jan 1999 01:21:57 -0500 | From | Chip Salzenberg <> | Subject | Re: C++ in kernel (was Re: exception in a device driver) |
| |
According to Alexander Viro: > On Sat, 16 Jan 1999, Chip Salzenberg wrote: > > Stroupstrup's design rule: "Constructors acquite resources; > > destructors release them." > > So, you are going to allocate an object in stack for each > semaphore you are holding?
Yup.
> shitload of overhead even if we'll do it in assembler
I doubt that very strongly. Consider that the object need not be polymorphic; all it needs is a pointer member. And if you use a template class, you don't even need the pointer, so it'll be 100% as efficient as the C version (except one byte for the object itself (zero-length objects are not allowed (yet))).
Given:
template <semaphore_t *SEM> class hold { public: hold() { down(SEM); } ~hold() { up(SEM); } };
The code would look like:
void random_function() { hold<&one_semaphore> hold1; hold<&other_semaphore> hold2; // ... }
-- Chip Salzenberg - a.k.a. - <chip@perlsupport.com> "When do you work?" "Whenever I'm not busy."
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |