Exemplo n.º 1
0
void BufferTest(int nChars,int bSize,int pDelay,int cDelay,char *pcPrioStr)
{
	HPriority pp,cp;
	int n = nChars;
	int pstat,cstat;

	printf("Starting Buffer Test\n\n");
	lock = HCreateLock("Buffer");
	notfull =  HCreateSignal("NotFull");
	notempty = HCreateSignal("NotEmpty");
	inx = 0; outx=0; used=0; bsize = bSize;
	pp = getpr(pcPrioStr[0]);
	cp = getpr(pcPrioStr[1]);
	pdel = pDelay; cdel = cDelay;
	prod_th = HCreateThread("Producer",10, pp, producer, (void *)n);
	cons_th = HCreateThread("Consumer",10, cp, consumer, (void *)n);
	HJoinThread(prod_th,&pstat);
	HJoinThread(cons_th,&cstat);
	printf("\n\nProducer terminated[%d chars sent]\n",pstat);
	printf("Consumer terminated[%d chars received]\n",cstat);
}
Exemplo n.º 2
0
void open_file(const mxArray *ptr, FTYPE *map)
{
    int n;
    int i, dtype;
    const double *pr;
    mxArray *arr;

    if (!mxIsStruct(ptr)) mexErrMsgTxt("Not a structure.");

    dtype = (int)(getpr(ptr, "dtype", 1, &n)[0]);
    map->dtype = NULL;
    for(i=0; i<sizeof(table)/sizeof(Dtype); i++)
    {
        if (table[i].code == dtype)
        {
            map->dtype = &table[i];
            break;
        }
    }
    if (map->dtype == NULL)        mexErrMsgTxt("Unrecognised 'dtype' value.");
    if (map->dtype->bits % 8)      mexErrMsgTxt("Can not yet write logical data.");
    if (map->dtype->channels != 1) mexErrMsgTxt("Can not yet write complex data.");
    pr        = getpr(ptr, "dim", -MXDIMS, &n);
    map->ndim = n;
    for(i=0; i<map->ndim; i++)
    {
        map->dim[i] = (int)fabs(pr[i]);
    }
    pr       = getpr(ptr, "be",1, &n);
#ifdef SPM_BIGENDIAN
    map->swap = (int)pr[0]==0;
#else
    map->swap = (int)pr[0]!=0;
#endif
    pr       = getpr(ptr, "offset",1, &n);
    map->off = (off_t)pr[0];
 /* if (map->off < 0) map->off = 0; Unsigned, so not necessary */

    arr = mxGetField(ptr,0,"fname");
    if (arr == (mxArray *)0) mexErrMsgTxt("Cant find 'fname' field.");

    if (mxIsChar(arr))
    {
        int buflen;
        char *buf;
        buflen = mxGetNumberOfElements(arr)+1;
        buf    = mxCalloc(buflen+1,sizeof(char));
        if (mxGetString(arr,buf,buflen))
        {
            mxFree(buf);
            mexErrMsgTxt("Cant get 'fname'.");
        }
        map->fp = fopen(buf,"rb+");
        if (map->fp == (FILE *)0)
        {
            map->fp = fopen(buf,"wb");
            if (map->fp == (FILE *)0)
            {
                mxFree(buf);
                mexErrMsgTxt("Cant open file.");
            }
        }

        mxFree(buf);
    }
    else
        mexErrMsgTxt("Wrong type of 'fname' field.");
}