Ooh, you've turned over quite a stone there :) You'll find hundreds of places in Citadel Server where we make references to thread specific data, particularly the macro "CC" which returns a reference to the session context associated with the currently executing thread. One of our developers, some number of years ago, tried to squeeze a bit more performance out of the server by changing lots of functions to load that address into a function-local variable at the top of many different functions. I felt it made the code harder to read and follow, and ended up removing a lot of those references. One of the biggest sins I committed in the 1980s and 1990s was the overuse of global variables. Thread-specific variables are sort of an extension of the same thing. Thread-specific and session-specific data need to exist, but they way I referred to them everywhere is kind of ugly.
For an example of the worst of the worst, look at the text client. In the oldest parts of it, you'd think that I learned to write in C by reading a book on BASIC. Global variables everywhere, too few functions, flow control like spaghetti. For an example of the best of the best, look at WebCit-NG. Global variables are kept to an absolute minimum; session-specific data are carefully passed up the stack through every function, usually with a variable called "h" for the HTTP session, and a variable called "c" for the Citadel Server context. You will find Citadel Server to be somewhere in between. Its flow control is reasonable but there are still too many non-local variable references, from the perspective of a modern developer. The practical upshot of all this is that YES, if we can pass a reference to thread-specific or session-specific data up the stack instead of constantly asking libc to find it for us, that is a reasonable performance improvement. But of course it's critical to make sure we get it right, and look carefully for edge cases so we don't accidentally pass a reference to the wrong thread or session. Oh, and do yourself a favor, try not to look at WebCit-Classic at all. It will hurt your brain. :)
