I have a legacy C API that I need to add functionality to. Specifically I need to make some of this API’s calls thread-safe, because a call like this:
A_DoFoo(HandleA a)
Uses an object shared by all handles of type A.
My first thought is to add a function to the API that looks like this:
A_DoFooEx(HandleA a, HandleB b)
Is this a normal approach?
(I only used the Ex suffix because of years of exposure to the Win32 SDK. Does it make more sense to give a more descriptive name to the function?)
Adding another function under a new name is the standard (and in fact just about the only) way to deal with this problem in straight C (in C++ you could add a new overload and keep the old name). I’m not a big fan of the
Exsuffix, because it doesn’t tell you what the difference between the old and new APIs is. On the other hand, don’t saddle people with something long and heinous likeA_DoFoo_ThreadSafe, that hurts readability.In this case, I’d try to think of a name that indicates what the requirements on
HandleBare. If you tell us what this API actually does, we can maybe make more specific suggestions.