Threading libsmbclient - a proposal.

Howard Chu hyc at
Tue Apr 7 23:15:26 GMT 2009

Jeremy Allison wrote:
> On Sat, Apr 04, 2009 at 05:33:15PM -0700, Jeremy Allison wrote:
>> I'm thinking of something like :
>> SMB_PTHREAD_DEFINE_FNS(log_fn, var);
>> Which expands into definitions of all the functions
>> (using pthreads) we need to pass in to initialize,
>> and a definition and declaration of the struct to
>> pass (the logging function is optional and can be
>> NULL if not needed). var becomes the name of the
>> declared struct containing the vectors.
>> The main() function would then call
>> to actually cause the library to initialize the
>> thread functions, mutexes and TLS.
>> There's also functions for TLS we have to add, but I'll
>> look at that next week.
> Ok, after talking with tridge here is the template
> I'll be using to start adding threads to the lower
> level code.
> There are a couple of files - smb_threads.h
> smb_threads_internal.h which sets up the definitions
> of the pthread implemenations of these functions as
> a macro, and the struct containing the function vectors,
> and smb_threads.c which initializes the function
> vectors and right now contains a sample of the
> the way we'd use these functions.
> I didn't add the logging function, as that
> really should be left inside the implementations
> I think.
> So the locking primitives we'll be using in the code
> are:
> SMB_THREAD_LOCK(plock, type)
> To lock a mutex use : SMB_THREAD_LOCK(plock, SMB_THREAD_LOCK)
> and to unlock the mutex use : SMB_THREAD_LOCK(plock, SMB_THREAD_UNLOCK)

We often find the need for a trylock() op - fail immediately if the lock is in 
use, instead of waiting.

Your pthread destroy_lock needs to free() the lock memory that you malloc'd; 
pthread_mutex_destroy() only deinitializes it, it doesn't actually free it.

> For thread local storage we'll use :
> SMB_THREAD_CREATE_TLS(keyname, key)
> SMB_THREAD_SET_TLS(key, val)
> Let me know what you think ! If eveyone is ok I'll
> start adding this into the master branch.
> Jeremy.

   -- Howard Chu
   CTO, Symas Corp. 
   Director, Highland Sun
   Chief Architect, OpenLDAP

More information about the samba-technical mailing list