I working on a huge code base written many years ago. We're trying to implement multi-threading and I'm incharge of cleaning up global variables (sigh!)
My strategy is to move all global variables to a class, and then individual threads will use instances of that class and the globals will be accessed through class instance and ->
operator.
In first go, I've compiled a list of global variables using nm
by finding B
and D
group object names. The list is not complete, and incase of static variables, I don't get file and line number info.
The second stage is even more messy, I've to replace all globals in the code base with classinstance->global_name
pattern. I'm using cscope Change text string
for this. The problem is that in case of some globals, their name is also being used locally inside functions, and thus cscope
is replacing them as well.
Any other way to go about it? Any strategies, or help please!