示例#1
0
void 
skynet_timer_init(void) {
	TI = timer_create_timer();
	TI->current = _gettime();

	struct timespec ti;
	clock_gettime(CLOCK_REALTIME, &ti);
	uint32_t sec = (uint32_t)ti.tv_sec;
	uint32_t mono = _gettime() / 100;

	TI->starttime = sec - mono;
}
示例#2
0
static unsigned char *get_pcm_data(VisAudio *audio)
{
    VisBuffer buf;
    float pcmbuf[MAXSIZE];
    static unsigned char retbuf[MAXSIZE];
    static int first_call = TRUE;
    static int then = 0;
    int now = _gettime(0);
    int i;

    /* Cache results every 25ms apart, skipping first call */
    if(first_call == FALSE && now - then > 25) {
        then = now;
        return retbuf;
    }

    first_call = FALSE;

    visual_buffer_set_data_pair(&buf, pcmbuf, MAXSIZE);

    visual_audio_get_sample_mixed(audio, &buf, TRUE, 2,
        VISUAL_AUDIO_CHANNEL_LEFT,
        VISUAL_AUDIO_CHANNEL_RIGHT,
        1.0,
        1.0);
    
    for(i = MAXSIZE; i; i--)
    {
        retbuf[i-1] = pcmbuf[i-1] * UCHAR_MAX;
    }
    
    return retbuf;
}
示例#3
0
void StopWatch::stop()
{
  if (_state == StopWatch::RUNNING)
  {
    _stoptime = _gettime();
    _state = StopWatch::STOPPED;
  }
}
示例#4
0
uint32_t StopWatch::value()
{
  if (_state == StopWatch::RUNNING)
  {
    _stoptime = _gettime();
  }
  return _stoptime - _starttime;
}
示例#5
0
void
skynet_timer_init(void) {
    TI = timer_create_timer();
    TI->current = _gettime();

#if defined(_POSIX_TIMERS)
    struct timespec ti;
    clock_gettime(CLOCK_REALTIME, &ti);
    uint32_t sec = (uint32_t)ti.tv_sec;
#else
    struct timeval tv;
    gettimeofday(&tv, NULL);
    uint32_t sec = (uint32_t)tv.tv_sec;
#endif
    uint32_t mono = _gettime() / 100;

    TI->starttime = sec - mono;
}
示例#6
0
void StopWatch::start()
{
  if (_state == StopWatch::RESET || _state == StopWatch::STOPPED)
  {
    _state = StopWatch::RUNNING;
    uint32_t t = _gettime();
    _starttime += t - _stoptime;
    _stoptime = t;
  }
}
示例#7
0
static void
_updatetime(struct timer * t) {
	uint32_t ct = _gettime();
	if (ct > t->current) {
		int diff = ct-t->current;
		t->current = ct;
		int i;
		for (i=0;i<diff;i++) {
			send_tick(t->sys);
		}
	}
}
示例#8
0
文件: chatLog.cpp 项目: kaina/sandbox
bool CChatLog::_checkdate(SYSTEMTIME* lpst)
{
	SYSTEMTIME t = _gettime(lpst);

	if ((t.wYear != m_st.wYear) || (t.wMonth != m_st.wMonth) || (t.wDay != m_st.wDay))
	{
		release();
		_acquire(&t);
	}

	return alive();
}
示例#9
0
void
skynet_updatetime(void) {
	uint32_t ct = _gettime();
	if (ct != TI->current) {
		int diff = ct>=TI->current?ct-TI->current:(0xffffff+1)*100-TI->current+ct;
		TI->current = ct;
		int i;
		for (i=0;i<diff;i++) {
			timer_update(TI);
		}
	}
}
示例#10
0
void
skynet_updatetime(void) {
	uint32_t ct = _gettime();
	if (ct > TI->current) {
		int diff = ct-TI->current;
		TI->current = ct;
		int i;
		for (i=0;i<diff;i++) {
			timer_execute(TI);
		}
	}
}
示例#11
0
文件: chatLog.cpp 项目: kaina/sandbox
void CChatLog::_acquire(SYSTEMTIME* lpst)
{
	SYSTEMTIME t = _gettime(lpst);

	TCHAR* filename = new TCHAR[MAX_PATH];
	_sntprintf(filename, MAX_PATH, _T("Chat\\%04d-%02d-%02d.txt"), t.wYear, t.wMonth, t.wDay);

	if (acquire(filename) == true)
	{
		::SetFilePointer(get(), 0, NULL, FILE_END);
		m_st = t;
	}

	delete [] filename;
}
示例#12
0
文件: window.c 项目: AsamQi/ejoy2d
int
main(int argc, char *argv[]) {
    XEvent event;
    uint32_t timestamp = 0;
    init_x();
    font_init();

    ejoy2d_win_init(argc, argv);

    for (;;) {
        
        while(XPending(g_X.display) > 0) {  
            XNextEvent(g_X.display, &event);
            if (XFilterEvent(&event,None))
                continue;
            switch (event.type) {
            case Expose:
                if (event.xexpose.count==0)
                    update_frame();
                break;
            case ButtonPress:
                ejoy2d_win_touch(event.xbutton.x, event.xbutton.y, TOUCH_BEGIN);
                break;
            case ButtonRelease:
                ejoy2d_win_touch(event.xbutton.x,event.xbutton.y,TOUCH_END);
                break;
            case MotionNotify:
                ejoy2d_win_touch(event.xbutton.x,event.xbutton.y,TOUCH_MOVE);
                break;
            }
        }

        uint32_t old = timestamp;
        timestamp= _gettime();
        if (timestamp - old >= UPDATE_INTERVAL) {
            ejoy2d_win_update();
            update_frame();
        }
        else
            usleep(1000);
    }
}
示例#13
0
文件: linux.c 项目: zhoukk/pixel
int main(int argc, char *argv[]) {
	XEvent event;
	KeySym keysym;
	char keychar[255];
	uint32_t timestamp = 0;
	uint32_t current;

	init_x();

	pixel_start(WIDTH, HEIGHT, argv[1]);

	for (;;) {
		while(XPending(g_X.display) > 0) {
			XNextEvent(g_X.display, &event);
			if (XFilterEvent(&event, None))
				continue;
			switch (event.type) {
			case Expose:
				if (event.xexpose.count==0) {
					pixel_frame(0.01f);
					glXSwapBuffers(g_X.display, g_X.wnd);
				}
				break;
			case KeyPress:
				XLookupString(&event.xkey, keychar, 255, &keysym, 0);
				pixel_key(KEY_DOWN, keychar[0]);
				break;
			case KeyRelease:
				XLookupString(&event.xkey, keychar, 255, &keysym, 0);
				pixel_key(KEY_UP, keychar[0]);
				break;
			case ButtonPress:
				pixel_touch(0, TOUCH_BEGIN, event.xbutton.x, event.xbutton.y);
				break;
			case ButtonRelease:
				pixel_touch(0, TOUCH_END, event.xbutton.x, event.xbutton.y);
				break;
			case MotionNotify:
				pixel_touch(0, TOUCH_MOVE, event.xbutton.x, event.xbutton.y);
				break;
			case ClientMessage:
				if ((Atom)event.xclient.data.l[0] == wm_delete_window) {
					Display *dis;
					pixel_close();
					glXMakeCurrent(g_X.display, g_X.wnd, NULL);
					dis = g_X.display;
					XFreeGC(dis, gc);
					XDestroyWindow(dis, g_X.wnd);
					XCloseDisplay(dis);
					exit(0);
				}
				break;
			}
		}
		current = _gettime();
		if (current - timestamp >= UPDATE_INTERVAL) {
			float t = (current - timestamp)/100.0f;
			timestamp = current;
			pixel_update(t);
			pixel_frame(t);
			glXSwapBuffers(g_X.display, g_X.wnd);
		} else {
			usleep(1000);
		}
	}
}
示例#14
0
void AP_USB_Copytest(void)
{
	int i, ok = 0;
	char *buf, *pbuf;
	int read_size, ret, per_loop_read_size, total_read_size=0;
	double final_total_sec=0;
	double USB_speed=0;
    struct timespec diff_time, total_time;

    memset(&total_time, 0, sizeof(struct timespec));

	for(i = (loop) ? loop : ~0; i > 0; --i)
	{
		per_loop_read_size=0;
		printf("%dth testing ...........................................\n",loop-i+1);

	    /* buffer */
		buf = malloc(RBUFSIZE);

		if( buf == NULL )
        {
			fprintf( stderr, "ERROR!! allocate memory(%dM) failed! (#%d: %s)\n",1048576/1048576, errno, strerror(errno) );
			exit(1);
		}


	    /* read and write through pbuf */
		pbuf = buf;

        _timerswitch(SWITCH_ON);
        while( !feof(fp_src) )
		{
			ret = fread( pbuf, 1, RBUFSIZE, fp_src );

			if( ret <  RBUFSIZE )
            {
				if( !feof(fp_src) )
                {
					fprintf( stderr, "ERROR!! read SRC failed! (#%d: %s)\n", errno, strerror(errno) );
					exit(1);
				}
			}
			read_size = ret;
			per_loop_read_size += read_size;
			total_read_size += read_size;

            printf("read_size=%d, per_loop_read_size=%d, total_read_size=%d\n", read_size, per_loop_read_size, total_read_size);

			ret = fwrite( pbuf, 1, read_size, fp_des );

			if( ret < read_size )
			{
				fprintf( stderr, "ERROR!! write DES failed! (#%d: %s)\n", errno, strerror(errno) );
				exit(1);
			}
		}

        fflush(fp_des); //clear stdin register
		fsync(fileno(fp_des));  //sync buff to disk
        _timerswitch(SWITCH_OFF);

        diff_time = _gettime();
		total_time.tv_sec = total_time.tv_sec + diff_time.tv_sec;
		total_time.tv_nsec = total_time.tv_nsec + diff_time.tv_nsec;


        //printf("finished %dth................. ok/total %d/%d .......................................\n\n",loop-i+1, loop, loop-i+1);

        if((loop-i+1)==loop)
    	{
    	    final_total_sec = CAL_TIME((double)total_time.tv_sec,(double)total_time.tv_nsec)/loop;
            printf("AVG R/W TOTAL TIME:%f sec\n",final_total_sec);
        	USB_speed = ((stat_src.st_size) /final_total_sec)/(1024*1024);
        	printf("SPEED:%f MBps\n",USB_speed);
        }

		free(buf);

	   /* execute diff mechanism */
	   if(diff_flag)
       {
			printf("call diff\n");
			if( !_comparefile() )
			   ++ok;
			else
			{
				printf("File Compare error and finished and exit...\n");
				exit(1);
			}

			printf("File Compare finished...\n");
       }/*if(diff_flag)*/


		sleep(1);
        printf("File Copy finished...\n"); //---> [GENE]
		printf("finished %dth................. ok/total %d/%d .......................................\n",loop-i+1, loop, loop-i+1);

        fseek(fp_src,0,SEEK_SET);
        fseek(fp_des,0,SEEK_SET);

	}/*TCC110729: for(i = (loop) ? loop : ~0; i > 0; --i)*/

	fclose(fp_src);
	fclose(fp_des);
}
示例#15
0
文件: chatLog.cpp 项目: kaina/sandbox
void CChatLog::output(enum CHAT type, BYTE* buf, ...)
{
	SYSTEMTIME t = _gettime(NULL);

	if (_checkdate(&t) == false)
		return;	// ファイル関連の障害ぐらい...
 

	va_list ap;
	va_start(ap, buf);


	switch (type)
	{
		case CT_ZONEINFO:
			{
				int p1 = va_arg(ap, int);	// mapname
				TCHAR* name = va_arg(ap, TCHAR*);
				adjust(_T("SYS %s has connected\r\n"), name);
				adjust(_T("MAP %s (%04d-%02d-%02d %02d:%02d:%02d)\r\n"), buf+p1, t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
			}
			break;

		case CT_CHANGEMAP:
		case CT_CHANGEZONE:
			{
				int p1 = va_arg(ap, int);	// mapname
				adjust(_T("MAP %s (%04d-%02d-%02d %02d:%02d:%02d)\r\n"), buf+p1, t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
			}
			break;

		case CT_MVP:
			{
				DWORD AID = va_arg(ap, DWORD);	// AID
				adjust(_T("MVP %02d:%02d:%02d AID=%08X\r\n"), t.wHour, t.wMinute, t.wSecond, AID);
			}
			break;

		case CT_NORMALCHAT:
		case CT_NORMALCHAT_OWN:
			{
				int p1 = va_arg(ap, int);	// body
				adjust(_T("%s %02d:%02d:%02d %s\r\n"), _T("NOR"), t.wHour, t.wMinute, t.wSecond, buf+p1);
			}
			break;

		case CT_SENDWHISPER:
			{
				int p1 = va_arg(ap, int);	// name
				int p2 = va_arg(ap, int);	// body
				adjust(_T("WIS %02d:%02d:%02d TO %s : %s\r\n"), t.wHour, t.wMinute, t.wSecond, buf+p1, buf+p2);
			}
			break;

		case CT_RECVWHISPER:
			{
				int p1 = va_arg(ap, int);	// name
				int p2 = va_arg(ap, int);	// body
				adjust(_T("WIS %02d:%02d:%02d FROM %s : %s\r\n"), t.wHour, t.wMinute, t.wSecond, buf+p1, buf+p2);
			}
			break;

		case CT_BROADCAST:
			{
				int p1 = va_arg(ap, int);	// body
				adjust(_T("%s %02d:%02d:%02d %s\r\n"), _T("GOD"), t.wHour, t.wMinute, t.wSecond, buf+p1);
			}
			break;

		case CT_PTCHAT:
			{
				int p1 = va_arg(ap, int);	// body
				adjust(_T("%s %02d:%02d:%02d %s\r\n"), _T("PRT"), t.wHour, t.wMinute, t.wSecond, buf+p1);
			}
			break;

		case CT_GUILDCHAT:
			{
				int p1 = va_arg(ap, int);	// body
				adjust(_T("%s %02d:%02d:%02d %s\r\n"), _T("GLD"), t.wHour, t.wMinute, t.wSecond, buf+p1);
			}
			break;

		case CT_TALKIE:
			{
				int p1 = va_arg(ap, int);	// body
				adjust(_T("%s %02d:%02d:%02d %s\r\n"), _T("TLK"), t.wHour, t.wMinute, t.wSecond, buf+p1);
			}
			break;

		case CT_LOCALBROADCAST:
			{
				int p1 = va_arg(ap, int);	// body
				adjust(_T("%s %02d:%02d:%02d %s\r\n"), _T("LBC"), t.wHour, t.wMinute, t.wSecond, buf+p1);
			}
			break;
	}


	va_end(ap);
}
示例#16
0
void AP_USB_SpeedTest(void)
{
    int i;
	char *rbuf = NULL, *wbuf = NULL;
	int read_size, ret, total_read_size=0;
	double final_total_sec=0;
	float USB_speed=0;
    struct timespec diff_time, total_time;

	/* buffer */
	rbuf = malloc(RBUFSIZE);
	wbuf = malloc(WBUFSIZE);

    printf("============Buffer Size:%d MB===========\n", RBUFSIZE/(1024*1024));

    if( rbuf == NULL )
    {
	    fprintf( stderr, "ERROR!! allocate memory(%dM) failed! (#%d: %s)\n",1048576/1048576, errno, strerror(errno) );
		exit(1);
	}

    memset(&total_time, 0, sizeof(struct timespec));

    printf("===============Start Read Test=================\n");
	for(i = (loop) ? loop : ~0; i > 0; --i)
	{

	    /* read file through buf */
        _timerswitch(SWITCH_ON);
		while( !feof(fp_src) )
		{
			ret = fread( rbuf, 1, RBUFSIZE, fp_src );

			if( ret < RBUFSIZE )
            {
				if( !feof(fp_src) )
                {
					fprintf( stderr, "ERROR!! read SRC failed! (#%d: %s)\n", errno, strerror(errno) );
					exit(1);
				}
			}
			read_size = ret;
			total_read_size += read_size;

            //printf("read_size=%d, total_read_size=%d\n", read_size, total_read_size);
		}
        _timerswitch(SWITCH_OFF);

        diff_time = _gettime();
		total_time.tv_sec = total_time.tv_sec + diff_time.tv_sec;
		total_time.tv_nsec = total_time.tv_nsec + diff_time.tv_nsec;

        printf("finished %d/%d : %f sec......OK \n",loop, loop-i+1, CAL_TIME((double)diff_time.tv_sec,(double)diff_time.tv_nsec));

        if((loop-i+1)==loop)
        {
            final_total_sec = CAL_TIME((double)total_time.tv_sec,(double)total_time.tv_nsec)/loop;
            printf("AVG R TOTAL TIME:%f sec\n",final_total_sec);

        	USB_speed = ((stat_src.st_size) /final_total_sec)/(1024*1024);
        	printf("SPEED:%f MBps\n",USB_speed);
        }

        fflush(fp_src); //clear stdin register
        fseek(fp_src,0,SEEK_SET);

    } //loopo end


	/* write file through buf */
    srand((int) time(0));
    for (i = 0; i < WBUFSIZE; i++)
    {
        wbuf[i] = rand()%256;
    }

    memset(&total_time, 0, sizeof(struct timespec));

    printf("\n===============Start Write Test %dMB=================\n",WBUFSIZE/(1024*1024));
	for(i = (loop) ? loop : ~0; i > 0; --i)
    {

        _timerswitch(SWITCH_ON);
        ret = fwrite( wbuf, 1, WBUFSIZE, fp_des);

        if( ret < WBUFSIZE)
    	{
    		printf("ERROR!! write %s failed! (#%d: %s)\n", gDes_path, errno, strerror(errno) );
    		exit(1);
    	}

        fflush(fp_des); //clear stdin register
		fsync(fileno(fp_des));  //sync buff to disk

        _timerswitch(SWITCH_OFF);

        diff_time = _gettime();
		total_time.tv_sec = total_time.tv_sec + diff_time.tv_sec;
		total_time.tv_nsec = total_time.tv_nsec + diff_time.tv_nsec;

        printf("finished %d/%d : %f sec......OK \n",loop, loop-i+1, CAL_TIME((double)diff_time.tv_sec,(double)diff_time.tv_nsec));

        if((loop-i+1)==loop)
        {
        	final_total_sec = CAL_TIME((double)total_time.tv_sec,(double)total_time.tv_nsec)/loop;
            printf("AVG W TOTAL TIME:%f sec\n",final_total_sec);

        	USB_speed = (WBUFSIZE/final_total_sec)/(1024*1024);//MB per second
        	printf("SPEED:%f MBps\n",USB_speed);//TCC110915
        }

		fseek(fp_des,0,SEEK_SET);
    }

    fclose(fp_src);
    fclose(fp_des);
    free(rbuf);
    free(wbuf);

	sleep(1);
    printf("USB Speed finished...\n\n");
}
示例#17
0
void 
skynet_timer_init(void) {
	TI = timer_create_timer();
	TI->current = _gettime();
}
示例#18
0
static void
timer_init(struct timer *t, struct cell * sys, struct global_queue *mq) {
	t->current = _gettime();
	t->sys = sys;
	t->mq = mq;
}