'this' and that
Hello all, I have a somewhat unusual question,
Having been given the task of unravelling a huge lump of multi-threaded spaghetti code (all data-members were public, don't ask) into three separate applications, one of the first things I did, was implement a thread-safe log-file of the call-stack, that records during run-time, for each thread, [almost] every function and method call (using the __FUNCTION__ macro), with various additional info (time-stamp, thread ID and system-component). This was achieved by factoring into the code, LOG_FUNC_ENTER and LOG_FUNC_RETURN macro calls, at the beginning of every function and every exit point (Ouch!). I used macros to "hide" the actual log-class method calls, so that I could have this code not-compiled in release versions. I'm very happy with my class (I'll post it if asked), and this log has helped me endlessly. But...
I would now like to add one additional piece of info, the value of the 'this' pointer, so I can track specific object instances across threads. Only problem is, that I have plenty of global and static functions, all of which obviously don't have a 'this'. :-( I considered adding a LogHelper fake base class to all classes that would merely contain a const void *__Self pointer that be set to 'this', and have an additional global variable of the same name set to 0xFFFF, to catch the cases where there is no 'this'. But this is rather memory-heavy, and won't work anyway for the static methods, where it is presumed you erroneously meant the non-static member (and not the legally accessible global). I'd rather not have to create two sets of macros, for methods and functions and then refactor all those hundreds of bloody calls.
So folks, is there any form of template magic or something, that will let me evaluate at compile time, an expression either to 'this' or to some preset constant??
Having been given the task of unravelling a huge lump of multi-threaded spaghetti code (all data-members were public, don't ask) into three separate applications, one of the first things I did, was implement a thread-safe log-file of the call-stack, that records during run-time, for each thread, [almost] every function and method call (using the __FUNCTION__ macro), with various additional info (time-stamp, thread ID and system-component). This was achieved by factoring into the code, LOG_FUNC_ENTER and LOG_FUNC_RETURN macro calls, at the beginning of every function and every exit point (Ouch!). I used macros to "hide" the actual log-class method calls, so that I could have this code not-compiled in release versions. I'm very happy with my class (I'll post it if asked), and this log has helped me endlessly. But...
I would now like to add one additional piece of info, the value of the 'this' pointer, so I can track specific object instances across threads. Only problem is, that I have plenty of global and static functions, all of which obviously don't have a 'this'. :-( I considered adding a LogHelper fake base class to all classes that would merely contain a const void *__Self pointer that be set to 'this', and have an additional global variable of the same name set to 0xFFFF, to catch the cases where there is no 'this'. But this is rather memory-heavy, and won't work anyway for the static methods, where it is presumed you erroneously meant the non-static member (and not the legally accessible global). I'd rather not have to create two sets of macros, for methods and functions and then refactor all those hundreds of bloody calls.
So folks, is there any form of template magic or something, that will let me evaluate at compile time, an expression either to 'this' or to some preset constant??
