/* $Header: test.c,v 1.1 87/03/11 15:59:16 mikew Exp $ */
/* $Source: /afs/andrew.cmu.edu/usr7/kazar/afs/lwp/RCS/test.c,v $ */

#ifndef lint
static char *rcsid = "$Header: test.c,v 1.1 87/03/11 15:59:16 mikew Exp $";
#endif

/*
 * P_R_P_Q_# (C) COPYRIGHT IBM CORPORATION 1987
 * LICENSED MATERIALS - PROPERTY OF IBM
 * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
 */
#include <stdio.h>
#include <sys/time.h>
#include <potpourri.h>
#include "lwp.h"

char semaphore;

int OtherProcess()
    {
    for(;;)
	{
	LWP_SignalProcess(&semaphore);
	}
    }

main(argc, argv)
int argc; char *argv[];
    {
    struct timeval t1, t2;
    int pid, otherpid;
    register int i,  count, x;
    char *waitarray[2];
    static char c[] = "OtherProcess";
    
    count = atoi(argv[1]);

    assert(LWP_InitializeProcessSupport(0, &pid) == LWP_SUCCESS);
    assert(LWP_CreateProcess(OtherProcess,4096,0, 0, c, &otherpid) == LWP_SUCCESS);

    waitarray[0] = &semaphore;
    waitarray[1] = 0;
    gettimeofday(&t1, NULL);
    for (i = 0; i < count; i++)
	{
	LWP_MwaitProcess(1, waitarray, 1);
	}
    gettimeofday(&t2, NULL);

    x = (t2.tv_sec -t1.tv_sec)*1000000 + (t2.tv_usec - t1.tv_usec);
    printf("%d milliseconds for %d MWaits (%f usec per Mwait and Signal)\n", x/1000, count, (float)(x/count));
    }
