Beispiel #1
0
void GLWidget::initializeGL() {
	initializeOpenGLFunctions();

	emit signalInit();

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	int side = qMin(width(), height());
	glViewport((width() - side) / 2, (height() - side) / 2, side, side);
}
// ****************************************************************
int main() {

	/* reset number generator seed */
	srand(time(NULL) + getpid());
	//srand(0); // to get the same sequence
	
	/* initialize the price and it's mutex */
	currentPriceX10 = 1000;
	price_mut = malloc (sizeof(pthread_mutex_t));
	pthread_mutex_init(price_mut,NULL);
	
	slimit = signalInit();
	lim = signalInit();
	
	/* Open the log file for writing */
	log_file = fopen("logfile.txt","w+");

	/*
	 * Initialize the array that we will use in order to log the type of each
	 * of the order that are received by the system.
	 * It is used only to by the cancel thread to find where each order has gone.
	 */
	saves.mut = malloc(sizeof(pthread_mutex_t));
	pthread_mutex_init(saves.mut,NULL);
	saves.archive = calloc(INT_MAX,sizeof(char));
	if(saves.archive == NULL) perror( "Not enough memory" );
	
	/* Start the time for timestamps */
	gettimeofday (&startwtime, NULL);
	
	/* Create all the thread variables */
	pthread_t prod, cons, cons2, market, lim_thread, stop_thread, slim_thread, cancel;
	
	/* Initialize the incoming order queue */
	queue *q = queueInit(0);
	
	/* Initialize the buy and sell market queues. */
	msq = queueInit(0);
	mbq = queueInit(0);

	/* Initialize the buy and sell limit order queues */
	lsq = queueInit(ASC);
	lbq = queueInit(DESC);
	
	/* Initialize the buy and sell stop order queues */
	ssq = queueInit(ASC);
	sbq = queueInit(DESC);
	
	/* Initialize the buy and sell stop limit order queues */
	tsq = queueInit(ASC);
	tbq = queueInit(DESC);

	/* Initialize the cancel queue */
	cq = queueInit(0);
	
	printf("     buffer |market sell|market buy|limit sell|limit buy |stop sell | stop buy |slimit sell|slimit buy | current price");
	printf("\n\n");
	
	/* Create and launch all the appropriate threads */
	pthread_create(&prod, NULL, Prod, q);
	pthread_create(&cons, NULL, Cons, q);
	pthread_create(&cons2, NULL, Cons, q);
	pthread_create(&lim_thread, NULL, limitWorker, NULL);
	pthread_create(&market, NULL, marketWorker, NULL);
	pthread_create(&stop_thread, NULL, stopWorker, NULL);
	pthread_create(&slim_thread, NULL, stoplimitWorker, NULL);
	pthread_create(&cancel, NULL, cancelWorker, NULL);

	
	/* Join the producer thread. I actually do not expect it to ever terminate */
	pthread_join(prod, NULL);
	
	
	pthread_exit(NULL);
}