static int globus_l_seg_stdout_deactivate(void) { globus_mutex_lock(&globus_l_seg_mutex); globus_l_seg_shutdown = 1; if (globus_l_seg_write_registered) { while (globus_l_seg_shutdown == 1) { globus_cond_wait(&globus_l_seg_mutex, &globus_l_seg_cond); } } globus_fifo_destroy(&globus_l_seg_buffers); globus_mutex_unlock(&globus_l_seg_mutex); globus_xio_close(globus_l_seg_output_handle, NULL); globus_xio_close(globus_l_seg_input_handle, NULL); globus_mutex_destroy(&globus_l_seg_mutex); globus_cond_destroy(&globus_l_seg_cond); globus_module_deactivate(GLOBUS_XIO_MODULE); globus_module_deactivate(GLOBUS_SCHEDULER_EVENT_GENERATOR_MODULE); globus_module_deactivate(GLOBUS_COMMON_MODULE); return 0; }
void test_monitor_destroy( test_monitor_t * monitor) { globus_cond_destroy(&monitor->cond); globus_mutex_destroy(&monitor->mutex); }
void transfer_control_destroy(transfer_control_t * TransferControl) { GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); if (TransferControl != NULL) { /* Unregister to receive messages. */ msg_unregister(TransferControl->MsgHandle, TransferControl->MsgRegisterID); /* Destroy the PIO control handle. */ pio_control_destroy(TransferControl->PioControl); /* * Temp workaround to make sure the thread that called us isn't still * holding this lock. */ globus_mutex_lock(&TransferControl->Lock); globus_mutex_unlock(&TransferControl->Lock); /* Dellocate the lock. */ globus_mutex_destroy(&TransferControl->Lock); /* Destroy the transfer range list. */ range_list_destroy(TransferControl->TransferRangeList); /* Deallocate our handle. */ globus_free(TransferControl); } GlobusGFSHpssDebugExit(); }
static void bounce_handle_destroy( bounce_handle_t * handle) { globus_mutex_destroy(&handle->mutex); globus_free(handle); }
/** * Destroy an HTTP handle * @ingroup globus_i_xio_http_handle * * Frees all storage associated with an HTTP handle. The handle must * not be used after this function returns. * * @param http_handle * Handle to be destroyed. * * @return void */ void globus_i_xio_http_handle_destroy( globus_i_xio_http_handle_t * http_handle) { int i; globus_mutex_destroy(&http_handle->mutex); globus_i_xio_http_request_destroy(&http_handle->request_info); globus_i_xio_http_response_destroy(&http_handle->response_info); globus_i_xio_http_target_destroy_internal(&http_handle->target_info); if (http_handle->header_iovec != NULL) { for (i = 0; i < http_handle->header_iovcnt; i++) { globus_libc_free(http_handle->header_iovec[i].iov_base); } globus_libc_free(http_handle->header_iovec); } if (http_handle->read_buffer.iov_base != NULL) { globus_libc_free(http_handle->read_buffer.iov_base); } if (http_handle->close_operation != NULL) { globus_xio_driver_operation_destroy(http_handle->close_operation); } }
/** * Operator: Finalize */ ngemResult_t ngrcOperatorFinalize( ngrcOperator_t*op) { globus_result_t gResult; ngLog_t *log; ngemResult_t ret = NGEM_SUCCESS; NGEM_FNAME(ngrcOperatorFinalize); log = ngemLogGetDefault(); NGEM_ASSERT(op != NULL); op->ngo_handle = NULL; op->ngo_canceled = false; gResult = globus_mutex_destroy(&op->ngo_mutex); if (gResult != GLOBUS_SUCCESS) { ngcpLogGlobusError(log, NGRC_LOGCAT_GT, fName, "globus_mutex_destroy", gResult); ret = NGEM_FAILED; } gResult = globus_cond_destroy(&op->ngo_cond); if (gResult != GLOBUS_SUCCESS) { ngcpLogGlobusError(log, NGRC_LOGCAT_GT, fName, "globus_cond_destroy", gResult); ret = NGEM_FAILED; } return ret; }
/** * Module deactivation * */ static int globus_l_openssl_deactivate(void) { int i; OBJ_cleanup(); ERR_clear_error(); X509V3_EXT_cleanup(); if (CRYPTO_get_id_callback() == globus_l_openssl_thread_id) { CRYPTO_set_id_callback(NULL); } if (CRYPTO_get_locking_callback() == globus_l_openssl_locking_cb) { CRYPTO_set_locking_callback(NULL); } for (i=0; i<CRYPTO_num_locks(); i++) { globus_mutex_destroy(&(mutex_pool[i])); } free(mutex_pool); globus_module_deactivate(GLOBUS_GSI_OPENSSL_ERROR_MODULE); globus_module_deactivate(GLOBUS_COMMON_MODULE); return GLOBUS_SUCCESS; }
/** * @brief Initialize a recursive mutex * @ingroup globus_mutex * * @details * The globus_rmutex_init() function initializes a recursive mutex, * that is, one which may be locked multiple times by a single thread * without causing deadlock. * @param rmutex * A pointer to the mutex to initialize * @param rattr * IGNORED * * @return * On success, globus_rmutex_init() initializes the mutex and returns * GLOBUS_SUCCESS; otherwise, it returns a non-zero error code. */ int globus_rmutex_init( globus_rmutex_t * rmutex, globus_rmutexattr_t * rattr) { int rc; rc = globus_mutex_init(&rmutex->mutex, GLOBUS_NULL); if(rc) { goto err_init; } rc = globus_cond_init(&rmutex->cond, GLOBUS_NULL); if(rc) { goto err_cond; } rmutex->level = 0; memset(&rmutex->thread_id,0,sizeof(rmutex->thread_id)); rmutex->waiting = 0; return 0; err_cond: globus_mutex_destroy(&rmutex->mutex); err_init: return rc; }
/** * @brief Destroy a recursive mutex * @ingroup globus_mutex * * @details * The globus_rmutex_destroy() function destroys a recursive mutex * If the mutex is currently locked, behavior is undefined. * * @param rmutex * Mutex to unlock * * @return GLOBUS_SUCCESS */ int globus_rmutex_destroy( globus_rmutex_t * rmutex) { globus_mutex_destroy(&rmutex->mutex); globus_cond_destroy(&rmutex->cond); return 0; }
static void globus_l_xio_pipe_handle_destroy( xio_l_pipe_handle_t * handle) { GlobusXIOName(globus_l_xio_pipe_handle_destroy); GlobusXIOPipeDebugEnter(); globus_mutex_destroy(&handle->lock); globus_free(handle); GlobusXIOPipeDebugExit(); }
/****************************************************************************** Function: globus_l_gass_server_ez_deactivate() Description: Parameters: Returns: ******************************************************************************/ static int globus_l_gass_server_ez_deactivate(void) { int rc = GLOBUS_SUCCESS; globus_mutex_destroy(&globus_l_gass_server_ez_mutex); /*rc = globus_module_deactivate(GLOBUS_GASS_TRANSFER_MODULE); globus_hashtable_destroy(&globus_l_gass_server_ez_listeners); rc|=globus_module_deactivate(GLOBUS_COMMON_MODULE);*/ return rc; } /* globus_l_gass_server_ez_deactivate() */
static void globus_l_xio_telnet_close_cb( globus_xio_operation_t op, globus_result_t result, void * user_arg) { globus_l_xio_telnet_handle_t * handle; handle = (globus_l_xio_telnet_handle_t *) user_arg; globus_xio_driver_finished_close(op, result); globus_free(handle->read_buffer); globus_fifo_destroy(&handle->write_q); globus_mutex_destroy(&handle->mutex); globus_free(handle); }
static void gfs_l_xio_cp_close_os( void * user_arg) { gfs_i_xio_cp_handle_t * cp_h; cp_h = (gfs_i_xio_cp_handle_t *) user_arg; cp_h->complete_cb(cp_h, cp_h->user_arg, cp_h->err_obj); globus_fifo_destroy(cp_h->read_all_q); globus_fifo_destroy(cp_h->write_all_q); globus_fifo_destroy(cp_h->write_q); globus_mutex_destroy(cp_h->mutex); globus_free(cp_h); }
void gridftp_destroy(gridftp_t * GridFTP) { GlobusGFSName(__func__); GlobusGFSHpssDebugEnter(); if (GridFTP != NULL) { /* Destroy the file range lists. */ range_list_destroy(GridFTP->StreamRanges); globus_mutex_destroy(&GridFTP->Lock); globus_cond_destroy(&GridFTP->Cond); globus_free(GridFTP); } GlobusGFSHpssDebugExit(); }
static void gfork_l_child_read_close_cb( globus_xio_handle_t xio_handle, globus_result_t result, void * user_arg) { gfork_i_lib_handle_t * handle; globus_result_t user_res; handle = (gfork_i_lib_handle_t *) user_arg; user_res = globus_error_put(handle->error_obj); handle->error_cb(handle, handle->user_arg, user_res); globus_mutex_destroy(&handle->mutex); globus_free(handle); }
globus_result_t globus_ftp_client_restart_marker_plugin_destroy( globus_ftp_client_plugin_t * plugin) { globus_result_t result; restart_marker_plugin_info_t * ps; GlobusFuncName(globus_ftp_client_restart_marker_plugin_destroy); if(plugin == GLOBUS_NULL) { return globus_error_put(globus_error_construct_string( GLOBUS_FTP_CLIENT_MODULE, GLOBUS_NULL, "[%s] NULL plugin at %s\n", GLOBUS_FTP_CLIENT_MODULE->module_name, _globus_func_name)); } result = globus_ftp_client_plugin_get_plugin_specific( plugin, (void **) (void *) &ps); if(result != GLOBUS_SUCCESS) { return result; } if(ps->error_obj) { globus_object_free(ps->error_obj); ps->error_obj = GLOBUS_NULL; } if(ps->error_url) { globus_libc_free(ps->error_url); ps->error_url = GLOBUS_NULL; } globus_mutex_destroy(&ps->lock); globus_free(ps); return globus_ftp_client_plugin_destroy(plugin); }
/** * Operator: Initialize */ ngemResult_t ngrcOperatorInitialize( ngrcOperator_t *op, globus_xio_handle_t handle) { globus_result_t gResult; ngLog_t *log; bool mutexInitialized = false; NGEM_FNAME(ngrcOperatorInitialize); log = ngemLogGetDefault(); NGEM_ASSERT(op != NULL); NGEM_ASSERT(handle != NULL); op->ngo_handle = handle; op->ngo_canceled = false; gResult = globus_mutex_init(&op->ngo_mutex, NULL); if (gResult != GLOBUS_SUCCESS) { ngcpLogGlobusError(log, NGRC_LOGCAT_GT, fName, "globus_mutex_init", gResult); goto error; } mutexInitialized = true; globus_cond_init(&op->ngo_cond, NULL); if (gResult != GLOBUS_SUCCESS) { ngcpLogGlobusError(log, NGRC_LOGCAT_GT, fName, "globus_cond_init", gResult); goto error; } return NGEM_SUCCESS; error: if (mutexInitialized) { gResult = globus_mutex_destroy(&op->ngo_mutex); if (gResult != GLOBUS_SUCCESS) { ngcpLogGlobusError(log, NGRC_LOGCAT_GT, fName, "globus_mutex_destroy", gResult); } } return NGEM_FAILED; }
/** * Module deactivation */ static int globus_l_gsi_gss_assist_deactivate(void) { static char * _function_name_ = "globus_l_gsi_gss_assist_deactivate"; GLOBUS_I_GSI_GSS_ASSIST_DEBUG_ENTER; globus_mutex_destroy(&globus_i_gsi_gss_assist_mutex); globus_module_deactivate(GLOBUS_GSI_GSSAPI_MODULE); globus_module_deactivate(GLOBUS_GSI_SYSCONFIG_MODULE); globus_module_deactivate(GLOBUS_CALLOUT_MODULE); globus_module_deactivate(GLOBUS_COMMON_MODULE); GLOBUS_I_GSI_GSS_ASSIST_DEBUG_EXIT; return GLOBUS_SUCCESS; }
/************************************************************************ * iface functions * --------------- * ***********************************************************************/ static void globus_l_xio_telnet_open_cb( globus_xio_operation_t op, globus_result_t result, void * user_arg) { globus_l_xio_telnet_handle_t * handle; handle = (globus_l_xio_telnet_handle_t *) user_arg; if(result != GLOBUS_SUCCESS) { globus_fifo_destroy(&handle->write_q); globus_free(handle->read_buffer); globus_mutex_destroy(&handle->mutex); globus_free(handle); } globus_xio_driver_finished_open(handle, op, result); }
void globus_usage_stats_handle_destroy( globus_usage_stats_handle_t vhandle) { #ifndef TARGET_ARCH_ARM globus_i_usage_stats_handle_t * handle = (globus_i_usage_stats_handle_t *) vhandle; if(handle) { if(handle->targets) { globus_list_destroy_all(handle->targets, globus_libc_free); } if(handle->xio_desc_list) { globus_xio_data_descriptor_t * dd; while (!globus_list_empty (handle->xio_desc_list)) { if((dd = globus_list_remove( &handle->xio_desc_list, handle->xio_desc_list)) != NULL) { globus_xio_data_descriptor_destroy(*dd); globus_free(dd); } } } if(handle->xio_handle) { globus_xio_close(handle->xio_handle, NULL); } globus_mutex_destroy(&handle->mutex); globus_free(handle); } #endif }
int main( int argc, char ** argv) { globus_xio_stack_t stack; globus_xio_stack_t mode_e_stack; globus_xio_handle_t xio_handle; globus_xio_server_t server; globus_xio_attr_t attr = NULL; char * cs = NULL; globus_result_t res; int ctr; int num_streams = 1; globus_bool_t be_server = GLOBUS_FALSE; int rc; char filename[FILE_NAME_LEN]; FILE * fp; rc = globus_module_activate(GLOBUS_XIO_MODULE); globus_assert(rc == GLOBUS_SUCCESS); res = globus_xio_driver_load("mode_e", &mode_e_driver); test_res(res); res = globus_xio_driver_load("ordering", &ordering_driver); test_res(res); res = globus_xio_stack_init(&stack, NULL); test_res(res); res = globus_xio_stack_push_driver(stack, mode_e_driver); test_res(res); res = globus_xio_stack_push_driver(stack, ordering_driver); test_res(res); res = globus_xio_driver_load("tcp", &tcp_driver); test_res(res); res = globus_xio_stack_init(&mode_e_stack, NULL); test_res(res); res = globus_xio_stack_push_driver(mode_e_stack, tcp_driver); test_res(res); if (argc < 4) { help(); exit(1); } test_res(globus_xio_attr_init(&attr)); test_res(globus_xio_attr_cntl( attr, mode_e_driver, GLOBUS_XIO_MODE_E_SET_STACK, mode_e_stack)); for(ctr = 1; ctr < argc; ctr++) { if(strcmp(argv[ctr], "-h") == 0) { help(); return 0; } else if(strcmp(argv[ctr], "-c") == 0) { if (argc < 5) { help(); exit(1); } cs = argv[ctr + 1]; ctr++; } else if(strcmp(argv[ctr], "-s") == 0) { be_server = GLOBUS_TRUE; } else if(strcmp(argv[ctr], "-p") == 0) { if (argc < 6) { help(); exit(1); } port = atoi(argv[ctr+1]); /* test_res(globus_xio_attr_cntl( attr, mode_e_driver, GLOBUS_XIO_MODE_E_APPLY_ATTR_CNTLS, attr_cntl_cb));*/ } else if(strcmp(argv[ctr], "-P") == 0) { if (argc < 6) { help(); exit(1); } num_streams = atoi(argv[ctr+1]); test_res(globus_xio_attr_init(&attr)); test_res(globus_xio_attr_cntl( attr, ordering_driver, GLOBUS_XIO_ORDERING_SET_MAX_READ_COUNT, num_streams)); test_res(globus_xio_attr_cntl( attr, mode_e_driver, GLOBUS_XIO_MODE_E_SET_NUM_STREAMS, num_streams)); } else if(strcmp(argv[ctr], "-f") == 0) { if (ctr + 1 < argc) { strcpy(filename, argv[ctr + 1]); } else { help(); exit(1); } } } if (!be_server && (!cs || !*cs)) { help(); exit(1); } if(be_server) { globus_size_t size = CHUNK_SIZE + 1; int i, nbytes; res = globus_xio_server_create(&server, attr, stack); test_res(res); globus_xio_server_get_contact_string(server, &cs); fprintf(stdout, "Contact: %s\n", cs); res = globus_xio_server_accept(&xio_handle, server); test_res(res); res = globus_xio_open(xio_handle, NULL, attr); test_res(res); fp = fopen(filename, "w"); while(1) { char * buffer; buffer = (char *) globus_malloc(size); for (i=0; i<size; i++) buffer[i] = '\0'; res = globus_xio_read( xio_handle, buffer, size - 1, 1, &nbytes, NULL); fputs(buffer, fp); if (res != GLOBUS_SUCCESS) break; } res = globus_xio_close(xio_handle, NULL); test_res(res); res = globus_xio_server_close(server); test_res(res); res = globus_xio_driver_unload(mode_e_driver); test_res(res); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == GLOBUS_SUCCESS); } else { globus_size_t size = CHUNK_SIZE + 1; int nbytes; int i,x; res = globus_xio_handle_create(&xio_handle, stack); test_res(res); res = globus_xio_stack_destroy(stack); test_res(res); res = globus_xio_open(xio_handle, cs, attr); test_res(res); globus_mutex_init(&mutex, NULL); globus_cond_init(&cond, NULL); fp = fopen(filename, "r"); globus_mutex_lock(&mutex); while(!feof(fp)) { char * buffer; buffer = (char *) globus_malloc(size); for (i = 0; i < size; i++) buffer[i] = '\0'; x = fread(buffer, CHUNK_SIZE, 1, fp); nbytes = strlen(buffer); res = globus_xio_register_write( xio_handle, buffer, nbytes, nbytes, NULL, write_cb, NULL); test_res(res); ++y; } fclose(fp); /* test_res(globus_xio_data_descriptor_init(&dd, xio_handle)); test_res(globus_xio_data_descriptor_cntl( dd, mode_e_driver, GLOBUS_XIO_MODE_E_SEND_EOD, GLOBUS_TRUE)); res = globus_xio_write( xio_handle, buffer, nbytes, nbytes, &nbytes, NULL); test_res(res); */ while(y) { globus_cond_wait(&mutex, &cond); } globus_mutex_unlock(&mutex); res = globus_xio_close(xio_handle, attr); test_res(res); res = globus_xio_driver_unload(mode_e_driver); test_res(res); res = globus_xio_driver_unload(ordering_driver); test_res(res); rc = globus_module_deactivate(GLOBUS_XIO_MODULE); globus_assert(rc == GLOBUS_SUCCESS); globus_mutex_destroy(&mutex); globus_cond_destroy(&cond); } return 0; }
static globus_result_t globus_l_xio_telnet_open( const globus_xio_contact_t * contact_info, void * driver_link, void * driver_attr, globus_xio_operation_t op) { globus_result_t res; globus_l_xio_telnet_attr_t * attr; globus_l_xio_telnet_handle_t * handle; GlobusXIOName(globus_l_xio_telnet_open); /* decide what attr to use */ if(driver_attr != NULL) { attr = (globus_l_xio_telnet_attr_t *) driver_attr; } else if(driver_link != NULL) { attr = (globus_l_xio_telnet_attr_t *) driver_link; } else { /* default */ attr = NULL; } handle = (globus_l_xio_telnet_handle_t *) globus_calloc( sizeof(globus_l_xio_telnet_handle_t), 1); if(handle == NULL) { res = GlobusXIOErrorMemory("handle"); goto error_handle_alloc; } if(attr != NULL && attr->force_server) { handle->client = GLOBUS_FALSE; } else { handle->client = driver_link ? GLOBUS_FALSE : GLOBUS_TRUE; } handle->read_buffer_length = GLOBUS_L_XIO_TELNET_DEFAULT_BUFFER_SIZE; handle->read_buffer = globus_malloc(handle->read_buffer_length); if(handle->read_buffer == NULL) { res = GlobusXIOErrorMemory("buffer"); goto error_buffer_alloc; } globus_mutex_init(&handle->mutex, NULL); globus_fifo_init(&handle->write_q); handle->create_buffer_mode = attr ? attr->create_buffer_mode : GLOBUS_FALSE; res = globus_xio_driver_pass_open( op, contact_info, globus_l_xio_telnet_open_cb, handle); if(res != GLOBUS_SUCCESS) { goto error_pass; } return GLOBUS_SUCCESS; error_pass: globus_free(handle->read_buffer); globus_mutex_destroy(&handle->mutex); globus_fifo_destroy(&handle->write_q); error_buffer_alloc: globus_free(handle); error_handle_alloc: return res; }
static int globus_l_job_manager_module_activate(void) { time_t timestamp_val; globus_l_job_manager_logfile_state_t * logfile_state; int rc; globus_reltime_t delay; globus_result_t result; char * scheduler; rc = globus_module_activate(GLOBUS_COMMON_MODULE); if (rc != GLOBUS_SUCCESS) { goto activate_common_failed; } rc = globus_mutex_init(&globus_l_job_manager_mutex, NULL); if (rc != GLOBUS_SUCCESS) { goto mutex_init_failed; } rc = globus_cond_init(&globus_l_job_manager_cond, NULL); if (rc != GLOBUS_SUCCESS) { goto cond_init_failed; } shutdown_called = GLOBUS_FALSE; callback_count = 0; GlobusDebugInit( SEG_JOB_MANAGER, SEG_JOB_MANAGER_DEBUG_INFO SEG_JOB_MANAGER_DEBUG_WARN SEG_JOB_MANAGER_DEBUG_ERROR SEG_JOB_MANAGER_DEBUG_TRACE); logfile_state = calloc(1, sizeof(globus_l_job_manager_logfile_state_t)); if (logfile_state == NULL) { goto calloc_state_failed; } /* Configuration info */ result = globus_scheduler_event_generator_get_timestamp(×tamp_val); if (result != GLOBUS_SUCCESS) { goto get_timestamp_failed; } if (timestamp_val != 0) { if (globus_libc_gmtime_r( ×tamp_val, &logfile_state->start_timestamp) == NULL) { goto gmtime_failed; } } scheduler = globus_libc_getenv(JOB_MANAGER_SEG_SCHEDULER); if (scheduler == NULL) { SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_ERROR, ("Error: %s not set\n", JOB_MANAGER_SEG_SCHEDULER)); result = GLOBUS_FAILURE; goto get_scheduler_failed; } if (getenv(JOB_MANAGER_SEG_LOG_PATH)) { logfile_state->log_dir = strdup(getenv(JOB_MANAGER_SEG_LOG_PATH)); } else { char * log_dir_pattern = globus_common_create_string( "${localstatedir}/lib/globus/globus-seg-%s", scheduler); globus_eval_path(log_dir_pattern, &logfile_state->log_dir); free(log_dir_pattern); } if (logfile_state->log_dir == NULL) { SEG_JOB_MANAGER_DEBUG(SEG_JOB_MANAGER_DEBUG_ERROR, ("Error: out of memory\n")); goto get_path_failed; } /* Convert timestamp to filename */ rc = globus_l_job_manager_find_logfile(logfile_state); if (rc == GLOBUS_SUCCESS) { logfile_state->fp = fopen(logfile_state->path, "r"); if (logfile_state->fp == NULL) { rc = SEG_JOB_MANAGER_ERROR_OUT_OF_MEMORY; goto fopen_failed; } GlobusTimeReltimeSet(delay, 0, 0); } else if(rc == SEG_JOB_MANAGER_ERROR_LOG_NOT_PRESENT) { GlobusTimeReltimeSet(delay, 1, 0); } else { goto bad_log_path; } result = globus_callback_register_oneshot( &logfile_state->callback, &delay, globus_l_job_manager_poll_callback, logfile_state); if (result != GLOBUS_SUCCESS) { goto oneshot_failed; } callback_count++; return 0; oneshot_failed: if (logfile_state->fp) { fclose(logfile_state->fp); } fopen_failed: if (logfile_state->path) { free(logfile_state->path); } bad_log_path: free(logfile_state->log_dir); get_path_failed: get_scheduler_failed: get_timestamp_failed: gmtime_failed: free(logfile_state); calloc_state_failed: globus_cond_destroy(&globus_l_job_manager_cond); cond_init_failed: globus_mutex_destroy(&globus_l_job_manager_mutex); mutex_init_failed: globus_module_deactivate(GLOBUS_COMMON_MODULE); activate_common_failed: return 1; }
virtual ~mutex() { globus_mutex_destroy(&mutex_); }
int main( int argc, char * argv[]) { int i; int nitems; long thread_id; globus_thread_t thread; globus_thread_set_model("pthread"); globus_module_activate(GLOBUS_COMMON_MODULE); if (argc != 4) { globus_stdio_lock(); { printf("\nusage: globus_thread_test " "nproducers nconsumers nitems\n\n"); } globus_stdio_unlock(); exit(1); } nproducers = atoi(argv[1]); nconsumers = atoi(argv[2]); nitems = atoi(argv[3]); /* * Initialize queue and queue concurrency control structures */ globus_fifo_init(&queue); globus_mutex_init(&queue_mutex, (globus_mutexattr_t *) GLOBUS_NULL); globus_cond_init(&queue_cond, (globus_condattr_t *) GLOBUS_NULL); /* * Initialize shared (common) concurrency control structures */ globus_mutex_init(&common_mutex, (globus_mutexattr_t *) GLOBUS_NULL); globus_cond_init(&common_cond, (globus_condattr_t *) GLOBUS_NULL); /* * Assign a thread id to the main thread so that it's output is uniquely * tagged. Note: we do not use the return value of globus_thread_self() * since it could be a pointer or a structure, the latter which is * extremely hard to print without knowing the implementation details. */ thread_id_assign(); thread_id = thread_id_get(); /* * Start producer and consumer threads */ globus_stdio_lock(); { printf("%04ld: main() - starting %d producer and %d consumer threads\n", thread_id, nproducers, nconsumers); } globus_stdio_unlock(); for (i = 0 ; i < nproducers ; i ++) { int rc; int nitems_per_thread; nitems_per_thread = nitems / nproducers + ((i < nitems % nproducers) ? 1 : 0); rc = globus_thread_create( &thread, NULL, producer, (void *) nitems_per_thread); if (rc != 0) { globus_stdio_lock(); { printf("%04ld: main() - ERROR: " "unable to create producer thread %d\n", thread_id, i); exit(1); } globus_stdio_unlock(); } } for (i = 0 ; i < nconsumers ; i ++) { int rc; int nitems_per_thread; nitems_per_thread = nitems / nconsumers + ((i < nitems % nconsumers) ? 1 : 0); rc = globus_thread_create( &thread, NULL, consumer, (void *) nitems_per_thread); if (rc != 0) { globus_stdio_lock(); { printf("%04ld: main() - ERROR: " "unable to create consumer thread %d\n", thread_id, i); exit(1); } globus_stdio_unlock(); } } /* * Wait for all threads to be started */ wait_for_all(); globus_stdio_lock(); { printf("%04ld: main() - all threads started\n", thread_id); } globus_stdio_unlock(); /* * Wait for all threads to complete their work */ wait_for_all(); globus_stdio_lock(); { printf("%04ld: main() - all threads have completed their work\n", thread_id); } globus_stdio_unlock(); /* * Wait for all thread id data to be destroyed */ while (thread_ids_destruct_cnt < nproducers + nconsumers) { globus_thread_yield(); } globus_stdio_lock(); { printf("%04ld: main() - all threads terminated\n", thread_id); } globus_stdio_unlock(); globus_cond_destroy(&common_cond); globus_mutex_destroy(&common_mutex); globus_cond_destroy(&queue_cond); globus_mutex_destroy(&queue_mutex); globus_fifo_destroy(&queue); globus_module_deactivate(GLOBUS_COMMON_MODULE); exit(0); }
void * producer( void * nitems_arg) { long i; long nitems; prod_data_t data; long thread_id; nitems = (long) nitems_arg; globus_mutex_init(&data.mutex, (globus_mutexattr_t *) GLOBUS_NULL); globus_cond_init(&data.cond, (globus_condattr_t *) GLOBUS_NULL); thread_id_assign(); thread_id = thread_id_get(); wait_for_all(); for (i = 0; i < nitems ; i++) { data.done = GLOBUS_FALSE; globus_mutex_lock(&queue_mutex); { globus_fifo_enqueue(&queue, &data); globus_cond_signal(&queue_cond); } globus_mutex_unlock(&queue_mutex); globus_mutex_lock(&data.mutex); { while(data.done == GLOBUS_FALSE) { # if (DEBUG_LEVEL > 1) { globus_stdio_lock(); { printf("%04ld: producer() - " "waiting for confirmation %d\n", thread_id, i); } globus_stdio_unlock(); } # endif globus_cond_wait(&data.cond, &data.mutex); } } globus_mutex_unlock(&data.mutex); } globus_cond_destroy(&data.cond); globus_mutex_destroy(&data.mutex); wait_for_all(); return NULL; }
/* * Timeout test: * -t server|client * Configure the server or client to cause a timeout. If server is * selected, then it will delay its part of the operation longer than the * timeout value, causing the client to time out (and vice versa). * -T timeout-in-ms * Set the timeout value in ms * -a * Expect / cause the accept operation to delay longer than the timeout. * -r * Expect / cause a read operation to delay longer than the timeout. * */ int main( int argc, char * argv[]) { int rc; char * contact = NULL; globus_result_t result; globus_l_timeout_info_t client_timeout_info; globus_l_timeout_info_t server_timeout_info; globus_reltime_t timeout; client_timeout_info.cause_timeout = GLOBUS_TRUE; client_timeout_info.expect_timeout = GLOBUS_FALSE; server_timeout_info.cause_timeout = GLOBUS_FALSE; server_timeout_info.expect_timeout = GLOBUS_TRUE; client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; server_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; client_timeout_info.timeout = 1000; server_timeout_info.timeout = 1000; while ((rc = getopt(argc, argv, "t:T:arh")) != EOF) { switch (rc) { case 'h': usage(argv[0]); exit(0); case 't': if (strcmp(optarg, "client") == 0) { client_timeout_info.cause_timeout = GLOBUS_TRUE; client_timeout_info.expect_timeout = GLOBUS_FALSE; server_timeout_info.cause_timeout = GLOBUS_FALSE; server_timeout_info.expect_timeout = GLOBUS_TRUE; } else if (strcmp(optarg, "server") == 0) { client_timeout_info.cause_timeout = GLOBUS_FALSE; client_timeout_info.expect_timeout = GLOBUS_TRUE; server_timeout_info.cause_timeout = GLOBUS_TRUE; server_timeout_info.expect_timeout = GLOBUS_FALSE; } else { usage(argv[0]); exit(1); } break; case 'T': client_timeout_info.timeout = atoi(optarg); server_timeout_info.timeout = atoi(optarg); break; case 'a': client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; server_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; break; case 'r': client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_READ; server_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_READ; break; default: usage(argv[0]); exit(1); } } rc = http_test_initialize( &globus_l_tcp_driver, &globus_l_http_driver, &globus_l_http_stack); if (rc != GLOBUS_SUCCESS) { exit(2); } globus_mutex_init(&lock, NULL); globus_cond_init(&cond, NULL); GlobusTimeReltimeSet(timeout, 0, (server_timeout_info.timeout * 1000)); globus_xio_attr_init(&client_timeout_info.attr); globus_xio_attr_init(&server_timeout_info.attr); switch (server_timeout_info.timeout_state) { case GLOBUS_XIO_OPERATION_TYPE_ACCEPT: if (client_timeout_info.cause_timeout) { globus_xio_attr_cntl( server_timeout_info.attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_ACCEPT, globus_l_timeout_callback, &timeout, NULL); } else { fprintf(stderr, "Unable to handle server-caused accept timeout\n"); exit(6); } break; case GLOBUS_XIO_OPERATION_TYPE_READ: if (client_timeout_info.cause_timeout) { globus_xio_attr_cntl( server_timeout_info.attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_READ, globus_l_timeout_callback, &timeout, NULL); } else { globus_xio_attr_cntl( client_timeout_info.attr, NULL, GLOBUS_XIO_ATTR_SET_TIMEOUT_READ, globus_l_timeout_callback, &timeout, NULL); } break; default: fprintf(stderr, "Error: invalid timeout state\n"); exit(3); } /* Set up client attributes */ globus_xio_attr_cntl( client_timeout_info.attr, globus_l_http_driver, GLOBUS_XIO_HTTP_ATTR_SET_REQUEST_METHOD, "POST"); /* Modulate timeout state to causer's related state for delaying */ if (client_timeout_info.cause_timeout) { switch (client_timeout_info.timeout_state) { case GLOBUS_XIO_OPERATION_TYPE_ACCEPT: client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_OPEN; break; case GLOBUS_XIO_OPERATION_TYPE_READ: client_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_WRITE; break; case GLOBUS_XIO_OPERATION_TYPE_WRITE: case GLOBUS_XIO_OPERATION_TYPE_OPEN: case GLOBUS_XIO_OPERATION_TYPE_CLOSE: case GLOBUS_XIO_OPERATION_TYPE_FINISHED: case GLOBUS_XIO_OPERATION_TYPE_NONE: case GLOBUS_XIO_OPERATION_TYPE_DRIVER: case GLOBUS_XIO_OPERATION_TYPE_DD: case GLOBUS_XIO_OPERATION_TYPE_SERVER_INIT: fprintf(stderr, "Error: unexpected state: %d\n", client_timeout_info.state); exit(4); } } else { globus_assert(server_timeout_info.cause_timeout); switch (server_timeout_info.timeout_state) { case GLOBUS_XIO_OPERATION_TYPE_ACCEPT: fprintf(stderr, "Invalid option (server-caused accept timeout)\n"); exit(5); case GLOBUS_XIO_OPERATION_TYPE_READ: server_timeout_info.timeout_state = GLOBUS_XIO_OPERATION_TYPE_WRITE; break; case GLOBUS_XIO_OPERATION_TYPE_WRITE: case GLOBUS_XIO_OPERATION_TYPE_OPEN: case GLOBUS_XIO_OPERATION_TYPE_CLOSE: case GLOBUS_XIO_OPERATION_TYPE_FINISHED: case GLOBUS_XIO_OPERATION_TYPE_NONE: case GLOBUS_XIO_OPERATION_TYPE_DRIVER: case GLOBUS_XIO_OPERATION_TYPE_DD: case GLOBUS_XIO_OPERATION_TYPE_SERVER_INIT: fprintf(stderr, "Error: unexpected state: %d\n", server_timeout_info.state); exit(4); } } /* create server */ server_timeout_info.state = GLOBUS_XIO_OPERATION_TYPE_ACCEPT; server_timeout_info.handle = NULL; server_timeout_info.result = GLOBUS_SUCCESS; server_timeout_info.contact = NULL; result = globus_xio_server_create( &server_timeout_info.server, server_timeout_info.attr, globus_l_http_stack); result = globus_xio_server_get_contact_string( server_timeout_info.server, &contact); client_timeout_info.contact = globus_common_create_string("http://%s/%s", contact, "ok"); /* create client handle */ client_timeout_info.state = GLOBUS_XIO_OPERATION_TYPE_OPEN; client_timeout_info.handle = NULL; client_timeout_info.result = GLOBUS_SUCCESS; client_timeout_info.server = NULL; result = globus_xio_handle_create( &client_timeout_info.handle, globus_l_http_stack); /* oneshot to start server state machine */ result = globus_callback_register_oneshot( NULL, &globus_i_reltime_zero, state_machine, &server_timeout_info); /* oneshot to start client state machine */ result = globus_callback_register_oneshot( NULL, &globus_i_reltime_zero, state_machine, &client_timeout_info); /* wait for both state machines to terminate */ globus_mutex_lock(&lock); while (client_timeout_info.state != GLOBUS_XIO_OPERATION_TYPE_NONE && server_timeout_info.state != GLOBUS_XIO_OPERATION_TYPE_NONE) { globus_cond_wait(&cond, &lock); } globus_mutex_unlock(&lock); globus_mutex_destroy(&lock); globus_module_deactivate_all(); return (client_timeout_info.result || server_timeout_info.result || client_timeout_info.expect_timeout || server_timeout_info.expect_timeout); }
globus_result_t globus_ftp_client_restart_marker_plugin_init( globus_ftp_client_plugin_t * plugin, globus_ftp_client_restart_marker_plugin_begin_cb_t begin_cb, globus_ftp_client_restart_marker_plugin_marker_cb_t marker_cb, globus_ftp_client_restart_marker_plugin_complete_cb_t complete_cb, void * user_arg) { restart_marker_plugin_info_t * ps; globus_result_t result; GlobusFuncName(globus_ftp_client_restart_marker_plugin_init); if(plugin == GLOBUS_NULL) { return globus_error_put(globus_error_construct_string( GLOBUS_FTP_CLIENT_MODULE, GLOBUS_NULL, "[%s] NULL plugin at %s\n", GLOBUS_FTP_CLIENT_MODULE->module_name, _globus_func_name)); } ps = (restart_marker_plugin_info_t *) globus_malloc(sizeof(restart_marker_plugin_info_t)); if(ps == GLOBUS_NULL) { return globus_error_put(globus_error_construct_string( GLOBUS_FTP_CLIENT_MODULE, GLOBUS_NULL, "[%s] Out of memory at %s\n", GLOBUS_FTP_CLIENT_MODULE->module_name, _globus_func_name)); } /* * initialize plugin specific structure. */ ps->user_arg = user_arg; ps->begin_cb = begin_cb; ps->marker_cb = marker_cb; ps->complete_cb = complete_cb; ps->error_url = GLOBUS_NULL; ps->error_obj = GLOBUS_NULL; globus_mutex_init(&ps->lock, GLOBUS_NULL); result = globus_ftp_client_plugin_init( plugin, GLOBUS_L_FTP_CLIENT_RESTART_MARKER_PLUGIN_NAME, GLOBUS_FTP_CLIENT_CMD_MASK_FILE_ACTIONS, ps); if(result != GLOBUS_SUCCESS) { globus_mutex_destroy(&ps->lock); globus_free(ps); return result; } globus_ftp_client_plugin_set_destroy_func(plugin, restart_marker_plugin_destroy_cb); globus_ftp_client_plugin_set_copy_func(plugin, restart_marker_plugin_copy_cb); globus_ftp_client_plugin_set_get_func(plugin, restart_marker_plugin_get_cb); globus_ftp_client_plugin_set_data_func(plugin, restart_marker_plugin_data_cb); globus_ftp_client_plugin_set_put_func(plugin, restart_marker_plugin_put_cb); globus_ftp_client_plugin_set_third_party_transfer_func(plugin, restart_marker_plugin_transfer_cb); globus_ftp_client_plugin_set_response_func(plugin, restart_marker_plugin_response_cb); globus_ftp_client_plugin_set_complete_func(plugin, restart_marker_plugin_complete_cb); globus_ftp_client_plugin_set_fault_func(plugin, restart_marker_plugin_fault_cb); globus_ftp_client_plugin_set_abort_func(plugin, restart_marker_plugin_abort_cb); return GLOBUS_SUCCESS; }
int main() { gss_cred_id_t credential; int listen_fd; int accept_fd; struct sockaddr_in address = {0}; globus_sockaddr_t connect_address; globus_socklen_t connect_address_len = sizeof(connect_address); struct thread_arg * arg = NULL; globus_thread_t thread_handle; int i; int ret; int error; LTDL_SET_PRELOADED_SYMBOLS(); globus_thread_set_model(THREAD_MODEL); globus_module_activate(GLOBUS_COMMON_MODULE); globus_module_activate(GLOBUS_GSI_GSSAPI_MODULE); printf("1..%d\n", NUM_CLIENTS); /* initialize global mutex */ globus_mutex_init(&mutex, NULL); /* and the condition variable */ globus_cond_init(&done, NULL); /* setup listener */ address.sin_family = AF_INET; address.sin_port = 0; address.sin_addr.s_addr = htonl(INADDR_LOOPBACK); listen_fd = socket(AF_INET, SOCK_STREAM, 0); if (listen_fd == 0) { perror("socket"); exit(EXIT_FAILURE); } ret = bind(listen_fd, (struct sockaddr *) &address, sizeof(struct sockaddr_in)); if (ret != 0) { perror("bind"); exit(EXIT_FAILURE); } ret = getsockname(listen_fd, (struct sockaddr *) &connect_address, &connect_address_len); if (ret != 0) { perror("getsockname"); exit(EXIT_FAILURE); } ret = listen(listen_fd, -1); if (ret != 0) { perror("listen"); exit(EXIT_FAILURE); } /* acquire credentials */ credential = globus_gsi_gssapi_test_acquire_credential(); if(credential == GSS_C_NO_CREDENTIAL) { fprintf(stderr,"Unable to aquire credential\n"); exit(-1); } /* start the clients here */ for(i=0;i<NUM_CLIENTS;i++) { arg = malloc(sizeof(struct thread_arg)); arg->address = &connect_address; arg->len = connect_address_len; arg->credential = credential; globus_mutex_lock(&mutex); { client_thread_count++; } globus_mutex_unlock(&mutex); globus_thread_create(&thread_handle,NULL,client_func,(void *) arg); } /* accept connections */ globus_mutex_lock(&mutex); while (client_thread_count > 0) { while (pending_connects > 0) { accept_fd = accept(listen_fd,NULL,0); if(accept_fd < 0) { perror("accept"); abort(); } arg = malloc(sizeof(struct thread_arg)); arg->fd = accept_fd; arg->credential = credential; server_thread_count++; pending_connects--; globus_thread_create(&thread_handle,NULL,server_func,(void *) arg); } globus_cond_wait(&done, &mutex); } /* wait for last thread to terminate */ while (server_thread_count > 0) { globus_cond_wait(&done, &mutex); } globus_mutex_unlock(&mutex); /* destroy global mutex */ globus_mutex_destroy(&mutex); /* and the condition variable */ globus_cond_destroy(&done); /* close the listener */ close(listen_fd); /* release credentials */ globus_gsi_gssapi_test_release_credential(&credential); globus_module_deactivate_all(); exit(client_failed); }
static globus_result_t globus_l_gfork_child_start( gfork_child_handle_t * out_handle, const char * in_env_suffix, globus_gfork_open_func_t open_cb, globus_gfork_closed_func_t close_cb, globus_gfork_incoming_cb_t incoming_cb, globus_gfork_error_func_t error_cb, void * user_arg, globus_bool_t master) { globus_result_t result; gfork_i_lib_handle_t * handle; char * env; char * env_suffix; int read_fd; int write_fd; handle = (gfork_i_lib_handle_t *) globus_calloc(1, sizeof(gfork_i_lib_handle_t)); handle->state = GFORK_STATE_OPEN; handle->open_cb = open_cb; handle->close_cb = close_cb; handle->error_cb = error_cb; handle->incoming_cb = incoming_cb; handle->user_arg = user_arg; handle->master = master; globus_mutex_init(&handle->mutex, NULL); globus_fifo_init(&handle->write_q); if(in_env_suffix == NULL) { env_suffix = ""; } else { env_suffix = (char *) in_env_suffix; } env = globus_common_create_string("%s%s", GFORK_CHILD_READ_ENV, env_suffix); result = gfork_l_get_env_fd(env, &read_fd); globus_free(env); if(result != GLOBUS_SUCCESS) { goto error_read_env; } env = globus_common_create_string("%s%s",GFORK_CHILD_WRITE_ENV,env_suffix); result = gfork_l_get_env_fd(env, &write_fd); globus_free(env); if(result != GLOBUS_SUCCESS) { goto error_write_env; } result = gfork_i_make_xio_handle(&handle->read_xio, read_fd); if(result != GLOBUS_SUCCESS) { goto error_read_convert; } result = gfork_i_make_xio_handle(&handle->write_xio, write_fd); if(result != GLOBUS_SUCCESS) { goto error_write_convert; } globus_mutex_lock(&handle->mutex); { result = globus_xio_register_read( handle->read_xio, (globus_byte_t *)&handle->header, sizeof(gfork_i_msg_header_t), sizeof(gfork_i_msg_header_t), NULL, gfork_l_child_read_header_cb, handle); if(result != GLOBUS_SUCCESS) { goto error_post; } } globus_mutex_unlock(&handle->mutex); *out_handle = handle; return GLOBUS_SUCCESS; error_post: gfork_l_child_error(handle, result); globus_mutex_unlock(&handle->mutex); error_write_convert: globus_xio_close(handle->read_xio, NULL); error_read_convert: error_write_env: error_read_env: globus_fifo_destroy(&handle->write_q); globus_mutex_destroy(&handle->mutex); globus_free(handle); return result; }