//Custom down
void down(Semaphore *s){
	
	pthread_t thread;
	thread = pthread_self(); //get the currently running thread

	enter_region(thread);
	if(thread == prod_thread){ //if producer
		s->val -= 1; 
		if(s->val < 0){
			//Save wake signal then sleep
			s->sig = PROD_SIGNAL;
			leave_region(thread);
			 
			my_sleep(PROD_SIGNAL);
		}
	} else if (thread == cons_thread){ //if consumer
		 
		s->val -= 1;
		 
		if(s->val < 0){
			//save wake signal then sleep
			s->sig = CONS_SIGNAL;
			leave_region(thread);
			 
			my_sleep(CONS_SIGNAL);
		}
	}
	leave_region(thread); //catchall

}
Example #2
0
File: g_vote.c Project: ETrun/ETrun
// Nico, delayed map change check function (thread)
void *G_delayed_map_change_watcher(void *arg) {
	int count    = 0;
	int limit    = 10; // Nico, in seconds
	int timeLeft = 0;

	// Nico, silent GCC
	(void)arg;

	while (!level.delayedMapChange.disabledWatcher) {
		if (level.time && level.delayedMapChange.timeChange) {
			// There is a delayed change

			if (level.time >= level.delayedMapChange.timeChange) {
				// Nico, do we have to wait for some threads to finish their work?
				while (activeThreadsCounter > 0 && count < limit) {
					threadingAllowed = qfalse;
					G_DPrintf("%s: waiting for %d thread%s before changing map\n", GAME_VERSION, activeThreadsCounter, activeThreadsCounter > 1 ? "s" : "");
					my_sleep(1000); // Nico, sleep for 1sec
					count++;
				}

				if (count >= limit) {
					G_Error("%s: warning, threads waiting timeout reached (threads: %d)", GAME_VERSION, activeThreadsCounter);
				}
				G_DPrintf("%s: changing map now!\n", GAME_VERSION);
				trap_SendConsoleCommand(EXEC_APPEND, va("map %s\n", level.delayedMapChange.passedVote));
				break;
			} else {
				timeLeft = (level.delayedMapChange.timeChange - level.time) / 1000;

				// Print incomming map change every 5 secs
				if (timeLeft % 5 == 0) {
					G_DPrintf("%s: map change to %s in %d sec%s\n", GAME_VERSION, level.delayedMapChange.passedVote, timeLeft, timeLeft > 1 ? "s" : "");
				}

				// Announce incomming map to players
				switch (timeLeft) {
				case 600:
					AP(va("cpm \"%s^w: map will be changed to ^Z%s ^win ^D10 ^wmins\n\"", GAME_VERSION_COLORED, level.delayedMapChange.passedVote));
					break;
				case 300:
					AP(va("cpm \"%s^w: map will be changed to ^Z%s ^win ^D5 ^wmins\n\"", GAME_VERSION_COLORED, level.delayedMapChange.passedVote));
					break;
				case 120:
					AP(va("cpm \"%s^w: map will be changed to ^Z%s ^win ^D2 ^wmins\n\"", GAME_VERSION_COLORED, level.delayedMapChange.passedVote));
					break;
				case 60:
					AP(va("cpm \"%s^w: map will be changed to ^Z%s ^win ^D1 ^wmin\n\"", GAME_VERSION_COLORED, level.delayedMapChange.passedVote));
					break;
				case 30:
					AP(va("cpm \"%s^w: map will be changed to ^Z%s ^win ^D30 ^wsecs\n\"", GAME_VERSION_COLORED, level.delayedMapChange.passedVote));
					break;
				}
			}
		}
		my_sleep(999);
	}
	return NULL;
}
Example #3
0
int main (int argc, char **argv) {
	my_sleep(10);
	set_background_priority(NORMAL_PRIORITY_CLASS);
	set_background_priority(BELOW_NORMAL_PRIORITY_CLASS);
	my_sleep(500);

	return 0;
}
Example #4
0
//------------------------------------------------------------------------------
PyObject* pybm_mid_set_radio_state(PyObject *self, PyObject *args)
{
    if (g_midState == UNDEFINED)
    {
        if (g_midErrorCallback) g_midErrorCallback("Current radio state is inknown !");
        return NULL;
    }

    // get state one would like to set hte radio to
    unsigned current = mid_getRadioState();
    unsigned state = current;
    //unsigned char notify = true;
    if (!PyArg_ParseTuple(args, "i", &state))
        return NULL;

    //if (state != current)
    {
        // depending on current state, we need to emulate MODE button press
        if ((current == RADIO_RADIO && state == RADIO_CD) ||
            (current == RADIO_CD    && state == RADIO_TAPE) ||
            (current == RADIO_TAPE  && state == RADIO_RADIO))
        {
            // send one MODE press event
            MODE_PRESS();
            MODE_RELEASE();

        }else if ((current == RADIO_RADIO && state == RADIO_TAPE) ||
                  (current == RADIO_CD    && state == RADIO_RADIO)||
                  (current == RADIO_TAPE  && state == RADIO_CD))
        {
            MODE_PRESS();
            MODE_RELEASE();
            my_sleep(50);
            MODE_PRESS();
            MODE_RELEASE();
        }else
        {
            MODE_PRESS();
            MODE_RELEASE();
            my_sleep(50);
            MODE_PRESS();
            MODE_RELEASE();
            my_sleep(50);
            MODE_PRESS();
            MODE_RELEASE();        
        }
    }

    // if notify is set, then call callbacks
    //if (notify && g_midForceRadioStateChangeCallback)
    //{
    //    g_midForceRadioStateChangeCallback();        
    //}
    
    // return void
    Py_INCREF(Py_None);
    return Py_None;
}
Example #5
0
int test_omp_task()
{
  int tids[NUM_TASKS];
  int i;

  #pragma omp parallel 
  {
    #pragma omp single
    {
      for (i = 0; i < NUM_TASKS; i++) {
        /* First we have to store the value of the loop index in a new variable
         * which will be private for each task because otherwise it will be overwritten
         * if the execution of the task takes longer than the time which is needed to 
         * enter the next step of the loop!
         */
        int myi;
        myi = i;
        #pragma omp task
        {
          my_sleep (SLEEPTIME);
          tids[myi] = omp_get_thread_num();
        } /* end of omp task */
      } /* end of for */
    } /* end of single */
  } /*end of parallel */

  /* Now we ckeck if more than one thread executed the tasks. */
  for (i = 1; i < NUM_TASKS; i++) {
    if (tids[0] != tids[i])
      return 1;
  }
  return 0;
} /* end of check_parallel_for_private */
Example #6
0
int main(int argc, char* argv[])
/*******************************************************************/
{
	int fd;
	struct termios oldtio, newtio;

	fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if (fd < 0) { 
		fprintf(stderr, "\n[NET32] : Serial FD Open fail ");
		fflush(stderr);
		perror(MODEMDEVICE); 
		system("reboot");
	}
	
	if (tcgetattr(fd, &oldtio) < 0)
	{
		fprintf(stderr, "\n[NET32] : error in tcgetattr ");
		fflush(stderr);
		system("reboot");
	}
	
	bzero(&newtio, sizeof(newtio));
	newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD;
	newtio.c_iflag = IGNPAR;
	newtio.c_oflag = 0;
	newtio.c_lflag = 0;
	newtio.c_cc[VTIME] = 0;
	newtio.c_cc[VMIN]  = 1;
	tcflush(fd, TCIFLUSH);
	tcsetattr(fd, TCSANOW, &newtio);

	while(1) {
		my_sleep(5,0);	
	}
}
Example #7
0
void mylock::get(ulonglong id, int milisecond) {
    int hash = id % MY_LOCK_HASH_SIZE;

redo:
    bool locked = false;
    pthread_mutex_lock(&mutexs_[hash]); 

    map<ulonglong, int>::iterator iter;

    pthread_rwlock_rdlock(&map_rwlock_);
    if ((iter = locks_.find(id)) != locks_.end()) {
        if (iter->second > 0) {
            locked = true;
        }
    }
    pthread_rwlock_unlock(&map_rwlock_);

    if (!locked) {
        pthread_rwlock_wrlock(&map_rwlock_);
        locks_[id] = 1;
        pthread_rwlock_unlock(&map_rwlock_);
    }

    pthread_mutex_unlock(&mutexs_[hash]);

    if (locked) {
        my_sleep(milisecond * 1000);
        goto redo;
    }
}
Example #8
0
/* Starts up the calendar thread.
 */
void *startup_timer_thread(void *arg)
{
	time_t justone = 0, trottime = 0;
	statistics_t trotstat;
	mythread_t *mt;

	thread_init();

	mt = thread_get_mythread();

	while (thread_alive (mt)) {
		time_t stime = get_time();

		timer_handle_status_lines (stime);

		timer_handle_transfer_statistics (stime, &trottime, &justone, &trotstat);

		if (mt->ping == 1)
			mt->ping = 0;

		my_sleep(400000);
	}
	
	thread_exit(7);
	return NULL;
}
Example #9
0
int radio_init() {

#ifdef _WIN32
// This turns off the error dialog that Windows throws up. 
// Just a time saver when you're debugging a crashy program.
DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);
#endif

#ifdef __linux
 signal(SIGSEGV, my_handler);
 signal(SIGABRT, my_handler);
#endif

 // initialize and open the rtlsdr device. 
 radio.set_name("radio");
 int dev_count = radio.list_rtl_devices();
 int index     = 0;
 if (index >= dev_count) {
  std::cerr << "-err-- no such device index" << std::endl;;
  exit(-1);
 }
 radio.open_rtl_device(index);

 pthread_t dsp_thread;
 pthread_t rtl_thread;

 pthread_create(&dsp_thread,NULL,dsp_thread_fn,&radio);
 pthread_create(&rtl_thread,NULL,rtl_thread_fn,&radio);

 my_sleep(100);
}
int LshttpdMain::testRunningServer()
{
    int count = 0;
    int ret;
    do
    {
        ret = m_pidFile.lockPidFile( PID_FILE );
        if ( ret )
        {
            if (( ret == -2 )&&( errno == EACCES || errno == EAGAIN ))
            {
                ++count;
                if ( count >= 10 )
                {
                    perr("LiteSpeed Web Server is running!" );
                    return 2;
                }
                my_sleep( 100 );
            }
            else
            {
                fprintf( stderr, "[ERROR] Failed to write to pid file:%s!\n", PID_FILE );
                return ret;
            }
        }
        else
            break;
    }while( true );
    return ret;
}
Example #11
0
int main()
{
	int semid,shmid;
	char *shmaddr=NULL;

	if((shmid=createshm(".",'m',SHM_SIZE))==-1)
	{
		exit(1);
	}

	if((shmaddr=shmat(shmid,(char*)0,0))==(char *)-1)
	{
		perror("attach shared memory error\n");
		exit(1);
	}

	if((semid=opensem(".",'s'))==-1)
	{
		exit(1);
	}

	while(1)
	{
                waitsem(semid,0);
		p(semid,0);
		printf("reader:");
		printf("%s\n",shmaddr);
		my_sleep(5);
		v(semid,0);
	//	my_sleep(5);
	}
	
}
Example #12
0
int main(void)
{
	struct timeval begintime, endtime;
	float elapsed;
	unsigned int rest;
	
	// 设置 SIGUSR1 的信号处理函数,不设置的话 SIGUSR1 信号不能从 pause 函数中唤醒进程
	if (signal(SIGUSR1, sigusr1_handler) == SIG_ERR) {
		perror("can't set handler for SIGUSR1");
		exit(1);	
	}

	printf("the first time\n");
	printf("before sleeping\n");

	gettimeofday(&begintime, NULL);
	
	my_sleep(10);

	printf("after sleep\n");

	gettimeofday(&endtime, NULL);

	elapsed = 1000000 * (endtime.tv_sec - begintime.tv_sec) + endtime.tv_usec - begintime.tv_usec;
	elapsed /= 1000000;

	printf("elapsed time is %f\n", elapsed);

	printf("the second time \n");
	printf("before sleeping\n");

	gettimeofday(&begintime, NULL);
	
	rest = my_sleep(20);

	printf("after sleep\n");

	gettimeofday(&endtime, NULL);

	elapsed = 1000000 * (endtime.tv_sec - begintime.tv_sec) + endtime.tv_usec - begintime.tv_usec;
	elapsed /= 1000000;

	printf("actual sleeping-time is %f\n", elapsed);
	printf("the rest is %u\n", rest);

	return 0;
}
Example #13
0
JNIEXPORT jobject JNICALL Java_node_NodeDynamicProxyClass_callJs(JNIEnv *env, jobject src, jlong ptr, jobject method, jobjectArray args) {
  threadId myThreadId = my_getThreadId();

  bool hasArgsGlobalRef = false;

  // args needs to be global, you can't send env across thread boundaries
  DynamicProxyData* dynamicProxyData = (DynamicProxyData*)ptr;
  dynamicProxyData->args = args;
  dynamicProxyData->done = false;
  dynamicProxyData->result = NULL;
  dynamicProxyData->throwableClass = "";
  dynamicProxyData->throwableMessage = "";

  jclass methodClazz = env->FindClass("java/lang/reflect/Method");
  jmethodID method_getName = env->GetMethodID(methodClazz, "getName", "()Ljava/lang/String;");
  dynamicProxyData->methodName = javaObjectToString(env, env->CallObjectMethod(method, method_getName));
  assertNoException(env);

  uv_work_t* req = new uv_work_t();
  req->data = dynamicProxyData;
  if(v8ThreadIdEquals(myThreadId, v8ThreadId)) {
#if NODE_MINOR_VERSION >= 10
    EIO_AfterCallJs(req, 0);
#else
    EIO_AfterCallJs(req);
#endif
  } else {
    if (args) {
      // if args is not null and we have to kick this across the thread boundary, make it a global ref
      dynamicProxyData->args = (jobjectArray) env->NewGlobalRef(args);
      hasArgsGlobalRef = true;
    }

    uv_queue_work(uv_default_loop(), req, EIO_CallJs, (uv_after_work_cb)EIO_AfterCallJs);

    while(!dynamicProxyData->done) {
      my_sleep(100);
    }
  }

  if(!dynamicProxyDataVerify(dynamicProxyData)) {
    throwNewThrowable(env, "java/lang/IllegalStateException", "dynamicProxyData was corrupted");
  }
  if(hasArgsGlobalRef) {
    env->DeleteGlobalRef(dynamicProxyData->args);
  }

  if (dynamicProxyData->done == DYNAMIC_PROXY_JS_ERROR) {
    throwNewThrowable(env, dynamicProxyData->throwableClass.c_str(), dynamicProxyData->throwableMessage);
  }

  jobject result = NULL;
  if(dynamicProxyData->result) {
    // need to retain a local ref so that we can return it, otherwise the returned object gets corrupted
    result = env->NewLocalRef(dynamicProxyData->result);
    env->DeleteGlobalRef(dynamicProxyData->result);
  }
  return result;
}
Example #14
0
void message_queue_test_case()
{
	pid_t pid = fork();
	check_errors(pid, "fork");
	if (pid == 0)
	{
		// Writer
		int msgflg = IPC_CREAT | 0666;
		key_t key = 1234;
		static struct message_buf send_data;
		//size_t buf_length;

		int msqid = msgget(key, msgflg);
		check_errors(msqid, "msgget");

		send_data.mtype = 1;

		for (size_t i = 0; i < sizeof(send_data.buffer); i++)
			send_data.buffer[i] = (unsigned char)(i);

		char *current = (char*)send_data.buffer;
		while(current - (char*)send_data.buffer < DATA_SIZE)
		{
			int result = msgsnd(msqid, &current, MSGSIZE + 1, IPC_NOWAIT);
			check_errors(result, "msgsnd");

			current += MSGSIZE;
		}

//		strcpy(send_data.buffer, "Did you get this?");
//		buf_length = strlen(send_data.buffer) + 1 ;

//		int result = msgsnd(msqid, &send_data, buf_length, IPC_NOWAIT);
//		check_errors(result, "msgsnd");

		//printf("Message: \"%s\" Sent\n", send_data.buffer);
		exit(0);
	}
	else
	{
		// Reader
		my_sleep(0 ,10);

		key_t key = 1234;
		static struct message_buf recieved_data;

		int msqid = msgget(key, 0666);
		check_errors(msqid, "msgget");

		int result = msgrcv(msqid, &recieved_data, DATA_SIZE, 1, 0);
		check_errors(result, "msgrcv");

		printf("I recieved: %s\n", recieved_data.buffer);
	}
}
Example #15
0
int FetcherManager::stop() {
    int ret = Manager::stop();

    while(!canstoped()) {
        my_sleep(500000); //0.5 seconds
    }

    curl_share_cleanup(sh);
    curl_global_cleanup();
    return ret;
}
Example #16
0
File: sock.c Project: ngmon/ngmon
int main(int argc, char *argv[])
{
    int sock;                        	/* Socket descriptor */
    struct sockaddr_in echoServAddr; 	/* Echo server address */
    unsigned short echoServPort = 5000; /* Echo server port */
    char *servIP = "127.0.0.1";      	/* Server IP address (dotted quad) */
    char *echoString;                	/* String to send */
    unsigned int echoStringLen;      	/* Length of string */
    int loops;
    int sleep_time;

    if ((argc < 3) || (argc > 3))    	/* Test for correct number of arguments */
    {
       fprintf(stderr, "Usage: %s <loops> <sleep_time_milis>\n",
               argv[0]);
       exit(1);
    }
	
	loops = atoi(argv[1]);
	sleep_time = atoi(argv[2]);	

    /* Create a reliable, stream socket using TCP */
    if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) error("socket() failed");

    /* Construct the server address structure */
    memset(&echoServAddr, 0, sizeof(echoServAddr));     /* Zero out structure */
    echoServAddr.sin_family      = AF_INET;             /* Internet address family */
    echoServAddr.sin_addr.s_addr = inet_addr(servIP);   /* Server IP address */
    echoServAddr.sin_port        = htons(echoServPort); /* Server port */

    /* Establish the connection to the echo server */
    if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) error("connect() failed");


	int avg = sleep_time;		
	int i;
	
	for (i = 0; i < loops; i++) {
		
		echoString = event_string();
		echoStringLen = strlen(echoString);          /* Determine input length */
		
		if (send(sock, echoString, echoStringLen, 0) != echoStringLen) error("send() sent a different number of bytes than expected"); /* Send the string to the server */
		
		avg += my_sleep(sleep_time);
		avg = avg/2;
	}
	
    printf("%d:%d",avg, i);   
    printf("\n");    /* Print a final linefeed */

    close(sock);
    exit(0);
}
Example #17
0
int
NdbSleep_MilliSleep(int milliseconds){
  my_sleep(milliseconds*1000);
  return 0;
#if 0
  int result = 0;
  struct timespec sleeptime;
  sleeptime.tv_sec = milliseconds / 1000;
  sleeptime.tv_nsec = (milliseconds - (sleeptime.tv_sec * 1000)) * 1000000;
  result = nanosleep(&sleeptime, NULL);
  return result;
#endif
}
Example #18
0
int test_omp_taskyield()
{
  int i;
  int count = 0;
  int start_tid[NUM_TASKS];
  int current_tid[NUM_TASKS];

  for (i=0; i< NUM_TASKS; i++) {
    start_tid[i]=0;
    current_tid[i]=0;
  }

  #pragma omp parallel
  {
    #pragma omp single
    {
      for (i = 0; i < NUM_TASKS; i++) {
        int myi = i;
        #pragma omp task untied
        {
          my_sleep(SLEEPTIME);
          start_tid[myi] = omp_get_thread_num();
          #pragma omp taskyield
          if((start_tid[myi] %2) ==0){
            my_sleep(SLEEPTIME);
            current_tid[myi] = omp_get_thread_num();
          } /*end of if*/
        } /* end of omp task */
      } /* end of for */
    } /* end of single */
  } /* end of parallel */
  for (i=0;i<NUM_TASKS; i++) {
    //printf("start_tid[%d]=%d, current_tid[%d]=%d\n",
      //i, start_tid[i], i , current_tid[i]);
    if (current_tid[i] == start_tid[i])
      count++;
  }
  return (count<NUM_TASKS);
}
Example #19
0
int test_omp_sections_nowait()
{
  int result;
  int count;
  int j;

  result = 0;
  count = 0;

  #pragma omp parallel
  {
    int rank;
    rank = omp_get_thread_num ();
    #pragma omp sections nowait
    {
      #pragma omp section
      {
        fprintf(stderr, "Thread nr %d enters first section"
          " and gets sleeping.\n", rank);
        my_sleep(SLEEPTIME);
        count = 1;
        fprintf(stderr, "Thread nr %d woke up an set"
          " count to 1.\n", rank);
        #pragma omp flush(count)
      }
      #pragma omp section
      {
        fprintf(stderr, "Thread nr %d executed work in the"
          " first section.\n", rank);
      }
    }
    /* Begin of second sections environment */
    #pragma omp sections
    {
      #pragma omp section
      {
        fprintf(stderr, "Thread nr %d executed work in the"
          " second section.\n", rank);
      }
      #pragma omp section
      {
        fprintf(stderr, "Thread nr %d executed work in the"
          " second section and controls the value of count\n", rank);
        if (count == 0)
          result = 1;
        fprintf(stderr, "count was %d\n", count);
      }
    }
  }
  return result;
}
Example #20
0
int test_omp_get_wtime()
{
  double start;
  double end;
  double measured_time;
  double wait_time = 5.0;
  start = 0;
  end = 0;
  start = omp_get_wtime();
  my_sleep (wait_time);
  end = omp_get_wtime();
  measured_time = end-start;
  return ((measured_time > 0.97 * wait_time) && (measured_time < 1.03 * wait_time)) ;
}
Example #21
0
void unix_domain_sockets_test_case()
{
	printf("Unix domain sockets test case\n");
	pid_t pid = fork();
	check_errors(pid, "fork");
	if (pid == 0)
	{
		unix_domain_sockets_server();
		exit(0);
	}
	else //parent
	{
		my_sleep(0, 10);
		unix_domain_sockets_client();
	}
}
Example #22
0
//------------------------------------------------------------------------------
PyObject* pybm_mid_req_update_fields(PyObject *self, PyObject *args)
{    
    if (g_ipcClient)
    {
        // C0 06 FF 20 00 B3 00
        std::vector<unsigned char> data(4);
        data[0] = 0x20;
        data[1] = 0x00;
        data[2] = 0xB3;
        data[3] = 0x00;
        IPCClient::IBusMessage msg(0xC0, 0xFF, data);

        g_ipcClient->send(msg);
    }

#if 0
    // C0 06 FF 20 02 8E 00 xx
    // C0 06 FF 20 01 B0 00 xx
    if (g_ipcClient)
    {
        std::vector<unsigned char> data(4);
        data[0] = 0x20;
        data[1] = 0x02;
        data[2] = 0x8E;
        data[3] = 0x00;
        IPCClient::IBusMessage msg(0xC0, 0xFF, data);

        g_ipcClient->send(msg);
    }
    my_sleep(100);
    
    if (g_ipcClient)
    {
        std::vector<unsigned char> data(4);
        data[0] = 0x20;
        data[1] = 0x01;
        data[2] = 0xB0;
        data[3] = 0x00;
        IPCClient::IBusMessage msg(0xC0, 0xFF, data);

        g_ipcClient->send(msg);
    }
#endif
    // return void
    Py_INCREF(Py_None);
    return Py_None;
}
Example #23
0
void pipex_exit(pipex_t *pipex, int kill_timeout){
    int status;
    int elapsed_time;
    bool exited;
    int ret;

    my_log("POLYGLOT Waiting for child process to exit.\n");

    elapsed_time=0;
    exited=FALSE;
    ret=0;
    while(elapsed_time<kill_timeout){
      ret=waitpid(pipex->pid,&status,WNOHANG);
      if(ret==0){
	my_log("POLYGLOT Child has not exited yet. Sleeping %dms.\n", WAIT_GRANULARITY);
	my_sleep(WAIT_GRANULARITY);
	elapsed_time+=WAIT_GRANULARITY;
      }else{
	exited=TRUE;
	break;
      }
    }
    if(!exited){
      my_log("POLYGLOT Child wouldn't exit by itself. Terminating it.\n");
      kill(pipex->pid,SIGKILL);
      waitpid(pipex->pid,&status,0);    
    }
    if(WIFEXITED(status)){
      if(pipex->quit_pending){
	my_log("POLYGLOT Child exited with status %d.\n",WEXITSTATUS(status));
      }else{
	// Suppress further messages.
	pipex->quit_pending=TRUE;
	my_fatal("pipex_exit(): %s: child exited with status %d.\n",pipex->command,WEXITSTATUS(status));
      }
    }else if(WIFSIGNALED(status)){
      if(pipex->quit_pending){
	my_log("POLYGLOT pipex_exit(): %s: child terminated with signal %d.\n",pipex->command,WTERMSIG(status));
      }else{
	// Suppress further messages.
	pipex->quit_pending=TRUE;
	  my_fatal("pipex_exit(): %s: child terminated with signal %d.\n",pipex->command,WTERMSIG(status));
      }
    }
    return;
}
Example #24
0
void
check_transfer_rate(struct request *rq, int size)
{
    struct group	*group ;
    int		cbytes, bw;

    /* LOCK_CONFIG must be done, but this slow things down */
    group = rq_to_group(rq);
    if ( group ) {
        bw = group->bandwidth;
        cbytes = MID(bytes);
        if ( cbytes < bw )
            return;
        /* must sleep a little. */
        my_sleep(1);
    }
}
Example #25
0
File: client.c Project: gonwan/toys
int main()
{
    int i, client_socks[MAX_CLIENT];
    struct sockaddr_in server_addr;
    char msg[32];
#ifdef WIN32
    WSADATA wsaData;
    WSAStartup(0x0202, &wsaData);
#endif

    srand((unsigned)time(0));
    memset(&server_addr, 0, sizeof(struct sockaddr_in));
    server_addr.sin_family = AF_INET;
    server_addr.sin_addr.s_addr = inet_addr(SERVER_ADDR);
    server_addr.sin_port = htons(SERVER_PORT);
    memset(client_socks, 0xff, sizeof(client_socks)); /* -1 */
    /* simulate multi-threading here, to avoid separate windows/linux code :) */
    while (1) {
        for (i = 0; i < MAX_CLIENT; i++) {
            int r = rand() % MAX_CLIENT;
            if (client_socks[r] != -1) {
                sock_close(client_socks[r]);
            }
            client_socks[r] = (int)socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
            if (client_socks[r] != -1) {
                connect(client_socks[r], (struct sockaddr *)&server_addr, sizeof(struct sockaddr_in));
                memset(msg, 0, sizeof(msg));
                sprintf(msg, "from client socket[%d]", client_socks[r]);
                printf("Client socket send: %s.\n", msg);
                sock_send(client_socks[r], msg, (int)strlen(msg));
            }
        }
        my_sleep(1000);
    }
    for (i = 0; i < MAX_CLIENT; i++) {
        if (client_socks[i] != -1) {
            sock_close(client_socks[i]);
        }
    }
#ifdef WIN32
    WSACleanup();
#endif
    return 0;
}
Example #26
0
void	aff_text(t_data *data, t_bunny_picture *text)
{
  int	i;
  t_bunny_position	pos;

  pos.x = data->player.x - 100;
  pos.y = data->player.y - 350;
  i = 0;
  while (i < 250)
    {
      aff_map(data);
      player_stop(data);
      (data->inv.open == 1 ? aff_inventory(data) : (void)0);
      bunny_blit(&data->win->buffer, text, &pos);
      bunny_display(data->win);
      my_sleep(200);
      i++;
    }
}
int main(int argc, char *argv[]){

	if(pipe(fd) < 0) {fprintf(stderr, "Piping failled\n"); exit(1);}

	pid = fork();
	if (pid < 0){
			printf("fork error %d\n", pid);
	}
	else if(pid != 0){
		// parent process
		//close(fd[0]);	
		while(1){
			signal(SIGINT, parent_handler);
			pause();

		 	if(strcmp(buffer, "exit\n") == 0){
				printf("Child is diying\n");
				kill(pid, SIGKILL);
				wait(NULL);
				exit(1);
			}else{
				write(fd[1], buffer, 512);
				kill(pid, SIGFPE);
			}
		}
		//close(wtr);
	}
	else{
		// child process
		//close(wtr);
		signal(SIGINT, SIG_IGN);
		int flag = 1;
		while(flag == 1){
			signal(SIGFPE, child_handler);
			my_sleep();
		}
		//close(rdr);
	}
	return 0;
}
Example #28
0
/*
 * Write a string to a socket. 
 * Return 1 if all bytes where successfully written, and 0 if not.
 * Assert Class: 2
 */
int sock_write_string(SOCKET sockfd, const char *buff)
{
	int write_bytes = 0, res = 0, len = ice_strlen(buff);

	if (!sock_valid(sockfd)) {
		fprintf(stderr,
			"ERROR: sock_write_string() called with invalid socket\n");
		return -1;
	} else if (!buff) {
		fprintf(stderr,
			"ERROR: sock_write_string() called with NULL format\n");
		return -1;
	}

	/*
	 * Never use send() to sockets 0 or 1 in Win32.
	 */

	if (sockfd == 1 || sockfd == 0) {
		if (running == SERVER_RUNNING) {
			write_bytes = fprintf(stdout, "%s", buff);
			fflush(stdout);
		}
	} else {
		while (write_bytes < len) {
			res =
				send(sockfd, &buff[write_bytes],
				     len - write_bytes, 0);
			if (res < 0 && !is_recoverable(errno))
				return 0;
			if (res > 0)
				write_bytes += res;
			else
				my_sleep(30000);
		}
	}

	return (write_bytes == len ? 1 : 0);
}
Example #29
0
File: main.c Project: PyHDI/PyCoRAM
//------------------------------------------------------------------------------
void pycoram_main()
{
  Uint mem_offset;
  //Uint address_width;
  Uint dma_size;
  Uint data_size;

  mem_offset = *((volatile Uint*)(MMAP_MEMORY + 0));
  //address_width = *((volatile Uint*)(MMAP_MEMORY + 4));
  dma_size = *((volatile Uint*)(MMAP_MEMORY + 8));
  data_size = *((volatile Uint*)(MMAP_MEMORY + 12));

  *((volatile Uint*)(MMAP_PYCORAM_IP)) = (volatile int) mem_offset;
  //*((volatile Uint*)(MMAP_PYCORAM_IP)) = (volatile int) address_width;
  *((volatile Uint*)(MMAP_PYCORAM_IP)) = (volatile int) dma_size;
  *((volatile Uint*)(MMAP_PYCORAM_IP)) = (volatile int) data_size;

  // wait 
  Uint cycles = *((volatile Uint*)(MMAP_PYCORAM_IP));

  my_sleep(1000);
  Xil_DCacheInvalidate();

  //printf("cycles=%d\n", 0);
  mylib_display_char('c');
  mylib_display_char('y');
  mylib_display_char('c');
  mylib_display_char('l');
  mylib_display_char('e');
  mylib_display_char(':');
  mylib_display_dec(cycles);
  mylib_display_newline();

  mylib_display_char('E');
  mylib_display_char('N');
  mylib_display_char('D');
}
Example #30
0
int test_omp_task_if()
{
  int condition_false;
  int count;
  int result;

  count=0;
  condition_false = (count == 1);
  #pragma omp parallel 
  {
    #pragma omp single
    {
      #pragma omp task if (condition_false) shared(count, result)
      {
        my_sleep (SLEEPTIME);
        #pragma omp critical
        result = (0 == count);
      } /* end of omp task */
      #pragma omp critical
      count = 1;
    } /* end of single */
  } /*end of parallel */
  return result;
}