head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


1.2
date	2008.09.16.22.57.21;	author martin;	state Exp;
branches;
next	1.1;
commitid	379748d039cf4567;

1.1
date	2008.09.16.22.18.10;	author martin;	state Exp;
branches;
next	;
commitid	282c48d030a14567;


desc
@@


1.2
log
@no message
@
text
@/*
  This file is part of JOP, the Java Optimized Processor
    see <http://www.jopdesign.com/>

  Copyright (C) 2008, Martin Schoeberl (martin@@jopdesign.com)

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


package rtlib;

import java.util.Vector;

import com.jopdesign.io.IOFactory;
import com.jopdesign.io.SysDevice;
import com.jopdesign.sys.Startup;

/**
 * Test of the rtlib Buffer
 * 
 * @@author Martin Schoeberl
 *
 */
public class CMPBuffer implements Runnable {
	
	final static int MAX = 10000000;
	
	boolean producer;
	int cnt;
	
	public CMPBuffer(boolean prod) {
		producer = prod;
	}
	
	static Vector msg;
	static rtlib.Buffer buf = new Buffer(5);

	/**
	 * @@param args
	 */
	public static void main(String[] args) {

		msg = new Vector();
		
		System.out.println("Buffer test start");
		
		SysDevice sys = IOFactory.getFactory().getSysDevice();
		if (sys.nrCpu<3) {
			System.out.println("Not enough CPUs for this test");
			System.exit(-1);
		}
		
		Startup.setRunnable(new CMPBuffer(true), 1);
		Startup.setRunnable(new CMPBuffer(false), 0);
				
		// start the other CPUs
		sys.signal = 1;
		
		// print their messages
		for (;;) {
			int size = msg.size();
			if (size!=0) {
				StringBuffer sb = (StringBuffer) msg.remove(0);
				System.out.println(sb);
			}
		}
	}

	public void run() {

		if (producer) {
			for (;;) {
				if (!buf.full()) {
					buf.write(cnt++);
				}
				if (cnt==MAX) break;
			}
			msg("Producer finished");
		} else {
			for (;;) {
				if (!buf.empty()) {
					int val = buf.read();
					if (val!=cnt) {
						msg("Problem!");
					}
					++cnt;
				}
				if (cnt==MAX) break;
			}
			msg("Consumer finished");
		}
	}
	
	void msg(String s) {
		msg.addElement(new StringBuffer(s));				
	}

}
@


1.1
log
@Test for the single reader/writer buffer
@
text
@d31 1
a31 1
 * A CMP version of Hello World
d33 1
a33 1
 * @@author martin
@

