Example #1
0
/*
 * copy 2 strings back and forth
 */
float StropBencher::copy(int numRuns, int strType) {

	float startTime = currTime();
	std::string tmp;
	std::string cpyStr = std::string("junk");
	std::string cpyStr2 = std::string("more junk");
	switch(strType) {

	case MAUTIL_STRING:

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				tmp = cpyStr2;
				cpyStr2 = cpyStr;
				cpyStr = tmp;
			}
		}
		printf("cpyStr = %s", cpyStr.c_str());
		

		/*case STD_STRING: TODO Will have to wait until STL is implemented*/

	}
    return currTime() - startTime;

}
Example #2
0
/*
 * Bench string insertion
 * @param insType, which insert()-func to call
 */
float StropBencher::insert(int numRuns, int strType, int insType) {

	std::string str("I am a string!");
	std::string inStr("I am a string to be inserted into other strings!");

	float startTime = currTime();
	switch(strType) {

	case MAUTIL_STRING:

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				if(insType == 0)
					str.insert(4, "junk");
				else
					str.insert(2, inStr); //this is a lot slower about 5 times in MoRE
			}
		}

		/*case STD_STRING: TODO Will have to wait until STL is implemented

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				mStdStr->append("junk");
			}
		}
		return currTime() - startTime;*/

	}
    return currTime() - startTime;

}
static void
sigchldHandler(int sig)
{
    int status, savedErrno;
    pid_t childPid;

    /* UNSAFE: This handler uses non-async-signal-safe functions
       (printf(), printWaitStatus(), currTime(); see Section 21.1.2) */

    savedErrno = errno;         /* In case we modify 'errno' */

    printf("%s handler: Caught SIGCHLD\n", currTime("%T"));

    while ((childPid = waitpid(-1, &status, WNOHANG)) > 0) {
        printf("%s handler: Reaped child %ld - ", currTime("%T"),
                (long) childPid);
        printWaitStatus(NULL, status);
        numLiveChildren--;
    }

    if (childPid == -1 && errno != ECHILD)
        errMsg("waitpid");

    sleep(5);           /* Artificially lengthen execution of handler */
    printf("%s handler: returning\n", currTime("%T"));

    errno = savedErrno;
}
Example #4
0
/*
 * Test the performance of the remove() function of our strType
 */
float StropBencher::remove(int numRuns, int strType) { //TODO remove this, std::string do not have remove()

	float startTime = currTime();
	std::string longStr;
	std::string subStr;
	int pos;

	switch(strType) {

	case MAUTIL_STRING:

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				longStr = std::string("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz");
				//longStr.remove(pos = rand()%(longStr.length()-1), rand()%(longStr.length()-pos)); 
			}
		}
		printf("longStr: %s", longStr.c_str()); //force the compiler to actually do the operations because subStr is used!

		/*case STD_STRING: TODO Will have to wait until STL is implemented*/

	}
    return currTime() - startTime;
    
}
Example #5
0
/*
 * Bench string appending
 */
float StropBencher::appender(int numRuns, int strType, int func) {

	float startTime = currTime();
    std::string str("Ima String!");
	std::string appStr("Append me!");
	switch(strType) {

	case MAUTIL_STRING:

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				if(func == 0)
					appStr.append("junk", 4);
				else if(func == 1)
					appStr += str; //testing operator+=
			}
		}

		/*case STD_STRING: TODO Will have to wait until STL is implemented

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				mStdStr->append("junk");
			}
		}
		return currTime() - startTime;*/

	}
    return currTime() - startTime;

}
static void
sigchldHandler(int sig)
{
  int status, savedErrno;
  pid_t childPid;

  savedErrno = errno; /* In case we modify 'errno' */

  printf("%s handler: Caught SIGCHLD\n", currTime("%T"));

  while ((childPid = waitpid(-1, &status, WNOHANG)) > 0) {
    printf("%s handler: Reaped child %ld - ", currTime("%T"),
      (long) childPid);
    printWaitStatus(NULL, status);
   numLiveChildren--;
  }

  if (childPid == -1 && errno != ECHILD)
    errMsg("waitpid");

  sleep(5);
  printf("%s handler: returning\n", currTime("%T"));

  errno = savedErrno;
}
int
main(int argc, char *argv[])
{
    int j, sigCnt;
    sigset_t blockMask, emptyMask;
    struct sigaction sa;

    if (argc < 2 || strcmp(argv[1], "--help") == 0)
        usageErr("%s child-sleep-time...\n", argv[0]);

    setbuf(stdout, NULL);       /* Disable buffering of stdout */

    sigCnt = 0;
    numLiveChildren = argc - 1;

    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sa.sa_handler = sigchldHandler;
    if (sigaction(SIGCHLD, &sa, NULL) == -1)
        errExit("sigaction");

    /* Block SIGCHLD to prevent its delivery if a child terminates
       before the parent commences the sigsuspend() loop below */

    sigemptyset(&blockMask);
    sigaddset(&blockMask, SIGCHLD);
    if (sigprocmask(SIG_SETMASK, &blockMask, NULL) == -1)
        errExit("sigprocmask");

    for (j = 1; j < argc; j++) {
        switch (fork()) {
        case -1:
            errExit("fork");

        case 0:         /* Child - sleeps and then exits */
            sleep(getInt(argv[j], GN_NONNEG, "child-sleep-time"));
            printf("%s Child %d (PID=%ld) exiting\n", currTime("%T"),
                    j, (long) getpid());
            _exit(EXIT_SUCCESS);

        default:        /* Parent - loops to create next child */
            break;
        }
    }

    /* Parent comes here: wait for SIGCHLD until all children are dead */

    sigemptyset(&emptyMask);
    while (numLiveChildren > 0) {
        if (sigsuspend(&emptyMask) == -1 && errno != EINTR)
            errExit("sigsuspend");
        sigCnt++;
    }

    printf("%s All %d children have terminated; SIGCHLD was caught "
            "%d times\n", currTime("%T"), argc - 1, sigCnt);

    exit(EXIT_SUCCESS);
}
int
main(int argc, char *argv[])
{
    int pfd[2];                             /* Process synchronization pipe */
    int j, dummy;

    if (argc < 2 || strcmp(argv[1], "--help") == 0)
        usageErr("%s sleep-time...\n", argv[0]);

    setbuf(stdout, NULL);                   /* Make stdout unbuffered, since we
                                               terminate child with _exit() */
    printf("%s  Parent started\n", currTime("%T"));

    if (pipe(pfd) == -1)
        errExit("pipe");

    for (j = 1; j < argc; j++) {
        switch (fork()) {
        case -1:
            errExit("fork %d", j);

        case 0: /* Child */
            if (close(pfd[0]) == -1)        /* Read end is unused */
                errExit("close");

            /* Child does some work, and lets parent know it's done */

            sleep(getInt(argv[j], GN_NONNEG, "sleep-time"));
                                            /* Simulate processing */
            printf("%s  Child %d (PID=%ld) closing pipe\n",
                    currTime("%T"), j, (long) getpid());
            if (close(pfd[1]) == -1)
                errExit("close");

            /* Child now carries on to do other things... */

            _exit(EXIT_SUCCESS);

        default: /* Parent loops to create next child */
            break;
        }
    }

    /* Parent comes here; close write end of pipe so we can see EOF */

    if (close(pfd[1]) == -1)                /* Write end is unused */
        errExit("close");

    /* Parent may do other work, then synchronizes with children */

    if (read(pfd[0], &dummy, 1) != 0)
        fatal("parent didn't get EOF");
    printf("%s  Parent ready to go\n", currTime("%T"));

    /* Parent can now carry on to do other things... */

    exit(EXIT_SUCCESS);
}
Example #9
0
int
main(int argc, char *argv[])
{
  int j, sigCnt;
  sigset_t blockMask, emptyMask;
  struct sigaction sa;

  if (argc < 2 || strcmp(argv[1], "--help") == 0)
    usageErr("%s child-sleep-time...\n", argv[0]);

  setbuf(stdout, NULL);

  sigCnt =  0;
  numLiveChildren = argc - 1;

  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  sa.sa_handler = sigchldhandler;
  if (sigaction(SIGCHLD, &sa, NULL) == -1)
    errExit("sigaction");

  sigemptyset(&blockMask);
  sigaddset(&blockMask, SIGCHLD);
  if (sigprocmask(SIG_SETMASK, &blockMask, NULL) == -1)
    errExit("sigprocmask");

  for (j = 1; j < argc; ++j) {
    switch (fork()) {
    case -1:
      errExit("fork");
    case 0:
      sleep(getInt(argv[j], GN_NONNEG, "child-sleep-time"));
      printf("%s Child %d (PID=%ld) exiting\n", currTime("%T"), j, (long) getpid());
      _exit(EXIT_SUCCESS);
    default:
      break;
    }
  }

  sigemptyset(&emptyMask);
  while (numLiveChildren > 0) {
    if (sigsuspend(&emptyMask) == -1 && errno != EINTR)
      errExit("sigsuspend");
    sigCnt++;
  }

  printf("%s All %d children have terminated; SIGCHLD was caught %d times\n", currTime("%T"), argc-1, sigCnt);

  exit(EXIT_SUCCESS);
}
Example #10
0
static void sigHandler(int sig)
{
    int savedErrno;
    savedErrno = errno;
    printf("%s Caught SIGCHLD %d\n",currTime("%T"));
    errno = savedErrno;
}
Example #11
0
// getLatest:
//
void SPIF::getLatest(Session *s, MatchInfo &matchInfo)
{

   Session::CacheModeType old_mode = s->m_eCacheMode;
   FUNC("SPIF::getLatestSPIF");
   AclString os;

   try
   {
       if (s == NULL)
       {
          throw ACL_EXCEPT(ACL_NULL_POINTER,"Session pointer is NULL");
       }

       // only search cache (LOCAL) for SPIFs
       //
       s->setCacheMode(Session::LOCAL);
   
       SPIFList *pList = s->getSPIF(matchInfo);

       SPIFList::iterator pCurr;
       SPIFList::iterator pLatest;

       // Find most recent SPIF
       //
       if (pList != NULL)
       {
          pLatest = pList->begin();
          pCurr = pList->begin();
          pCurr++;
          for (; pCurr != pList->end(); pCurr++)
          {
               CML::ASN::Time latestTime(pLatest->spiftoSign.versionInformation.creationDate);
               CML::ASN::Time currTime(pCurr->spiftoSign.versionInformation.creationDate);
               if (latestTime < currTime)
               {
                  pLatest = pCurr;
               }
               else if (latestTime == currTime)
               {
                  throw ACL_EXCEPT(ACL_CACHE_ERROR,
                     "Multiple matching SPIFs found in cache with the same creationDate");
               }
          }
          *this  = *pLatest;
          delete pList;
       }
       else
       {
          os << "SPIF not found in cache.\0";
          throw ACL_EXCEPT(ACL_CACHE_ERROR, os.str());
       }
   }
   catch (SnaccException &e)
   {
      s->setCacheMode(old_mode);
      e.push(STACK_ENTRY);
      throw;
   }
} // END OF MEMBER FUNCTION getLatest
Example #12
0
static void handler(int sig, siginfo_t *si, void *uc)
{
    printf("[%s] Got signal %d\n", currTime("%T"), sig);
    printf("    sival_int          = %d\n", si->si_value.sival_int);
    printf("    timer_getoverrun() = %d\n",
            timer_getoverrun((timer_t) si->si_value.sival_ptr));
}
static void                         /* Thread notification function */
threadFunc(union sigval sv)
{
    timer_t *tidptr;
    int s;

    tidptr = sv.sival_ptr;

    printf("[%s] Thread notify\n", currTime("%T"));
    printf("    timer ID=%ld\n", (long) *tidptr);
    printf("    timer_getoverrun()=%d\n", timer_getoverrun(*tidptr));

    /* Increment counter variable shared with main thread and signal
       condition variable to notify main thread of the change. */

    s = pthread_mutex_lock(&mtx);
    if (s != 0)
        errExitEN(s, "pthread_mutex_lock");

    expireCnt += 1 + timer_getoverrun(*tidptr);

    s = pthread_mutex_unlock(&mtx);
    if (s != 0)
        errExitEN(s, "pthread_mutex_unlock");

    s = pthread_cond_signal(&cond);
    if (s != 0)
        errExitEN(s, "pthread_cond_signal");
}
Example #14
0
int
main(int argc, char *argv[])
{
    int numDead;       /* Number of children so far waited for */
    pid_t childPid;    /* PID of waited for child */
    int j;

    if (argc < 2 || strcmp(argv[1], "--help") == 0)
        usageErr("%s sleep-time...\n", argv[0]);

    setbuf(stdout, NULL);           /* Disable buffering of stdout */

    for (j = 1; j < argc; j++) {    /* Create one child for each argument */
        switch (fork()) {
        case -1:
            errExit("fork");

        case 0:                     /* Child sleeps for a while then exits */
            printf("[%s] child %d started with PID %ld, sleeping %s "
                    "seconds\n", currTime("%T"), j, (long) getpid(),
                    argv[j]);
            sleep(getInt(argv[j], GN_NONNEG, "sleep-time"));
            _exit(EXIT_SUCCESS);

        default:                    /* Parent just continues around loop */
            break;
        }
    }

    numDead = 0;
    for (;;) {                      /* Parent waits for each child to exit */
        childPid = wait(NULL);
        if (childPid == -1) {
            if (errno == ECHILD) {
                printf("No more children - bye!\n");
                exit(EXIT_SUCCESS);
            } else {                /* Some other (unexpected) error */
                errExit("wait");
            }
        }

        numDead++;
        printf("[%s] wait() returned child PID %ld (numDead=%d)\n",
                currTime("%T"), (long) childPid, numDead);
    }
}
Example #15
0
void CMMFTestVideoDecodeHwDevice::SetClockSource(MMMFClockSource* aClock)
	{
	__ASSERT_ALWAYS(aClock, DevVideoDecoderPanic(EDecoderPanicClockSource)); 

	// call Time() to check that clock can be used
	TTimeIntervalMicroSeconds currTime(0); // done this way to remove compiler warning
	currTime = aClock->Time();
	}
Example #16
0
int
main(int argc, char *argv[])
{
  int fd, lock;
  const char *lname;

  if (argc < 3 || strcmp(argv[1], "--help") == 0 ||
      strchr("sx", argv[2][0]) == NULL)
    usageErr("%s file lock [sleep-time]\n"
             "    'lock' is 's' (shared) or 'x' (exclusive)\n"
             "        optionally followed by 'n' (nonblocking)\n"
             "    'secs' specifies time to hold lock\n", argv[0]);

  lock = (argv[2][0] == 's') ? LOCK_SH : LOCK_EX;
  if (argv[2][1] == 'n')
    lock |= LOCK_NB;

  fd = open(argv[1], O_RDONLY);  /* Open file to be locked */
  if (fd == -1)
    errExit("open");

  lname = (lock & LOCK_SH) ? "LOCK_SH" : "LOCK_EX";

  printf("PID %ld: requesting %s at %s\n", (long) getpid(), lname,
      currTime("%T"));

  if (flock(fd, lock) == -1) {
    if (errno == EWOULDBLOCK)
      fatal("PID %ld: already locked - bye!", (long) getpid());
    else
      errExit("flock (PID=%ld)", (long) getpid());
  }

  printf("PID %ld: granted  %s at %s\n", (long) getpid(), lname,
      currTime("%T"));

  sleep((argc > 3) ? getInt(argv[3], GN_NONNEG, "sleep-time") : 10);
  
  printf("PID %ld: releasing %s at %s\n", (long) getpid(), lname,
      currTime("%T"));

  if (flock(fd, LOCK_UN) == -1)
    errExit("flock");

  exit(EXIT_SUCCESS);
}
Example #17
0
int main(int argc, char *argv[])
{
    pid_t childPid;
    sigset_t blockMask, origMask, emptyMask;
    struct sigaction sa;

    setbuf(stdout, NULL);

    sigemptyset(&blockMask);
    sigaddset(&blockMask, SYNC_SIG);
    if (sigprocmask(SIG_BLOCK, &blockMask, &o rigMask) == -1)
        errExit("sigprocmask");

    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    sa.sa_handler = handler;
    if (sigaction(SYNC_SIG, &sa, NULL) == -1)
        errExit("sigaction");

    switch(childPid = fork()) {
    case -1:
        errExit("fork");
    case 0:
        printf("[%s %ld] Child started - doing some work\n",
                currTime("%T"), (long) getpid());
        if (kill(getppid(), SYNC_SIG) == -1)
            errExit("kill");
        _exit(EXIT_SUCCESS);

    default:
        printf("[%s %ld] Parent about to wait for signal\n",
                currTime("%T"), (long) getpid());
        sigemptyset(&emptyMask);
        if (sigsuspend(&emptyMask) == -1 && errno != EINTR)
            errExit("sigsuspend");
        printf("[%s %ld] Parent got signal\n", currTime("%T"), (long) getpid());

        if (sigprocmask(SIG_SETMASK, &origMask, NULL) == -1)
            errExit("sigprocmask");

        exit(EXIT_SUCCESS);
    }

}
Example #18
0
int main(int argc, char *argv[])
{
    int sigCnt;
    struct sigaction sa;

    if(argc<2 || !strcmp(argv[1], "--help"))
        usageErr("%s child-sleep-time...\n", argv[0]);

    setvbuf(stdout, NULL, _IONBF, 0);

    sigCnt = 0;
    numLiveChildren = argc-1;

    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sa.sa_handler = sigChldHandler;
    if(sigaction(SIGCHLD, &sa, NULL) == -1)
        errExit("sigaction");

    for(int j=1; j<argc; ++j){
        switch(fork()){
            case -1:
                     errExit("fork()");
            case  0:
                     sleep(getInt(argv[j], GN_NONNEG, "child-sleep-time"));
                     printf("%s Child %d (PID = %jd) exiting\n", currTime("%T"),
                              j, (intmax_t) getpid());
                     _exit(EXIT_SUCCESS);
            default:
                     break;
        }
    }

    while(numLiveChildren > 0){
        pause();
        ++sigCnt;
   }

    printf("%s All %d children have terminated; SIGCHDL was caught "
           "%d times\n", currTime("%T"), argc-1, sigCnt);


    exit(EXIT_SUCCESS);
}
Example #19
0
int
main(int argc, char *argv[])
{
    int semid;

    if (argc < 2 || argc > 3 || strcmp(argv[1], "--help") == 0)
        usageErr("%s init-value\n"
                 "   or: %s semid operation\n", argv[0], argv[0]);

    if (argc == 2) {            /* Create and initialize semaphore */
        union semun arg;

        semid = semget(IPC_PRIVATE, 1, S_IRUSR | S_IWUSR);
        if (semid == -1)
            errExit("semid");

        arg.val = getInt(argv[1], 0, "init-value");
        if (semctl(semid, /* semnum= */ 0, SETVAL, arg) == -1)
            errExit("semctl");

        printf("Semaphore ID = %d\n", semid);

    } else {                    /* Perform an operation on first semaphore */

        struct sembuf sop;              /* Structure defining operation */

        semid = getInt(argv[1], 0, "semid");

        sop.sem_num = 0;                /* Specifies first semaphore in set */
        sop.sem_op = getInt(argv[2], 0, "operation");
                                        /* Add, subtract, or wait for 0 */
        sop.sem_flg = 0;                /* No special options for operation */

        printf("%ld: about to semop at  %s\n", (long) getpid(), currTime("%T"));
        if (semop(semid, &sop, 1) == -1)
            errExit("semop");

        printf("%ld: semop completed at %s\n", (long) getpid(), currTime("%T"));
    }

    exit(EXIT_SUCCESS);
}
static void
handler(int sig, siginfo_t *si, void *uc)
{
   /* Note: calling printf() from a signal handler is not
      strictly correct, since printf() is not async-signal-safe;
      see signal(7) */

   printf("[%s]Caught signal %d\n",currTime("%T"), sig);
   print_siginfo(si);
  // signal(SIG, SIG_DFL);
}
Example #21
0
/*
 * Benchmark the find functions family
 * @param func tells which find-function to bench
 */
float StropBencher::find(int numRuns, int strType, int func) {

	float startTime = currTime();
	std::string alphabet("abcdefghiljkmnopqrstuvwxyz");
	const char * c_str = "a\0b\0c\0d\0e\0f\0g\0h\0i\0j\0k\0l\0m\0n\0o\0p\0q\0r\0s\0t\0u\0v\0w\0x\0y\0z\0";
	std::string largeAlphabet("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz");
	int res; //result of find (position where char was found or -1 on no match)

	switch(strType) {

	case MAUTIL_STRING:

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				for(char k = 0; k < alphabet.length(); ++k){
					if(func == 0){
						res = alphabet.find(c_str+2*k, 0);
						if(res == -1)
							printf("Error in find(), no match but it should be!");
					}else if(func == 1){
						res = largeAlphabet.find_last_of((char) k+97); //ascii val of 'a' is 97
						if(res == -1)
							printf("Error in find_last_of(), no match but it should be!");
					}else if(func == 2){
						res = largeAlphabet.find_first_of((char) k+97, rand()%(largeAlphabet.length()-1)); //randomize starting position
					}else{
						res = largeAlphabet.find_first_not_of((char) k+97, rand()%(largeAlphabet.length()-1)); //randomize starting position
						if(res == -1)
							printf("Error in find_first_not_of(), no match but it should be!");
					}
				}
			}
		}

		/*case STD_STRING: TODO Will have to wait until STL is implemented*/

	}
    return currTime() - startTime;

}
Example #22
0
/*
 * Test the performance of string comparisons on our strType
 */
float StropBencher::compare(int numRuns, int strType, int cmpType) {

	float startTime = currTime();
	bool ret;
	std::string longStr("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz");
	std::string eq("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz");
	std::string notEq("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghilj#kmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz");
	std::string less("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljjkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz"); //2 j:s in a row makes this string lexiographically less than longStr
	std::string more("abcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljmkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyzabcdefghiljkmnopqrstuvwxyz"); //a m after the j makes this string lexiographically more than longStr
	int pos;

	switch(strType) {

	case MAUTIL_STRING:

		for(int i = 0; i < numRuns; ++i){
			for(int j = 0; j < ALOT; ++j){
				if(cmpType == 0)
					ret = longStr == eq;
				else if(cmpType == 1)
					ret = longStr != notEq;
				else if(cmpType == 2)
					ret = longStr <= more;
				else if(cmpType == 3)
					ret = longStr >= less;
				else if(cmpType == 4)
					ret = longStr < less;
				else
					ret = longStr > less;

			}
		}
//		printf("ret: %d", ret); //force the compiler to actually do the operations because subStr is used!

		/*case STD_STRING: TODO Will have to wait until STL is implemented*/

	}
    return currTime() - startTime;

}
Example #23
0
static void sigChldHandler(int sig)
{
    int status, savedErrno;
    pid_t childPid;

    savedErrno = errno;
    printf("%s handler: Caught SIGCHLD\n", currTime("%T"));

    while((childPid = waitpid(-1, &status, WNOHANG)) > 0){
        printf("%s handler: Reaped child %jd - ", currTime("%T"),
                (intmax_t) childPid);
        printWaitStatus(NULL, status);
        --numLiveChildren;
    }

    if(childPid == -1 && errno != ECHILD)
        errMsg("waitpid()");

    printf("%s handler: returning\n", currTime("%T"));

    errno = savedErrno;
}
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
	{
		switch (event)
		{
			case eFE_Initialize:
			{
				m_actInfo = *pActInfo;
			}
			break;

			case eFE_Activate:
			{
				if (IsPortActive(pActInfo, EIP_Enable)) {
					
					if (socketWorking) {
						endSocket();
					}
					
					m_bEnabled = true;
					// try to open port socket
					port = GetPortInt(pActInfo, EIP_Port);
					multicast = GetPortString(pActInfo, EIP_Multicast);
					startSocket(port, multicast);

					Execute(pActInfo);
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true);
				}
				if (IsPortActive(pActInfo, EIP_Disable)) {
					m_bEnabled = false;
					endSocket();
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);
				}
			}
			break;

			case eFE_Update:
			{
				CTimeValue currTime(gEnv->pTimer->GetCurrTime());
				float delay = 0;  // processing delay
				delay -= (currTime-m_lastTime).GetSeconds();
				m_lastTime = currTime;

				// Execute?
				if (delay <= 0.0f)
				{
					Execute(pActInfo);
				}
			}
			break;
		}
	}
static void
handler(int sig, siginfo_t *si, void *uc)
{
    timer_t *tidptr;

    tidptr = si->si_value.sival_ptr;

    /* UNSAFE: This handler uses non-async-signal-safe functions
       (printf(); see Section 21.1.2) */

    printf("[%s] Got signal %d\n", currTime("%T"), sig);
    printf("    *sival_ptr         = %ld\n", (long) *tidptr);
    printf("    timer_getoverrun() = %d\n", timer_getoverrun(*tidptr));
}
Example #26
0
int
main(int argc, char *argv[])
{
    struct sembuf sops[MAX_SEMOPS];
    int ind, nsops;

    if (argc < 2 || strcmp(argv[1], "--help") == 0)
        usageError(argv[0]);

    for (ind = 2; argv[ind] != NULL; ind++) {
        nsops = parseOps(argv[ind], sops);

        printf("%5ld, %s: about to semop()  [%s]\n", (long) getpid(),
                currTime("%T"), argv[ind]);

        if (semop(getInt(argv[1], 0, "semid"), sops, nsops) == -1)
            errExit("semop (PID=%ld)", (long) getpid());

        printf("%5ld, %s: semop() completed [%s]\n", (long) getpid(),
                currTime("%T"), argv[ind]);
    }

    exit(EXIT_SUCCESS);
}
Example #27
0
Explosion::Explosion (View* _view, float __radius) : FlyingObject(_view, 1, 0), _radius(__radius)
{
    x = _view->getShip()->X();
    y = _view->getShip()->Y() + view->getShip()->height();
    vx = 0; vy = 0;
    nvertices = NP;
    vertices = new Point[nvertices];
    for (int i=0; i< nvertices; i++)
    {
        float fi = M_PI* 2* i/ (nvertices-1);
        vertices[i] = Point(_radius* sin(fi), _radius* cos(fi));
    }
    _color = Point4D(0.5,0,0,1);
    _endTime = currTime() + 1500;
    initGL();
}
Example #28
0
int main(int argc, char *argv[])
{
	int parentStatus;

	printf("Grandparent: %ld\n", (long)getpid());

	switch (fork()) {

		case -1:
			errExit("fork");

		// parent
		case 0:

			printf("Parent: %ld\n", (long)getpid());

			switch (fork()) {

				case -1:
					errExit("fork2");

				// child
				case 0:
					printf("Child: %ld\n", (long)getpid());

					printf("[%s] Before parent exit: %ld\n", currTime("%T"), (long)getppid());
					sleep(2);
					printf("[%s] After parent exit: %ld\n", currTime("%T"), (long)getppid());
					sleep(4);
					printf("[%s] After parent was reaped: %ld\n", currTime("%T"), (long)getppid());
					_exit(EXIT_SUCCESS);

				// still parent
				default:
					sleep(1);
					printf("[%s] Parent exiting\n", currTime("%T"));
					// 2
					_exit(EXIT_SUCCESS);
			}

		// grandparent
		default:
			sleep(5);
			printf("[%s] Grandparent reaping parent\n", currTime("%T"));
			if (wait(&parentStatus) == -1) {
				printf("WAIT FAILED TO REAP PARENT");
			}
			printf("[%s] Parent exit code: %d\n", currTime("%T"), parentStatus);
			sleep(3);
			exit(EXIT_SUCCESS);
	}

	exit(EXIT_FAILURE);
}
Example #29
0
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
	{
		switch (event)
		{
		case eFE_Initialize : 
			{
				current_values = new float[5];
				for(int i = 0 ;i<5;i++) current_values[i]= 0;
				break;
			}
			case eFE_Activate:
			{
				if (IsPortActive(pActInfo, EIP_Enable)) {
					
					if (udpListener->IsWorking()) udpListener->EndSocket();
					
					m_bEnabled = true;
					udpListener->StartSocket(GetPortInt(pActInfo, EIP_Port));

					Execute(pActInfo);
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true);
				}

				if (IsPortActive(pActInfo, EIP_Disable)) {
					m_bEnabled = false;
					udpListener->EndSocket();
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);
				}
			}
			break;

			case eFE_Update:
			{
				CTimeValue currTime(gEnv->pTimer->GetCurrTime());
				float delay = 0;  // processing delay
				delay -= (currTime-m_lastTime).GetSeconds();
				m_lastTime = currTime;

				if (delay <= 0.0f)
				{
					Execute(pActInfo);
				}
			}
			break;
		}
	}
Example #30
0
int main(int argc, char *argv[])
{
  pid_t childPid;
  sigset_t blockMask, origMask, emptyMask;
  sigset_t ch_blockMask, ch_origMask, ch_emptyMask;
  struct sigaction sa, ch_sa;

  setbuf(stdout, NULL);

  sigemptyset(&blockMask);
  sigaddset(&blockMask, SYNC_SIG);
  if (sigprocmask(SIG_BLOCK, &blockMask, &origMask) == -1)
    errExit("sigprocmask");

  sigemptyset(&sa.sa_mask);
  sa.sa_flags = SA_RESTART;
  sa.sa_handler = handler;
  if (sigaction(SYNC_SIG, &sa, NULL) == -1)
    errExit("sigaction");

  switch (childPid = fork()) {
    case -1:
      errExit("fork");
    case  0: /* Child */

      sigemptyset(&ch_blockMask);
      sigaddset(&ch_blockMask, SEC_SIG);
      if (sigprocmask(SIG_BLOCK, &ch_blockMask, &ch_origMask) == -1)
        errExit("sigprocmask");

      sigemptyset(&ch_sa.sa_mask);
      ch_sa.sa_flags = SA_RESTART;
      ch_sa.sa_handler = handler;
      if (sigaction(SEC_SIG, &ch_sa, NULL) == -1)
        errExit("sigaction");

      printf("[%s %ld] Child started - doing some work\n",
              currTime("%T"), (long) getpid());
      sleep(2);  /* simulate work */

      /* send signal to parent that it's done */

      printf("[%s %ld] Child about to signal parent\n",
              currTime("%T"), (long) getpid());
      if (kill(getppid(), SYNC_SIG) == -1)
        errExit("kill");

      /* now child wait for signal from parent to continue */

      if (sigsuspend(&ch_origMask) == -1 && errno != EINTR)
        errExit("sigsuspend");

      printf("[%s %ld] Child got signal from parent\n",
              currTime("%T"), (long) getpid());

      _exit(EXIT_SUCCESS);

    default: /* Parent */
      printf("[%s %ld] Parent about to wait for signal\n",
              currTime("%T"), (long) getpid());
      sigemptyset(&emptyMask);
      if (sigsuspend(&emptyMask) == -1 && errno != EINTR)
        errExit("sigsuspend");
      printf("[%s %ld] Parent got signal \n", currTime("%T"), (long) getpid());

      /* If required, return signal mask to its original state */

      if (sigprocmask(SIG_SETMASK, &origMask, NULL) == -1)
        errExit("sigprocmask");

      printf("[%s %ld] Parent send signal to child \n", currTime("%T"), (long) getpid());
       if (kill(childPid, SEC_SIG) == -1)
         errExit("kill");

      /* Parent carries on to do other things ... */

      exit(EXIT_SUCCESS);
  }
}