Skip to content

Conversation

@sunjinopensource
Copy link

fix issue #209

…e defined by CO_ROUTINE_SPECIFIC is referenced in multiple cpps, multiple instances of the variable will be generated under release build.
@tencent-adm
Copy link
Member

tencent-adm commented Jan 4, 2024

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Sapiens-wx
Copy link

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.

@sunjinopensource
Copy link
Author

#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants