Back to index

courier  0.68.2
Functions | Variables
test.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>
#include <time.h>
#include "threadlib.h"

Go to the source code of this file.

Functions

static void workfunc (void *p)
static void cleanupfunc (void *p)
static void getwork (void *p, void *q)
static int cmpdbl (const void *a, const void *b)
int main (int argc, char **argv)

Variables

static double buf [100]
static int bufcnt = 0
static unsigned ndelay = 0

Function Documentation

static void cleanupfunc ( void *  p) [static]

Definition at line 31 of file test.c.

{
double *dp= (double *)p;

       buf[bufcnt++]= *dp;
}

Here is the caller graph for this function:

static int cmpdbl ( const void *  a,
const void *  b 
) [static]

Definition at line 46 of file test.c.

{
const double *pa=(const double *)a;
const double *pb=(const double *)b;

       return (*pa < *pb ? -1: *pa > *pb ? 1:0);
}

Here is the caller graph for this function:

static void getwork ( void *  p,
void *  q 
) [static]

Definition at line 38 of file test.c.

{
double *dp= (double *)p;
double *qp= (double *)q;

       *dp= *qp;
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 54 of file test.c.

{
double n;
struct cthreadinfo *cit;
int    i, j;

       if (argc < 2) return (1);

       j=atoi(argv[1]);
       if (argc > 2)
              ndelay=atoi(argv[2]);

       if (j <= 0 || j > sizeof(buf)/sizeof(buf[0]))    return (1);

       if ( (cit=cthread_init(2, sizeof(double), workfunc, cleanupfunc)) == 0)
       {
              perror("cthread_init");
              return (1);
       }

       for (i=0; i<j; i++)
       {
              n= i+1;

              if (cthread_go(cit, getwork, &n))
              {
                     perror("cthread_go");
                     return (1);
              }
              printf ("Started %d\n", i+1);
       }
       cthread_wait(cit);

       qsort(buf, bufcnt, sizeof(buf[0]), &cmpdbl);

       for (i=0; i<bufcnt; i++)
       {
              printf("%6.2f\n", buf[i]);
       }
       return (0);
}

Here is the call graph for this function:

static void workfunc ( void *  p) [static]

Definition at line 19 of file test.c.

{
double *dp= (double *)p;
time_t t1, t2;

       *dp=sqrt( *dp );

       time(&t1);
       while ( time(&t2) < t1 + ndelay)
              ;
}

Here is the caller graph for this function:


Variable Documentation

double buf[100] [static]

Definition at line 15 of file test.c.

int bufcnt = 0 [static]

Definition at line 16 of file test.c.

unsigned ndelay = 0 [static]

Definition at line 17 of file test.c.