/*
 * Function: prldap_allocate_map()
 * Description: allocate a thread-private data map to use for a new
 *	LDAP session handle.
 * Returns: a pointer to the TPD map or NULL if none available.
 */
static PRLDAP_TPDMap *
prldap_allocate_map( LDAP *ld )
{
    PRLDAP_TPDMap	*map, *prevmap;

    PR_Lock( prldap_map_mutex );

    /*
     * first look for a map that is already allocated but free to be re-used
     */
    prevmap = NULL;
    for ( map = prldap_map_list; map != NULL; map = map->prtm_next ) {
	if ( map->prtm_ld == NULL ) {
	    break;
	}
	prevmap = map;
    }

    /*
     * if none was found (map == NULL), try to allocate a new one and add it
     * to the end of our global list.
     */
    if ( map == NULL ) {
	PRUintn	tpdindex;

	tpdindex = prldap_new_tpdindex();
	map = (PRLDAP_TPDMap *)PR_Malloc( sizeof( PRLDAP_TPDMap ));
	if ( map != NULL ) {
	    map->prtm_index = tpdindex;
	    map->prtm_next = NULL;
	    if ( prevmap == NULL ) {
		prldap_map_list = map;
	    } else {
		prevmap->prtm_next = map;
	    }
	}
    }

    if ( map != NULL ) {
	map->prtm_ld = ld;	/* now marked as "in use" */

	/*
	 * If old thread-private error information exists, reset it. It may
	 * have been left behind by an old LDAP session that was used by
	 * this thread but disposed of by a different thread.
	 */
	if ( NULL != prldap_get_thread_private( map->prtm_index )) {
	    prldap_set_ld_error( LDAP_SUCCESS, NULL, NULL, map );
	}
    }

    PR_Unlock( prldap_map_mutex );

    return( map );
}
Exemple #2
0
/*
 * Function: prldap_allocate_map()
 * Description: allocate a thread-private data map to use for a new
 *	LDAP session handle.
 * Returns: a pointer to the TPD map or NULL if none available.
 */
static PRLDAP_TPDMap *
prldap_allocate_map( LDAP *ld )
{
    PRLDAP_TPDMap	*map, *prevmap;

    PR_Lock( prldap_map_mutex );

    /*
     * first look for a map that is already allocated but free to be re-used
     */
    prevmap = NULL;
    for ( map = prldap_map_list; map != NULL; map = map->prtm_next ) {
	if ( map->prtm_ld == NULL ) {
	    break;
	}
	prevmap = map;
    }

    /*
     * if none we found (map == NULL), try to allocate a new one and add it
     * to the end of our global list.
     */
    if ( map == NULL ) {
	PRUintn	tpdindex;

	tpdindex = prldap_new_tpdindex();
	map = (PRLDAP_TPDMap *)PR_Malloc( sizeof( PRLDAP_TPDMap ));
	if ( map != NULL ) {
	    map->prtm_index = tpdindex;
	    map->prtm_next = NULL;
	    if ( prevmap == NULL ) {
		prldap_map_list = map;
	    } else {
		prevmap->prtm_next = map;
	    }
	}
    }

    if ( map != NULL ) {
	map->prtm_ld = ld;	/* now marked as "in use" */
				/* since we are reusing...reset */
				/* to initial state */
	(void)prldap_set_thread_private( map->prtm_index, NULL );
    }

    PR_Unlock( prldap_map_mutex );

    return( map );
}