BurstFS_Server/burstfs_request_manager.c
int rm_delegate_request(cli_signature_t *my_sig) {
	int rc = ULFS_SUCCESS;
	int app_id = my_sig->app_id;
	int sock_id = my_sig->sock_id;

	app_config_t *app_config =\
			(app_config_t *)arraylist_get(app_config_list, app_id);
	int thrd_id = app_config->thrd_idxs[sock_id];
	thrd_ctrl_t *thrd_ctrl =\
			(thrd_ctrl_t *)arraylist_get(thrd_list, thrd_id);

	while(1) {
		pthread_mutex_lock(&thrd_ctrl->thrd_lock);
		thrd_ctrl->has_waiting_delegator = 1;
		if (thrd_ctrl->has_waiting_dispatcher == 1)
			pthread_cond_signal(&thrd_ctrl->thrd_cond);
		pthread_cond_wait(&thrd_ctrl->thrd_cond,\
				&thrd_ctrl->thrd_lock);
		thrd_ctrl->has_waiting_delegator = 0;
		if (thrd_ctrl->exit_flag == 1) {
			pthread_mutex_unlock(&thrd_ctrl->thrd_lock);
			break;
		}

		long tot_sz = 0;
		rc = rm_send_remote_requests(thrd_ctrl,\
				thrd_id, &tot_sz);
		if (rc != ULFS_SUCCESS) {
			pthread_mutex_unlock(&thrd_ctrl->thrd_lock);
			return rc;
		}

		rc = rm_receive_remote_message(app_id, sock_id, tot_sz);
		if (rc != 0) {
			pthread_mutex_unlock(&thrd_ctrl->thrd_lock);
			return rc;
		}
		pthread_mutex_unlock(&thrd_ctrl->thrd_lock);
	}
	return rc;
}
/**
* delegate the read requests
* for the delegator thread's client. Each
* delegator thread handles one connection to
* one client-side rank.
* @param my_sig: the signature of the delegator thread,
* marked by its client's app_id and the socket id.
* @return success/error code
*/
delegate the read requests
for the delegator thread's client. Each
delegator thread handles one connection to
one client-side rank.
delegate the read requests for the delegator thread ' s client . Each delegator thread handles one connection to one client - side rank .
int rm_delegate_request(cli_signature_t *my_sig) {
	int rc = ULFS_SUCCESS;
	int app_id = my_sig->app_id;
	int sock_id = my_sig->sock_id;
	app_config_t *app_config =\
			(app_config_t *)arraylist_get(app_config_list, app_id);
	int thrd_id = app_config->thrd_idxs[sock_id];
	thrd_ctrl_t *thrd_ctrl =\
			(thrd_ctrl_t *)arraylist_get(thrd_list, thrd_id);
	while(1) {
		pthread_mutex_lock(&thrd_ctrl->thrd_lock);
		thrd_ctrl->has_waiting_delegator = 1;
		if (thrd_ctrl->has_waiting_dispatcher == 1)
			pthread_cond_signal(&thrd_ctrl->thrd_cond);
		pthread_cond_wait(&thrd_ctrl->thrd_cond,\
				&thrd_ctrl->thrd_lock);
		thrd_ctrl->has_waiting_delegator = 0;
		if (thrd_ctrl->exit_flag == 1) {
			pthread_mutex_unlock(&thrd_ctrl->thrd_lock);
			break;
		}
		long tot_sz = 0;
		rc = rm_send_remote_requests(thrd_ctrl,\
				thrd_id, &tot_sz);
		if (rc != ULFS_SUCCESS) {
			pthread_mutex_unlock(&thrd_ctrl->thrd_lock);
			return rc;
		}
		rc = rm_receive_remote_message(app_id, sock_id, tot_sz);
		if (rc != 0) {
			pthread_mutex_unlock(&thrd_ctrl->thrd_lock);
			return rc;
		}
		pthread_mutex_unlock(&thrd_ctrl->thrd_lock);
	}
	return rc;
}
int rm_delegate_request ( cli_signature_t * my_sig ) { int rc = ULFS_SUCCESS ; int app_id = my_sig -> app_id ; int sock_id = my_sig -> sock_id ; app_config_t * app_config = ( app_config_t * ) arraylist_get ( app_config_list , app_id ) ; int thrd_id = app_config -> thrd_idxs [ sock_id ] ; thrd_ctrl_t * thrd_ctrl = ( thrd_ctrl_t * ) arraylist_get ( thrd_list , thrd_id ) ; while ( 1 ) { pthread_mutex_lock ( & thrd_ctrl -> thrd_lock ) ; thrd_ctrl -> has_waiting_delegator = 1 ; if ( thrd_ctrl -> has_waiting_dispatcher == 1 ) pthread_cond_signal ( & thrd_ctrl -> thrd_cond ) ; pthread_cond_wait ( & thrd_ctrl -> thrd_cond , & thrd_ctrl -> thrd_lock ) ; thrd_ctrl -> has_waiting_delegator = 0 ; if ( thrd_ctrl -> exit_flag == 1 ) { pthread_mutex_unlock ( & thrd_ctrl -> thrd_lock ) ; break ; } long tot_sz = 0 ; rc = rm_send_remote_requests ( thrd_ctrl , thrd_id , & tot_sz ) ; if ( rc != ULFS_SUCCESS ) { pthread_mutex_unlock ( & thrd_ctrl -> thrd_lock ) ; return rc ; } rc = rm_receive_remote_message ( app_id , sock_id , tot_sz ) ; if ( rc != 0 ) { pthread_mutex_unlock ( & thrd_ctrl -> thrd_lock ) ; return rc ; } pthread_mutex_unlock ( & thrd_ctrl -> thrd_lock ) ; } return rc ; }
delegate the read requests
for the delegator thread's client.
delegate the read requests for the delegator thread ' s client .