fix CO_ROUTINE_SPECIFIC bugs when variable used in multiple cpps#210
fix CO_ROUTINE_SPECIFIC bugs when variable used in multiple cpps#210sunjinopensource wants to merge 1 commit intoTencent:masterfrom
Conversation
…e defined by CO_ROUTINE_SPECIFIC is referenced in multiple cpps, multiple instances of the variable will be generated under release build.
|
|
|
I don't think this method would work. It seems like you defined a static CO_ROUTINE_SPECIFIC variable for that macro. In this case, every .c or .cpp file that referenced the header file where CO_ROUTINE_SPECIFIC variable is defined will have their own copy of that variable (static variables don't share across .c or .cpp files). This is not the same as coroutine-specific variables, where as long as you are refering to that variable from the same coroutine, you are accessing the same copy of the variable, no matter from which .cpp file you are refering. To correctly declare a coroutine specific variable where every .cpp file shares the same copy, you have to do the same as you declare a static variable: define them in a .cpp file and declare "extern [variable]" in the corresponding header file. |
|
#define CO_ROUTINE_SPECIFIC(Cls, var) static clsCoSpecificData& var = clsCoSpecificData::GetInstance(); The static variable defined by CO_ROUTINE_SPECIFIC is a reference, which actually points to the same object, so there is no copy problem. |
fix issue #209