Exemplo n.º 1
0
double TTimer::GetTimer()
{

    double t=0;
    pthread_mutex_lock(&mutex);

    if(!init){

        init=true;
        ClockGetTime(CLOCK_MONOTONIC,&t0);

    }else{

        timespec t1;
        ClockGetTime(CLOCK_MONOTONIC,&t1);
        t=util::dift(t1,t0);

    }


    pthread_mutex_unlock(&mutex);

    return t;

}
Exemplo n.º 2
0
/*
 * @brief Print all the pending activities in the system
 */
void
PwrEventActivityPrint(void)
{
    struct timespec now;
    ClockGetTime(&now);

    _activity_print(&now, &now);
}
Exemplo n.º 3
0
/** 
* @brief Prints the activities active in range from
*        time 'start' to now.
* 
* @param  from 
*/
void
PwrEventActivityPrintFrom(struct timespec *start)
{
    struct timespec now;
    ClockGetTime(&now);

    _activity_print(start, &now);
}
Exemplo n.º 4
0
/**
 * Pretty print the current time.
 */
void
ClockPrint(void)
{
    struct timespec time;
    ClockGetTime(&time);

    ClockPrintTime(&time);
}
Exemplo n.º 5
0
/**
 * Render the tiles for a frame.
 * @param xOffset the leftmost X coordinate
 * @param yOffset the topmost Y coordinate
 * @todo This can be simplified and improved significantly by just rendering a
 *       pre-created vertex array of the entire tilemap on each frame.  It will
 *       reduce overhead and actually be faster.
 */
void GLTileEngine::renderTiles()
{
	static uint64_t lasttime = 0;
	int width = this->width, height = this->height;
	int xOffset = this->xOffset, yOffset = this->yOffset;

	xOffset &= 0xfffffff0;
	yOffset &= 0xfffffff0;

	glBindTexture(GL_TEXTURE_2D, this->texture);
	GLenum filter = this->scale == 1.0f ? GL_NEAREST : GL_LINEAR;
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);

	// do the actual drawing
	glBegin(GL_QUADS);
	for(int y=yOffset; y <= this->yMax; y+=16)
	{
		for(int x=xOffset; x <= this->xMax; x+=16)
		{
			int tileX = x>>4;
			int tileY = y>>4;

			if(tileX < 0 || tileX >= WORLD_W || tileY < 0 || tileY >= WORLD_H)
				continue;
			
			int tile = *(unsigned short*)(this->tiles + ROW_BYTES*tileY + COL_BYTES*tileX) & LOMASK;
			renderTile(x, y, tile);
		}
	}
	glEnd();

	if(lasttime)
		printf("FPS: %f\r", 1000000.0/(ClockGetTime()-lasttime));
	lasttime = ClockGetTime();
}
Exemplo n.º 6
0
/* void ClockGetTime(struct timespec *time) */
static void
test_ClockGetTime(void)
{
    struct timespec time;

    ClockGetTime(&time);

    /* Check if the values are sane. */

    g_assert_cmpint(time.tv_sec, >, 0); /* seconds - TYPE_T (long int) */
    g_assert(time.tv_nsec > 0); /* nanoseconds - long int */

    /* The value should always be less than one second. */
    int nsecToSec = time.tv_sec / NSEC_PER_SEC;
    g_assert_cmpint(nsecToSec, <, 1);
}
Exemplo n.º 7
0
Arquivo: tipke.c Projeto: msantl/SZRSV
void *check_list(void *arg) {

    while (RUNNING) {
        pthread_mutex_lock(&m_datagram_list);

        struct timespec now;
        ClockGetTime(&now);

        ListRemoveByTimeout(&datagram_list, now);

        pthread_mutex_unlock(&m_datagram_list);
        usleep(LIST_FREQUENCY);
    }

    return NULL;
}
Exemplo n.º 8
0
ULONG32 GetTickCount()
{
    TickSpec ticks;
    TimeSpec time;
    if (_clock == NULL)
    {
        _clock = ClockCreate(SYSTEM_CLOCK);
        if (_clock == NULL)
        {
            return 0;
        }
        g_RegisterGlobalPtr(&_clock);
    }
    ClockGetTime(_clock, &ticks);
    ClockConvertToTime(_clock, &ticks, &time);
    return (time.tv_sec * 1000) + (time.tv_nsec / 1000000);
}
Exemplo n.º 9
0
NTSTATUS
NTAPI
ClockPropertyTime(
    IN PIRP Irp,
    IN PKSIDENTIFIER Request,
    IN OUT PVOID Data)
{
    PLONGLONG Time = (PLONGLONG)Data;
    PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation(Irp);

    DPRINT("ClockPropertyTime\n");

    *Time = ClockGetTime(IoStack->FileObject);

    Irp->IoStatus.Information = sizeof(LONGLONG);
    return STATUS_SUCCESS;
}
Exemplo n.º 10
0
Arquivo: tipke.c Projeto: msantl/SZRSV
void send_ack(int ack, int sockfd, struct sockaddr *server, socklen_t server_l) {
    struct message_t resp;
    resp.id = GetNewMessageID();
    resp.type = POTVRDA;

    sprintf(resp.data, "%d", ack);

    ClockGetTime(&resp.timeout);
    ClockAddTimeout(&resp.timeout, TIMEOUT);

#ifdef DEBUG
    printf("Sending ACK for message %d\n", ack);
#endif
    sendto(sockfd, &resp, sizeof(resp), 0, server, server_l);

    return;
}
Exemplo n.º 11
0
Arquivo: tipke.c Projeto: msantl/SZRSV
void *tipke(void *arg) {
    char cmd[MAX_BUFF];
    int floor;

    struct message_t msg;

    /* do tipke things */
    while (RUNNING) {
        memset(cmd, 0, sizeof(cmd));

        /* format: floor direction*/
        scanf("%d%s", &floor, cmd);

        if (*cmd == 'a' && floor != 9) {
            msg.type = TIPKE_KEY_PRESSED_UP;
        } else if (*cmd == 'z' && floor != 0) {
            msg.type = TIPKE_KEY_PRESSED_DOWN;
        } else {
            warnx("Unkown command (use 'a' for UP and 'z' for down)!");
            continue;
        }

        msg.id = GetNewMessageID();

        memset(msg.data, 0, sizeof(msg.data));
        sprintf(msg.data, "%d", floor);

        ClockGetTime(&msg.timeout);
        ClockAddTimeout(&msg.timeout, TIMEOUT);

        pthread_mutex_lock(&m_datagram_list);

        sendto(upr_socket, &msg, sizeof(msg), 0, &upr_server, upr_server_l);
        ListInsert(&datagram_list, msg);

        pthread_mutex_unlock(&m_datagram_list);
    }

    return NULL;
}
Exemplo n.º 12
0
static Activity *
_activity_new(const char *activity_id, int duration_ms)
{
    if (duration_ms >= ACTIVITY_MAX_DURATION_MS)
    {
        duration_ms = ACTIVITY_MAX_DURATION_MS;
    }

    Activity *activity = g_new0(Activity, 1);

    activity->activity_id = g_strdup(activity_id);
    activity->duration_ms = duration_ms;

    // end += duration
    ClockGetTime(&activity->start_time);

    activity->end_time.tv_sec = activity->start_time.tv_sec;
    activity->end_time.tv_nsec = activity->start_time.tv_nsec;

    ClockAccumMs(&activity->end_time, activity->duration_ms);

    return activity;
}
Exemplo n.º 13
0
Arquivo: tipke.c Projeto: msantl/SZRSV
void *udp_listener(void *arg) {
    char tipke_hostname[MAX_BUFF], tipke_port[MAX_BUFF];
    int server_socket;
    int ack, floor;

    struct message_t msg;
    struct sockaddr client;
    socklen_t client_l = sizeof(client);

    ParseHostnameAndPort("TIPKE", (char **) &tipke_hostname, (char **) &tipke_port);
#ifdef DEBUG
    printf("Listening as TIPKE on %s:%s\n", tipke_hostname, tipke_port);
#endif
    server_socket = InitUDPServer(tipke_port);
#ifdef DEBUG
    printf("Server started successfully\n");
#endif

    while (RUNNING) {
        /* waiting for next datagram */
        recvfrom(server_socket, &msg, sizeof(msg), 0, &client, &client_l);

        switch(msg.type) {
            case POTVRDA:
                /* received ack */
                pthread_mutex_lock(&m_datagram_list);

                sscanf(msg.data, "%d", &ack);

#ifdef DEBUG
                printf("Received ACK for message %d\n", ack);
#endif
                ListRemoveById(&datagram_list, ack);

                pthread_mutex_unlock(&m_datagram_list);

                break;
            case TIPKE_PALI_LAMPICU_UP:
                send_ack(msg.id, upr_socket, &upr_server, upr_server_l);

                pthread_mutex_lock(&m_status);

                sscanf(msg.data, "%d", &floor);
                status[floor][D_UP] = 1;

                pthread_mutex_unlock(&m_status);

                PrintStatus();

                break;
            case TIPKE_PALI_LAMPICU_DOWN:
                send_ack(msg.id, upr_socket, &upr_server, upr_server_l);

                pthread_mutex_lock(&m_status);

                sscanf(msg.data, "%d", &floor);
                status[floor][D_DOWN] = 1;

                pthread_mutex_unlock(&m_status);

                PrintStatus();

                break;
            case TIPKE_GASI_LAMPICU_UP:
                send_ack(msg.id, upr_socket, &upr_server, upr_server_l);

                pthread_mutex_lock(&m_status);

                sscanf(msg.data, "%d", &floor);
                status[floor][D_UP] = 0;

                pthread_mutex_unlock(&m_status);

                PrintStatus();

                break;
            case TIPKE_GASI_LAMPICU_DOWN:
                send_ack(msg.id, upr_socket, &upr_server, upr_server_l);

                pthread_mutex_lock(&m_status);

                sscanf(msg.data, "%d", &floor);
                status[floor][D_DOWN] = 0;

                pthread_mutex_unlock(&m_status);

                PrintStatus();

                break;
            case TIPKE_STATUS_REQUEST:
                send_ack(msg.id, upr_socket, &upr_server, upr_server_l);

                msg.id = GetNewMessageID();
                msg.type = TIPKE_STATUS_REPORT;

                ClockGetTime(&msg.timeout);
                ClockAddTimeout(&msg.timeout, TIMEOUT);

                pthread_mutex_lock(&m_datagram_list);

                sendto(upr_socket, &msg, sizeof(msg), 0, &upr_server, upr_server_l);
                ListInsert(&datagram_list, msg);

                pthread_mutex_unlock(&m_datagram_list);

                break;
            default:
                warnx("Unknown message!");
                break;
        }
    }

    CloseUDPServer(server_socket);
#ifdef DEBUG
    printf("Server closed successfully\n");
#endif
    return NULL;
}