Description | Sometimes there is need to have an object that is thread specific. For example, a random number generator object in mcsmear. The overhead of maintaining this in a list that one then needs to lock a mutex to access every event is unnecessary. Similarly for creating a factory object and accessing the random number generator through that.
If a user-definable reference were added to JEventLoop, one could set it once and then access it at event time without mutex locking.
This could be done in a simple C-style way where the value is kept as a void* and it is up to the user to cast it back to the appropriate form.
Alternatively, one could use templated methods in JEventLoop to record not only the value, but rtti info so that it can be checked upon retrieval (value would be stored as void* in JEventLoop, but converted by template method before returning). This would be safer, but would add a little more overhead. Presumably not as much as mutex locking though. This second method would also allow for more than one type of reference to be stored, though again, for a slight overhead cost. |