Example #1
0
/*
 * globus_l_module_decrement()
 */
static globus_l_module_entry_t *
globus_l_module_decrement(
    globus_module_descriptor_t *	module_descriptor,
    globus_l_module_key_t		parent_key)
{
    globus_l_module_entry_t *		entry;
    
    entry =
	globus_hashtable_lookup(
	    &globus_l_module_table,
	    (void *) module_descriptor->activation_func);
    if (entry == GLOBUS_NULL || entry->reference_count <= 0)
    {
	return NULL;
    }

    entry->reference_count--;
    
    if (parent_key != GLOBUS_NULL)
    {
	globus_list_t *			client_entry;

	
	client_entry = globus_list_search(entry->clients,
					  (void *) parent_key);
	if(client_entry != GLOBUS_NULL)
        {
	    globus_list_remove(&entry->clients, client_entry);
	}
	/* else module was activated outside this parent */
    }

    return entry;
}
Example #2
0
/*
 * globus_l_module_increment()
 */
static globus_bool_t
globus_l_module_increment(
    globus_module_descriptor_t *	module_descriptor,
    globus_l_module_key_t		parent_key,
    globus_module_deactivate_proxy_cb_t deactivate_cb,
    void *                              user_arg)
{
    globus_l_module_entry_t *		entry;
    
    entry =
	globus_hashtable_lookup(
	    &globus_l_module_table,
	    (void *) module_descriptor->activation_func);

    if (entry != GLOBUS_NULL)
    {
	/*
	 * The module has already been registered.  Increment its reference
	 * counter and add any new clients to the dependency list
	 */
	entry->reference_count++;
	if (parent_key != GLOBUS_NULL
	    && globus_list_search(entry->clients,
				  (void *) parent_key) == GLOBUS_NULL)
	{
	    globus_list_insert(&entry->clients, (void *) parent_key);
	}

	if(entry->reference_count == 1)
	{
	    entry->deactivate_cb = deactivate_cb;
	    entry->user_arg = user_arg;
	    return GLOBUS_TRUE;
	}
	else
	{
    	    return GLOBUS_FALSE;
	}
    }
    else
    {
	/*
	 * This is the first time this module has been registered.  Create a
	 * new entry in the modules table.
	 */
	entry = (globus_l_module_entry_t *)
	    globus_malloc(sizeof(globus_l_module_entry_t));
	globus_assert(entry != GLOBUS_NULL);

	entry->descriptor = module_descriptor;
	entry->reference_count = 1;
	entry->clients = GLOBUS_NULL;
	entry->deactivate_cb = deactivate_cb;
	entry->user_arg = user_arg;
	if (parent_key != GLOBUS_NULL)
	{
	    globus_list_insert(&entry->clients, (void *) parent_key);
	}
	
	globus_hashtable_insert(
	    &globus_l_module_table,
	    (void *) module_descriptor->activation_func,
	    entry);

	globus_list_insert(&globus_l_module_list, entry);
	
	return GLOBUS_TRUE;
    }
}
Example #3
0
/*
 * globus_module_activate()
 */
int
globus_module_activate_proxy(
    globus_module_descriptor_t *	module_descriptor,
    globus_module_deactivate_proxy_cb_t deactivate_cb,
    void *                              user_arg)
{
    globus_l_module_key_t               parent_key;
    int                                 ret_val;
    globus_l_module_key_t               parent_key_save;
    
    /*
     * If this is the first time this routine has been called, then we need to
     * initialize the internal data structures and activate the threads
     * packages if the system has been configured to use threads.
     */
    if (globus_i_module_initialized == GLOBUS_FALSE)
    {
	globus_i_module_initialized = GLOBUS_TRUE;
	globus_l_module_initialize();
    }
    
    parent_key = (globus_l_module_key_t)
        globus_thread_getspecific(globus_l_activate_parent_key);
    /*
     * Once the recursive mutex has been acquired, increment the reference
     * counter for this module, and call it's activation function if it is not
     * currently active.
     */
    globus_l_module_mutex_lock(&globus_l_module_mutex);
    {
	ret_val = GLOBUS_SUCCESS;

	if (module_descriptor->activation_func != GLOBUS_NULL)
	{
	    if (globus_l_module_increment(module_descriptor,
					  parent_key,
					  deactivate_cb,
					  user_arg) == GLOBUS_TRUE)
	    {
		parent_key_save = parent_key;
		globus_thread_setspecific(
		    globus_l_activate_parent_key,
		    module_descriptor->activation_func);
		
		ret_val = module_descriptor->activation_func();
                
                if(ret_val != GLOBUS_SUCCESS)
                {
                    globus_l_module_decrement(
                        module_descriptor, parent_key_save);
                }
                else
                {
		/*
		 * Set up the exit handler
		 */
#                   if defined(HAVE_ATEXIT) || defined(HAVE_ONEXIT)
                    {
                        if(module_descriptor->atexit_func != GLOBUS_NULL)
                        {
                            /* only call the atexit function once */
                            if(!globus_list_search(
                                globus_l_module_atexit_funcs,
                                (void *) module_descriptor->atexit_func))
                            {
                                globus_list_insert(
                                    &globus_l_module_atexit_funcs,
                                    (void *) module_descriptor->atexit_func);
    
                                atexit(module_descriptor->atexit_func);
                            }
                        }
                    }
#                   endif
                }
                
                globus_thread_setspecific(
		    globus_l_activate_parent_key, parent_key_save);
	    }
	}
    }
    globus_l_module_mutex_unlock(&globus_l_module_mutex);

    return ret_val;
}
/** @brief Globus List Test Cases*/
int
list_test(void)
{
    globus_list_t                      *list = GLOBUS_NULL;
    int                                 rc;
    void                               *ptr;
    int                                 x1 = 1;
    int                                 x2 = 2;
    int                                 x3 = 3;
    int                                 x4 = 4;
    int                                 search_item;
    globus_list_t                      *sub_list;
    int                                 size;
    printf("1..25\n");
    globus_module_activate(GLOBUS_COMMON_MODULE);

    /**
     * @test
     * Call globus_list_size() with an empty list
     */
    size = globus_list_size(list);
    ok(size == 0, "size_of_empty_list");

    /**
     * @test
     * Insert a datum into a globus_list_t with globus_list_insert()
     */
    rc = globus_list_insert(&list, &x1);
    ok(rc == 0, "insert_item_into_empty_list");

    /**
     * @test
     * Add a datum to a globus_list_t with globus_list_cons()
     */
    list = globus_list_cons(&x2, list);
    ok(list != NULL, "globus_list_cons");

    /**
     * @test
     * Verify that globus_list_size() returns 2 after adding two data
     * items to a list.
     */
    size = globus_list_size(list);
    ok(size == 2, "size_of_list_after_insert_and_cons");

    /**
     * @test
     * Insert x3 into a list with globus_list_insert()
     */
    ok(globus_list_insert(&list, &x3) == 0, "insert_x3");

    /**
     * @test
     * Insert x4 into a list with globus_list_insert()
     */
    ok(globus_list_insert(&list, &x4) == 0, "insert_x4");

    /**
     * @test
     * Verify that the size of the list is now 4 with globus_list_size()
     */
    ok(globus_list_size(list) == 4, "check_new_size");

    /**
     * @test
     * Search for the first item in a list with globus_list_search()
     */
    sub_list = globus_list_search(list, &x1);
    ok(sub_list != NULL, "search_first");

    /**
     * @test
     * Use globus_list_first() to return the datum from the returned list node.
     * Verify that the search result matches the value searched for.
     */
    ptr = globus_list_first(sub_list);
    ok(*((int *)ptr) == x1, "search_first_value");

    /**
     * @test
     * Search for the third item in a list with globus_list_search()
     */
    sub_list = globus_list_search(list, &x3);
    ok(sub_list != NULL, "search_third");

    /**
     * @test
     * Use globus_list_first() to return the datum from the returned list node.
     * Verify that the search result matches the value searched for.
     */
    ptr = globus_list_first(sub_list);
    ok(*((int *)ptr) == x3, "search_third_value");

    /**
     * @test
     * Search for the fourth item in a list with globus_list_search()
     */
    sub_list = globus_list_search(list, &x4);
    ok(sub_list != NULL, "search_last");
    /**
     * @test
     * Use globus_list_first() to return the datum from the returned list node.
     * Verify that the search result matches the value searched for.
     */
    ptr = globus_list_first(sub_list);
    ok(*((int *)ptr) == x4, "search_last_value");

    /**
     * @test
     * Search for the second item in a list with globus_list_search()
     */
    sub_list = globus_list_search(list, &x2);
    ok(sub_list != NULL, "search_second");

    /**
     * @test
     * Use globus_list_first() to return the datum from the returned list node.
     * Verify that the search result matches the value searched for.
     */
    ptr = globus_list_first(sub_list);
    ok(*((int *)ptr) == x2, "search_second_value");

    /**
     * @test
     * Search for the fourth item in a list with globus_list_search_pred()
     */
    search_item = 4;
    sub_list = globus_list_search_pred(list, matches, &search_item);
    ok(sub_list != NULL, "search_pred_4");

    /**
     * @test
     * Search for the second item in a list with globus_list_search_pred()
     */
    search_item = 2;
    sub_list = globus_list_search_pred(list, matches, &search_item);
    ok(sub_list != NULL, "search_pred_2");

    /**
     * @test
     * Search for the third item in a list with globus_list_search_pred()
     */
    search_item = 3;
    sub_list = globus_list_search_pred(list, matches, &search_item);
    ok(sub_list != NULL, "search_pred_3");

    /**
     * @test
     * Search for the first item in a list with globus_list_search_pred()
     */
    search_item = 1;
    sub_list = globus_list_search_pred(list, matches, &search_item);
    ok(sub_list != NULL, "search_pred_1");

    /**
     * @test
     * Search for the second item in the list with globus_list_search()
     */
    sub_list = globus_list_search(list, &x2);
    ok(sub_list != NULL, "search_2");

    /**
     * @test
     * Remove the second item in the list with globus_list_remove()
     */
    ok(globus_list_remove(&list, sub_list) == &x2, "remove_2");

    /**
     * @test
     * Remove the first item in the list with globus_list_remove()
     */
    ok(globus_list_remove(&list, list) == &x4, "remove_first");
    /**
     * @test
     * Remove the first item in the list with globus_list_remove()
     */
    ok(globus_list_remove(&list, list) == &x3, "remove_first_again");
    /**
     * @test
     * Remove the first item in the list with globus_list_remove()
     */
    ok(globus_list_remove(&list, list) == &x1, "remove_first_again");

    /**
     * @test
     * Verify that the list is empty with globus_list_empty()
     */
    ok(globus_list_empty(list), "empty_list");

    globus_list_free(list);

    globus_module_deactivate(GLOBUS_COMMON_MODULE);

    return TEST_EXIT_CODE;
}
globus_result_t
globus_xio_data_descriptor_destroy(
    globus_xio_data_descriptor_t        data_desc)
{
    globus_result_t                     res = GLOBUS_SUCCESS;
    globus_i_xio_op_t *                 op;
    globus_i_xio_handle_t *             handle;
    globus_bool_t                       destroy_handle = GLOBUS_FALSE;
    globus_list_t *                     node;
    GlobusXIOName(globus_xio_data_descriptor_destroy);

    GlobusXIODebugEnter();
    
    if(data_desc == NULL)
    {
        res = GlobusXIOErrorParameter("data_desc");
        goto err;
    }

    op = (globus_i_xio_op_t *) data_desc;

    globus_mutex_lock(&globus_i_xio_mutex);
    {
        /* make sure we haven't destroyed it already */
        node = globus_list_search(globus_i_xio_outstanding_dds_list, op);
        if(node)
        {
            globus_list_remove(&globus_i_xio_outstanding_dds_list, node);
        }
    }
    globus_mutex_unlock(&globus_i_xio_mutex);
    
    if(node == NULL)
    {
        res = GlobusXIOErrorParameter("data_desc already destroyed");
        goto err;
    }
    
    handle = op->_op_handle;
    
    globus_mutex_lock(&handle->context->mutex);
    {
        GlobusXIOOpDec(op);
        if(op->ref == 0)
        {
            globus_i_xio_op_destroy(op, &destroy_handle);
        }
    }
    globus_mutex_unlock(&handle->context->mutex);
    
    if(destroy_handle)
    {
        globus_i_xio_handle_destroy(handle);
    }

    GlobusXIODebugExit();
    return GLOBUS_SUCCESS;

  err:

    GlobusXIODebugExitWithError();
    return res;
}
globus_result_t
globus_xio_attr_destroy(
    globus_xio_attr_t                   attr)
{
    int                                 ctr;
    globus_result_t                     res = GLOBUS_SUCCESS;
    globus_result_t                     tmp_res;
    GlobusXIOName(globus_xio_attr_destroy);

    GlobusXIODebugEnter();
    
    if(attr == NULL)
    {
        res = GlobusXIOErrorParameter("attr");
        goto err;
    }
    
    globus_mutex_lock(&globus_i_xio_mutex);
    {
        if(!attr->unloaded)
        {
            for(ctr = 0; ctr < attr->ndx; ctr++)
            {
                GlobusXIODebugPrintf(
                    GLOBUS_XIO_DEBUG_INFO_VERBOSE, 
                    (_XIOSL("[globus_xio_attr_destroy]: destroying attr @0x%x "
                        "driver @0x%x, %s\n"), 
                    attr,
                    attr->entry[ctr].driver,
                    attr->entry[ctr].driver->name));
                                
                /* report the last seen error but be sure to attempt to clean 
                    them all */
                tmp_res = attr->entry[ctr].driver->attr_destroy_func(
                        attr->entry[ctr].driver_data);
                if(tmp_res != GLOBUS_SUCCESS)
                {
                    res = tmp_res;
                }
            }
            
            globus_list_remove(
                &globus_i_xio_outstanding_attrs_list,
                globus_list_search(
                    globus_i_xio_outstanding_attrs_list, attr));
        }
    }
    globus_mutex_unlock(&globus_i_xio_mutex);

    if(attr->user_open_sbj)
    {
        globus_free(attr->user_open_sbj);
    }
    if(attr->user_open_username)
    {
        globus_free(attr->user_open_username);
    }
    if(attr->user_open_pw)
    {
        globus_free(attr->user_open_pw);
    }
 
    globus_callback_space_destroy(attr->space);
    globus_free(attr->entry);
    globus_free(attr);
    if(res != GLOBUS_SUCCESS)
    {
        goto err;
    }

    GlobusXIODebugExit();
    return GLOBUS_SUCCESS;

  err:

    GlobusXIODebugExitWithError();
    return res;
}
/**
 * Dereference a request handle.
 *
 * This function decreases the reference count on an GASS Transfer
 * request handle. If the reference count becomes zero, then the
 * #globus_gass_transfer_request_struct_t associated with the handle
 * is destroyed.
 *
 * @note This function must be called with the request handle mutex locked.
 *
 * @param request
 *        The request to destroy.
 *
 * @retval GLOBUS_SUCCESS
 *         The request handle's reference count was decremented. The request
 *         structure is freed if this was the final reference to the handle.
 * @retval GLOBUS_GASS_TRANSFER_ERROR_INVALID_USE
 *         The request handle was not valid.
 * @see globus_gass_transfer_request_destroy()
 */
int
globus_i_gass_transfer_request_destroy(
    globus_gass_transfer_request_t		request)
{
    globus_bool_t				referenced;
    globus_gass_transfer_request_struct_t *	req;

    req =
	globus_handle_table_lookup(&globus_i_gass_transfer_request_handles,
				   request);
    if(req == GLOBUS_NULL)
    {
	return GLOBUS_GASS_TRANSFER_ERROR_INVALID_USE;
    }

    referenced =
	globus_handle_table_decrement_reference(&globus_i_gass_transfer_request_handles,
						request);
    if(!referenced)
    {
	int					i;
	globus_list_t *				tmp;

	tmp = globus_list_search(globus_i_gass_transfer_requests,
				 (void *) (intptr_t) request);
	
#if DEBUG_GASS_TRANSFER
	printf(_GTSL("removing from list\n"));
#endif
        if (tmp)
        {
            globus_list_remove(&globus_i_gass_transfer_requests,
                               tmp);

            globus_cond_signal(&globus_i_gass_transfer_shutdown_cond);
            
            if(req->attr)
            {
                globus_object_free(req->attr);
            }
            globus_fifo_destroy(&req->pending_data);
            if (req->url)
            {
                globus_free(req->url);
            }

            /* free referral */
            for(i = 0; i < req->referral_count; i++)
            {
                globus_free(req->referral_url[i]);
            }
            if(req->referral_url)
            {
                globus_free(req->referral_url);
            }
            req->referral_url = GLOBUS_NULL;
            req->referral_count = 0;

            /* free deny message */
            if(req->denial_message)
            {
                globus_free(req->denial_message);
            }

            /* free subject name */
            if(req->subject)
            {
                globus_free(req->subject);
            }

            globus_free(req);
            request = GLOBUS_NULL_HANDLE;
        }

	return GLOBUS_SUCCESS;
    }
    else
    {
	return GLOBUS_SUCCESS;
    }
}