1N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 1N/A * Use is subject to license terms. 1N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1N/A * The contents of this file are subject to the Netscape Public 1N/A * License Version 1.1 (the "License"); you may not use this file 1N/A * except in compliance with the License. You may obtain a copy of 1N/A * Software distributed under the License is distributed on an "AS 1N/A * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 1N/A * implied. See the License for the specific language governing 1N/A * rights and limitations under the License. 1N/A * The Original Code is Mozilla Communicator client code, released 1N/A * The Initial Developer of the Original Code is Netscape 1N/A * Communications Corporation. Portions created by Netscape are 1N/A * Copyright (C) 1998-1999 Netscape Communications Corporation. All 1N/A * Thread callback functions for libldap that use the NSPR (Netscape 1N/A * Portable Runtime) thread API. 1N/A#
endif /* _SOLARIS_SDK */ 1N/A * Grow thread private data arrays 10 elements at a time. 1N/A * Structures and types: 1N/A * Structure used by libldap thread callbacks to maintain error information. 1N/A * Structure used to maintain thread-private data. At the present time, 1N/A * only error info. is thread-private. One of these structures is allocated 1N/A * Structure used by associate a PRLDAP thread-private data index with an 1N/A * LDAP session handle. One of these exists for each active LDAP session 1N/A#
endif /* _SOLARIS_SDK */ 1N/A * prldap_map_list points to all of the PRLDAP_TPDMap structures 1N/A * we have ever allocated. We recycle them as we open and close LDAP 1N/A * The prldap_map_mutex is used to protect access to the prldap_map_list. 1N/A * The prldap_tpd_maxindex value is used to track the largest TPD array 1N/A * index we have used. 1N/A * prldap_tpdindex is an NSPR thread private data index we use to 1N/A * maintain our own thread-private data. It is initialized inside 1N/A * prldap_init_tpd(). 1N/A * The prldap_callonce_init_tpd structure is used by NSPR to ensure 1N/A * that prldap_init_tpd() is called at most once. 1N/A * Private function prototypes: 1N/A * Install NSPR thread functions into ld (if ld is NULL, they are installed 1N/A * as the default functions for new LDAP * handles). 1N/A * Returns 0 if all goes well and -1 if not. 1N/A#
endif /* _SOLARIS_SDK */ 1N/A /* set thread function pointers */ 1N/A * If this is a real ld (i.e., we are not setting the global 1N/A * defaults) allocate thread private data for error information. 1N/A * If ld is NULL we do not do this here but it is done in 1N/A * prldap_thread_new_handle(). 1N/A /* set extended thread function pointers */ 1N/A * Error info. has not yet been allocated for this thread. 1N/A * Do so now. Note that we free this memory only for the 1N/A * thread that calls prldap_thread_dispose_handle(), which 1N/A * should be the one that called ldap_unbind() -- see 1N/A * prldap_return_map(). Not freeing the memory used by 1N/A * other threads is deemed acceptable since it will be 1N/A * recycled and used by other LDAP sessions. All of the 1N/A * thread-private memory is freed when a thread exits 1N/A * (inside the prldap_tsd_destroy() function). 1N/A * Called when a new LDAP * session handle is allocated. 1N/A * Allocate thread-private data for error information, but only if 1N/A * it has not already been allocated and the get_ld_error callback has 1N/A * been installed. If ld is not NULL when prldap_install_thread_functions() 1N/A * is called, we will have already allocated the thread-private data there. 1N/A * Called when an LDAP * session handle is being destroyed. 1N/A * Clean up our thread private data map. 1N/A * Function: prldap_allocate_map() 1N/A * Description: allocate a thread-private data map to use for a new 1N/A * LDAP session handle. 1N/A * Returns: a pointer to the TPD map or NULL if none available. 1N/A * first look for a map that is already allocated but free to be re-used 1N/A * if none we found (map == NULL), try to allocate a new one and add it 1N/A * to the end of our global list. 1N/A /* since we are reusing...reset */ 1N/A /* to initial state */ 1N/A * Function: prldap_return_map() 1N/A * Description: return a thread-private data map to the pool of ones 1N/A * available for re-use. 1N/A * Dispose of thread-private LDAP error information. Note that this 1N/A * only disposes of the memory consumed on THIS thread, but that is 1N/A * okay. See the comment in prldap_set_ld_error() for the reason why. 1N/A /* mark map as available for re-use */ 1N/A * Function: prldap_new_tpdindex() 1N/A * Description: allocate a thread-private data index. 1N/A * Returns: the new index. 1N/A * Function: prldap_set_thread_private() 1N/A * Description: store a piece of thread-private data. 1N/A * Returns: 0 if successful and -1 if not. 1N/A return( -
1 );
/* bad index */ 1N/A return( -
1 );
/* realloc failed */ 1N/A * Function: prldap_get_thread_private() 1N/A * Description: retrieve a piece of thread-private data. If not set, 1N/A * Returns: 0 if successful and -1 if not. 1N/A return(
NULL );
/* no thread private data */ 1N/A return(
NULL );
/* fewer data items than requested index */ 1N/A * Function: prldap_tsd_realloc() 1N/A * Description: enlarge the thread-private data array. 1N/A * Returns: the new PRLDAP_TPDHeader value (non-NULL if successful). 1N/A * Note: tsdhdr can be NULL (allocates a new PRLDAP_TPDHeader). 1N/A /* allocate a new thread private data header */ 1N/A * Make the size of the new array the next highest multiple of 1N/A * the array increment value that is greater than maxindex. 1N/A /* increase the size of the data item array if necessary */ 1N/A * Function: prldap_tsd_destroy() 1N/A * Description: Free a thread-private data array. Installed as an NSPR TPD 1N/A * destructor function 1N/A * Note: this function assumes that each TPD item installed at the PRLDAP 1N/A * level can be freed with a call to PR_Free(). 1N/A * Initialize NSPR once 1N/A * For performance reason, test it here first 1N/A /* Make sure PR_Init() is executed only once */ 1N/A * PR_Init changes the signal handler of SIGPIPE to SIG_IGN. 1N/A * Save the original and restore it after PR_Init. 1N/A * PR_Init() changes the current thread's 1N/A * priority. Save and restore the priority. 1N/A * Restore signal handling attributes of SIGPIPE