예제 #1
0
파일: thrq.c 프로젝트: 4get/aup2ex
/*[main]*/
int main(void)
{
	sigset_t set;
	struct sigaction act;
	union sigval value;
	pthread_t tid;

#ifdef LINUX
	printf("Warning: May hang -- see comment at the top of c9/thrq.c\n");
#endif
	ec_neg1( sigemptyset(&set) )
	ec_neg1( sigaddset(&set, MYSIG_COUNT) )
	ec_neg1( sigaddset(&set, MYSIG_STOP) )
	ec_rv( pthread_sigmask(SIG_SETMASK, &set, NULL) )
	memset(&act, 0, sizeof(act));
	act.sa_flags = SA_SIGINFO;
	act.sa_sigaction = dummy_handler;
	ec_neg1( sigaction(MYSIG_COUNT, &act, NULL) )
	ec_neg1( sigaction(MYSIG_STOP, &act, NULL) )
	value.sival_ptr = "One";
	ec_neg1( sigqueue(getpid(), MYSIG_COUNT, value) )
	value.sival_ptr = "Two";
	ec_neg1( sigqueue(getpid(), MYSIG_COUNT, value) )
	value.sival_ptr = "Three";
	ec_neg1( sigqueue(getpid(), MYSIG_COUNT, value) )
	value.sival_ptr = NULL;
	ec_neg1( sigqueue(getpid(), MYSIG_STOP, value) )
	ec_rv( pthread_create(&tid, NULL, sig_thread, &set) )
	ec_rv( pthread_join(tid, NULL) )
	exit(EXIT_SUCCESS);

EC_CLEANUP_BGN
	exit(EXIT_FAILURE);
EC_CLEANUP_END
}
예제 #2
0
파일: wrapper_lib.c 프로젝트: SRI-CSL/iopc
void *echoErrorsSilently(void *arg){
  fdBundle fdB;
  int errcode, failures = 0;
  sigset_t mask; 
  if(arg == NULL){
    fprintf(stderr, "Bad arg to echoErrorsSilently\n");
    return NULL;
  }
  fdB = *((fdBundle *)arg);

  ec_neg1( sigemptyset(&mask) );
  ec_neg1( sigaddset(&mask, SIGCHLD) );
  ec_rv( pthread_sigmask(SIG_BLOCK, &mask, NULL) );

  while(!(*(fdB.exit))){
    errcode = echoSilently(fdB.fd, STDERR_FILENO);
    if(errcode <= 0){
      if(++failures > 5){ return NULL; }
    } else {
      failures = 0;
    }
  }
  return NULL;
EC_CLEANUP_BGN
  return NULL;
EC_CLEANUP_END
}
예제 #3
0
int One2OneChannel::init() {
    int rm = -1;
    int rc = -1;
   
    ec_rv( rm = pthread_mutex_init(&m_sync, NULL) )
    ec_rv( rc = pthread_cond_init(&m_cond, NULL) )

    // EC_LOG("success");
    return 0;

EC_CLEANUP_BGN
    if (0 == rm)
    {
       // No error should occur logically.
       ec_rv_fatal( pthread_mutex_destroy(&m_sync) )
    }

    return -1;
EC_CLEANUP_END
}
예제 #4
0
void netlog(const char *format, ...){
#if NETREQUEST_DEBUG == 1
  FILE* logfp = NULL;
  va_list arg;
  va_start(arg, format);
  logfp = fopen(logFile, "aw");
  if(logfp != NULL){
    ec_rv( pthread_mutex_lock(&netrequest_log_mutex) );
    /* if(NETREQUEST_DEBUG)vfprintf(stderr, format, arg);*/
    fprintf(logfp, "\n%s", time2string());
    vfprintf(logfp, format, arg);
    ec_rv( pthread_mutex_unlock(&netrequest_log_mutex) );
    fclose(logfp);
    logfp = NULL;
  }
  va_end(arg);
  return;
EC_CLEANUP_BGN
  va_end(arg);
  if(logfp != NULL){ fclose(logfp); }
  return;
EC_CLEANUP_END
#endif
}
예제 #5
0
파일: tx4.c 프로젝트: 4get/aup2ex
/*[tx4]*/
static long get_and_incr_x(long incr)
{
	static long x = 0;
	static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
	long rtn;

	ec_rv( pthread_mutex_lock(&mtx) )
	rtn = x += incr;
	ec_rv( pthread_mutex_unlock(&mtx) )
	return rtn;

EC_CLEANUP_BGN
	exit(EXIT_FAILURE);
EC_CLEANUP_END
}
예제 #6
0
파일: tx4.c 프로젝트: 4get/aup2ex
int main(void)
{
	pthread_t tid;
	void *status;

	assert(sizeof(long) <= sizeof(void *));
	ec_rv( pthread_create(&tid, NULL, thread_func, (void *)6) )
	while (get_and_incr_x(0) < 10) {
		printf("Thread 1 says %ld\n", get_and_incr_x(1));
		sleep(2);
	}
	ec_rv( pthread_join(tid, &status) )
	printf("Thread 2's exit status is %ld\n", (long)status);
	return EXIT_SUCCESS;

EC_CLEANUP_BGN
	return EXIT_FAILURE;
EC_CLEANUP_END
}
예제 #7
0
int main(int argc, char** argv){
  if(argc != 1){
    fprintf(stderr, "Usage: %s\n", argv[0]);
  }

  self_debug_flag  = PVS_ACTOR_DEBUG;
  self = argv[0];

  ec_neg1( iop_install_handlers(chld_handler, intr_handler) );

  ec_neg1( pipe(pin) );
  ec_neg1( pipe(perr) );
  ec_neg1( pipe(pout) );

  /*it's time to fork */
  ec_neg1( child = fork() );

  if(child == 0){
    /* i'm destined to be pvs */
    ec_neg1( dup2(pin[0],  STDIN_FILENO) );
    ec_neg1( dup2(perr[1], STDERR_FILENO) );
    ec_neg1( dup2(pout[1], STDOUT_FILENO) );

    ec_neg1( close(pin[0])  );
    ec_neg1( close(perr[1]) );
    ec_neg1( close(pout[1]) );

    ec_neg1( execvp(pvs_exe, pvs_argv) );

  } else {
    /* i'm the boss */
    pthread_t errThread;
    fdBundle  errFdB;

    /* for monitoring the error stream */
    errFdB.fd = perr[0];
    errFdB.exit = &child_died;

    ec_neg1( close(pin[0])  );
    ec_neg1( close(perr[1]) );
    ec_neg1( close(pout[1]) );
    
    /* sleep(2); */
    
    ec_rv( pthread_create(&errThread, NULL, echoErrorsSilently, &errFdB) );
      
    announce("Listening to PVS\n");
    parsePVSThenEcho("\ncl-user(", pout[0], STDOUT_FILENO);

    write(pin[1], "(in-package 'pvs)\n", strlen("(in-package 'pvs)\n"));
    
    announce("Listening to PVS\n");

    parsePVSThenEcho("\npvs(", pout[0], STDOUT_FILENO);
    
    while(1){
      int length, retval;
      msg *query = NULL, *response = NULL;
      char *sender, *command;
      
      announce("Listening to IO\n");
      query = acceptMsg(STDIN_FILENO);
      if(query == NULL) continue;
      retval = parseActorMsg(query->data, &sender, &command);
      
      write(pin[1], command, strlen(command));
      write(pin[1], "\n", 1);
      
      announce("Listening to PVS\n");
      
      response = readPVSMsg("\npvs(", pout[0]);
      if(response != NULL){
	length = parseString(response->data, response->bytesUsed);
	response->bytesUsed = length;
	
	sendFormattedMsgFP(stdout, "%s\n%s\n%s\n", sender, self, response->data);
	
	if(self_debug_flag)writeMsg(STDERR_FILENO, response);
	announce("\nparseThenEcho wrote %d bytes\n", response->bytesUsed);
      }
      
      freeMsg(query);
      freeMsg(response);
      
    }
  }
  exit(EXIT_SUCCESS);

EC_CLEANUP_BGN
  exit(EXIT_FAILURE);
EC_CLEANUP_END

}