Threading libsmbclient - a proposal.

Jeremy Allison jra at samba.org
Tue Apr 7 22:53:05 GMT 2009


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
> 
> SMB_PTHREAD_INIT(var);
> 
> 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_CREATE_LOCK(name, plock)
SMB_THREAD_LOCK(plock, type)
SMB_THREAD_DESTROY_LOCK(plock)

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)

For thread local storage we'll use :

SMB_THREAD_CREATE_TLS(keyname, key)
SMB_THREAD_DESTROY_TLS(key)
SMB_THREAD_SET_TLS(key, val)
SMB_THREAD_GET_TLS(key)

Let me know what you think ! If eveyone is ok I'll
start adding this into the master branch.

Jeremy.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smb_threads.h
Type: text/x-chdr
Size: 3731 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20090407/feb3423d/smb_threads.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smb_threads_internal.h
Type: text/x-chdr
Size: 1637 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20090407/feb3423d/smb_threads_internal.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smb_threads.c
Type: text/x-csrc
Size: 2741 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20090407/feb3423d/smb_threads-0001.bin


More information about the samba-technical mailing list