gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Possible code simplification and optimisation


From: Richard Frith-Macdonald
Subject: Possible code simplification and optimisation
Date: Wed, 22 Oct 2003 12:53:59 +0100

I've written a couple of classes - GSLazyLock and GSLazyRecursiveLock (subclasses of NSLock and NSRecursiveLock).

The idea of these is to be used to simplify stuff a bit with respect to threading - If we have a single threaded application, we don't want to waste time locking/unlocking mutexes pointlessly, but if we become multithreaded, we want any classes that need locks to have those locks in the correct state.

So, a GSLazyLock keeps track of its own state in a BOOL, and metamorphoses into an NSLock when the program becomes multithreaded, while a GSRecursiveLock keeps track of the number of times it has been locked in a counter. Classes using these locks can therefore be coded with no need to be aware of whether the program is running in single or multi-threaded mode.

Now -
I could add these as private classes and use them internally in the base library or I could add them as public classes in the Additions part of the base library or I could change the existing NSLock/NSRecursiveLock classes so that they do the same sort of thing.

Thoughts/comments?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]