Exemplo n.º 1
0
GFatalErrorImpl::GFatalErrorImpl(char const * ckpMessage)
{
	// Log fatal error message.
	GSystem::Trace(ckpMessage);

	// Block forever.
	GSemaphore Sem(0);
	Sem.Wait();
}
void
MessageLooper::_GetLooperName(char* name, size_t length)
{
	sem_id semaphore = Sem();
	sem_info info;
	if (get_sem_info(semaphore, &info) == B_OK)
		strlcpy(name, info.name, length);
	else
		strlcpy(name, "unnamed looper", length);
}
Exemplo n.º 3
0
int main(int argc, char** argv)
{
    //获取程序启动参数
    int optch = 0;
    static char optstring[] = "o:l:s:vi:t:p:k:";
    extern char *optarg;

    char smode[128] = { 0 };
    int mode = -1;
    while ((optch = getopt(argc, argv, optstring)) != -1)
    {
        switch (optch)
        {
        case 'o'://启动模式
            strcpy(smode, optarg);
            if (strcmp(optarg, "rqueue") == 0)
                mode = 0;
            if (strcmp(optarg, "wqueue") == 0)
                mode = 1;
            if (strcmp(optarg, "queue") == 0)
                mode = 10;
            if (strcmp(optarg, "rsem") == 0)
                mode = 2;
            if (strcmp(optarg, "wsem") == 0)
                mode = 3;
            if (strcmp(optarg, "sem") == 0)
                mode = 11;
            if (strcmp(optarg, "rfifo") == 0)
                mode = 4;
            if (strcmp(optarg, "wfifo") == 0)
                mode = 5;
            if (strcmp(optarg, "fifo") == 0)
                mode = 12;
            if (strcmp(optarg, "rsock") == 0)
                mode = 6;
            if (strcmp(optarg, "wsock") == 0)
                mode = 7;
            if (strcmp(optarg, "sock") == 0)
                mode = 13;
            if (strcmp(optarg, "rusock") == 0)
                mode = 8;
            if (strcmp(optarg, "wusock") == 0)
                mode = 9;
            if (strcmp(optarg, "usock") == 0)
                mode = 14;
            if (strcmp(optarg, "rpoll") == 0)
                mode = 15;
            if (strcmp(optarg, "rpoll2") == 0)
                mode = 16;
            if (strcmp(optarg, "rpollset") == 0)
                mode = 17;
#ifdef OCE_CACHE
            if (strcmp(optarg, "rcache") == 0)
                mode = 18;
            if (strcmp(optarg, "wcache") == 0)
                mode = 19;
            if (strcmp(optarg, "cache") == 0)
                mode = 20;
#endif
            break;
        case 'l':
            g_len = atoi(optarg);
            break;
        case 's':
            g_usleep = atoi(optarg);
            break;
        case 'v':
            g_verify = 1;
            break;
        case 'i':
            strcpy(g_ip, optarg);
            break;
        case 't':
            loop_times = atol(optarg);
            break;
        case 'p':
            g_port = atol(optarg);
            break;
        case 'k':
            strcpy(g_sKeyFile, optarg);
            break;
        default:
            exit(-1);
        }
    }

    daemon();

    if(g_verify == 1)
    {
        memcpy(wbuff+sizeof(struct timeval), &g_data, sizeof(g_data));
        g_len = sizeof(struct timeval) + sizeof(g_data);
    }
    else
    {
        for (int i = 0; i < sizeof(wbuff); i++)
        {
            wbuff[i] = 'b';
        }
        wbuff[0] = 'a';
        wbuff[g_len-1] = 'a';
        wbuff[sizeof(wbuff) - 1] = '\0';
    }

    g_nSig = _RegisterSignal();
    if(g_nSig == NULL)
    {
        printf("Could not set up signal handling.  Aborting.\n");
        return -1;
    }

    if (mode == 0)
    {
        Rqueue();
    }
    if (mode == 1)
    {
        Wqueue();
    }
    if (mode == 2)
    {
        Rsem();
    }
    if (mode == 3)
    {
        Wsem();
    }
    if (mode == 4)
    {
        Rfifo();
    }
    if (mode == 5)
    {
        Wfifo();
    }
    if (mode == 6)
    {
        Rsock();
    }
    if (mode == 7)
    {
        Wsock();
    }
    if (mode == 8)
    {
        Rusock();
    }
    if (mode == 9)
    {
        Wusock();
    }
    if (mode == 10)
    {
        Queue();
    }
    if (mode == 11)
    {
        Sem();
    }
    if (mode == 12)
    {
        Fifo();
    }
    if (mode == 13)
    {
        Sock();
    }
    if (mode == 14)
    {
        Usock();
    }
    if (mode == 15)
    {
        Rpoll();
    }
    if (mode == 16)
    {
        Rpoll2();
    }
    if (mode == 17)
    {
        Rpollset();
    }
#ifdef OCE_CACHE
    if (mode == 18)
    {
        Rcache();
    }
    if (mode == 19)
    {
        Wcache();
    }
    if (mode == 20)
    {
        Cache_();
    }
#endif

    if(total_time0 != 0)
    {
        double avg1 = (double) total_time0 / (double) g_count0;
        double avg2 = (double) g_count0 / (double)((double) total_time0 / 1000000);
        printf("%s total0 g_count0:%lld, avgage %lf us, max %lf num/s\n", smode, g_count0, avg1,avg2);
    }
    if(recv_delay0 != 0)
    {
        double avg1 = (double) recv_delay0 / (double) recv_delay_count0;
        printf("%s recv delay avgage %lf us , max delay %llu\n", smode, avg1, g_delay_max);
    }
    if(total_time1 != 0)
    {
        double avg1 = (double) total_time1 / (double) g_count1;
        double avg2 = (double) g_count1 / (double)((double) total_time1 / 1000000);
        printf("%s total1 g_count1:%lld, avgage %lf us, max %lf num/s\n", smode, g_count1, avg1,avg2);
    }
    if(total_time2 != 0)
    {
        double avg1 = (double) total_time2 / (double) g_count2;
        double avg2 = (double) g_count2 / (double)((double) total_time2 / 1000000);
        printf("%s total2 g_count2:%lld, avgage %lf us, max %lf num/s\n", smode, g_count2, avg1,avg2);
    }

    printf("exit.\n");
    return 0;
}
Exemplo n.º 4
0
Sem::Sem ():m_i16Value(0),m_i16WaitCount(0),m_valueMutex(),m_valueCond()
{
  Sem(0);
}