Well, I want to use freeDiameter with threads :) I need some advice on using the library in multi-threading environment.
Let me review a use-case: Lets say I've implemented several member functions in a class to simply provide wrapper methods on freediameter C function calls. In MessageRequest method I'd like to create DCC Message and send to diameter server. Well, for doing this I clearly need to use fd_sess_new and fd_sess_getsid functions to setup my "Session-ID" AVP, also have to use session_handler variable with fd_sess_state_store/fd_sess_state_retrieve functions for storing and retrieving session handler object on MessageResponse. So, as there will be going to several concurrent refers to MessageRequest method, I'd like to ask if the objects and functions in freediameter are thread-safe ? should i handle it manually ? should i use mutex every time that i'm going to work with the variables used in the methods ?
Thanks,
Many (all?) of the functions are thread-safe. For example, reading the source for
fd_sess_state_store
andfd_sess_state_retrieve
, we can see that thesession->stlock
is held while operating on the data structure. At least for those, there is no need to take a separate lock.