pthread_mutex_unlock(&queue_mutex); close(workersock);
void *DoConnection(void *fd){	int *sf;	int workersock;	char buffer[1024];	char size[100];	int QIndex;	struct QItem TxnQItem;#ifdef GET_TIME	struct timeval receive_request_time,  send_response_time, t1;	double server_response_time, db_response_time, server_db_time;#endif		sf = (int *)(fd);	workersock = *sf;#ifdef DEBUG	DEBUGMSG("pthread_id%ld: DoConnection: got connection", pthread_self());#endif	while (1)	{		if(receive_transaction_packet(workersock, &TxnQItem) != W_OK) 		{			LOG_ERROR_MESSAGE("receive_transaction_packet failed");			pthread_exit(NULL);		}#ifdef DEBUG		DEBUGMSG("pthread_id%ld: TxnQItem txn_id %d, slot %d", pthread_self(), TxnQItem.TxnType, TxnQItem.SlotID);#endif#ifdef GET_TIME		if (gettimeofday(&receive_request_time, NULL)== -1)		{			LOG_ERROR_MESSAGE("gettimeofday failed");		}#endif		/*add interaction to txnQ */		pthread_mutex_lock(&queue_mutex);		QIndex=enqueue(TxnQItem, &TxnQ);		if (QIndex==-1)		{			LOG_ERROR_MESSAGE("enquue failed");			pthread_exit(NULL);		}		pthread_mutex_unlock(&queue_mutex);		sem_post(&TxnQSem);#ifdef GET_TIME		if (gettimeofday(&t1, NULL)== -1)		{			LOG_ERROR_MESSAGE("gettimeofday failed");		}#endif		/* wait for transation done */#ifdef DEBUG		DEBUGMSG("pthread_id%ld: wait for txn done...", pthread_self());#endif		pthread_mutex_lock(&queue_entry_condition[QIndex].condition_mutex);		while (!queue_entry_condition[QIndex].txn_done_flag)			pthread_cond_wait(&queue_entry_condition[QIndex].txn_done_cv, &queue_entry_condition[QIndex].condition_mutex);		queue_entry_condition[QIndex].txn_done_flag=0;		pthread_mutex_unlock(&queue_entry_condition[QIndex].condition_mutex);			#ifdef DEBUG		DEBUGMSG("pthread_id%ld: got it, txn done", pthread_self());#endif#ifdef GET_TIME		if (gettimeofday(&send_response_time, NULL)== -1)		{			LOG_ERROR_MESSAGE("gettimeofday failed");		}		server_response_time=time_diff(receive_request_time, send_response_time);		server_db_time=time_diff(t1,send_response_time);		switch (TxnQItem.TxnType)		{			case ADMIN_CONFIRM:				db_response_time = app_admin_confirm_array.db_response_time[TxnQItem.SlotID];				break;			case ADMIN_REQUEST:				db_response_time = app_admin_request_array.db_response_time[TxnQItem.SlotID];				break;			case BEST_SELLERS:				db_response_time = app_best_sellers_array.db_response_time[TxnQItem.SlotID];				break;			case BUY_CONFIRM:				db_response_time = app_buy_confirm_array.db_response_time[TxnQItem.SlotID];				break;			case BUY_REQUEST:				db_response_time = app_buy_request_array.db_response_time[TxnQItem.SlotID];				break;			case HOME:				db_response_time = app_home_array.db_response_time[TxnQItem.SlotID];				break;			case NEW_PRODUCTS:				db_response_time = app_new_products_array.db_response_time[TxnQItem.SlotID];				break;			case ORDER_DISPLAY:				db_response_time = app_order_display_array.db_response_time[TxnQItem.SlotID];				break;			case ORDER_INQUIRY:				db_response_time = app_order_inquiry_array.db_response_time[TxnQItem.SlotID];				break;			case PRODUCT_DETAIL:				db_response_time = app_product_detail_array.db_response_time[TxnQItem.SlotID];				break;			case SEARCH_REQUEST:				db_response_time = app_search_request_array.db_response_time[TxnQItem.SlotID];				break;			case SEARCH_RESULTS:				db_response_time = app_search_results_array.db_response_time[TxnQItem.SlotID];				break;			case SHOPPING_CART:				db_response_time = app_shopping_cart_array.db_response_time[TxnQItem.SlotID];				break;		}		pthread_mutex_lock(&time_log_mutex);		fprintf(timefp, "%s, total %f, db %f, server_db_time %f\n",			interaction_short_name[TxnQItem.TxnType], 			server_response_time, db_response_time, server_db_time);		fflush(timefp);		pthread_mutex_unlock(&time_log_mutex);#endif		if(send_transaction_packet(workersock, TxnQItem) != W_OK) 		{			LOG_ERROR_MESSAGE("send_transaction_packet failed");			pthread_exit(NULL);		}	}	close(workersock);	return NULL;}