Cat Zimmermann
Cat Zimmermann

Reputation: 1420

Adding functionality to an existing C API

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?)

Upvotes: 0

Views: 109

Answers (2)

zwol
zwol

Reputation: 140796

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 Ex suffix, 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 like A_DoFoo_ThreadSafe, that hurts readability.

In this case, I'd try to think of a name that indicates what the requirements on HandleB are. If you tell us what this API actually does, we can maybe make more specific suggestions.

Upvotes: 1

Vivek Goel
Vivek Goel

Reputation: 24160

I prefer writing wrapper for thread safe code. So I can embedded any thread un safe code and make it thread safe use wrapper.

You should always use a proper naming format. it will help you easily maintain your code and make it more readable.

Upvotes: 0

Related Questions