Esempio n. 1
0
void
tcp_echo_srv_rcv_task(intptr_t exinf)
{
    ID	tskid;

    get_tid(&tskid);
    syslog(LOG_NOTICE, "[TCP ECHO SRV RCV:%d,%d] started.", tskid, (ID)exinf);
    while (true) {
        while (tcp_echo_srv_rcv((ID)exinf, TCP_ECHO_SRV_REPID) == E_OK)
            ;
    }
}
Esempio n. 2
0
int sockets_add(int sock, struct sockaddr_in *sa, int sid, int type,
		socket_action a, socket_action c, socket_action t)
{
	int i;
	char ra[50];
	sockets *ss;

	i = add_new_lock((void **) s, MAX_SOCKS, sizeof(sockets), &s_mutex);
	if (i == -1)
		LOG_AND_RETURN(-1, "sockets_add failed for socks %d", sock);

	ss = s[i];
	ss->enabled = 1;
	ss->sock = sock;
	ss->tid = get_tid();
	memset(&ss->sa, 0, sizeof(ss->sa));
	if (sa)
		memcpy(&ss->sa, sa, sizeof(ss->sa));
	ss->action = ss->close = ss->timeout = NULL;
	if (a)
		ss->action = a;
	if (c)
		ss->close = c;
	if (t)
		ss->timeout = t;
	ss->sid = sid;
	ss->type = type & ~TYPE_CONNECT;
	ss->rtime = getTick();
	ss->wtime = 0;
	if (max_sock <= i)
		max_sock = i + 1;
	ss->buf = NULL;
	ss->lbuf = 0;
	ss->timeout_ms = 0;
	ss->id = i;
	ss->read = (read_action) sockets_read;
	ss->lock = NULL;
	if (ss->type == TYPE_UDP || ss->type == TYPE_RTCP)
		ss->read = (read_action) sockets_recv;
	else if (ss->type == TYPE_SERVER)
		ss->read = (read_action) sockets_accept;
	ss->events = POLLIN | POLLPRI;
	if (type & TYPE_CONNECT)
		ss->events |= POLLOUT;

	LOG(
			"sockets_add: handle %d (type %d) returning socket index %d [%s:%d] read: %p",
			ss->sock, ss->type, i, get_socket_rhost(i, ra, sizeof(ra)),
			ntohs(ss->sa.sin_port), ss->read);
	mutex_unlock(&ss->mutex);
	return i;
}
Esempio n. 3
0
static void user2_f(void) {
	unsigned int tid = get_tid();
	uart_print(DEV_UART0, "f2 tid ");
	uart_dprint(DEV_UART0, tid);
	uart_cprint(DEV_UART0, '\n');
	unsigned int a = 0;
	while (1) {
		uart_xprint(DEV_UART0, a);
		uart_cprint(DEV_UART0, '\n');
		a++;
		for (int i = 0; i < 200000000; i++);
	}
}
Esempio n. 4
0
// clone a b-tree
void oc_bpt_test_utl_btree_clone(
    struct Oc_wu *wu_p,
    struct Oc_bpt_test_state* src_p,
    struct Oc_bpt_test_state* trg_p
    )
{
    if (param->verbose) printf("// clone new-TID=%Lu\n", get_tid(trg_p));
    
    oc_bpt_clone_b(wu_p, &src_p->bpt_s, &trg_p->bpt_s);
    oc_bpt_alt_clone_b(wu_p, &src_p->alt_s, &trg_p->alt_s);

    if (param->verbose) print_fun();
}
Esempio n. 5
0
void oc_bpt_test_utl_btree_lookup(
    Oc_wu* wu_p,
    Oc_bpt_test_state *s_p,
    uint32 key,
    bool *check_eq_pio)
{
    if (param->verbose) {
        printf("// lookup %lu  TID=%Lu\n", key, get_tid(s_p));  
        fflush(stdout);
    }

    oc_bpt_test_utl_btree_lookup_internal(
        wu_p, s_p, key, check_eq_pio);
}
Esempio n. 6
0
static int __ui_get_tid(struct pt_regs *regs)
{
	ID tskid;
	ER err;

	err = get_tid(&tskid);

	if (err == E_OK &&
	    __xn_safe_copy_to_user((void __user *)__xn_reg_arg1(regs), &tskid,
				   sizeof(tskid)))
		return -EFAULT;

	return err;
}
Esempio n. 7
0
/* サンプルタスク */
void appli(VP_INT exinf)
{
    char count[9];
    char task_id[2];
    MESSAGE* msg;
    ID this;

    memset(count,'0',sizeof(count));
    count[8] = task_id[1] = '\0';

    while (1) {
        if (++count[7] > '9') {
            count[7] = '0';
            if (++count[6] > '9') {
                count[6] = '0';
                if (++count[5] > '9') {
                    count[5] = '0';
                    if (++count[4] > '9') {
                        count[4] = '0';
                        if (++count[3] > '9') {
                            count[3] = '0';
                            if (++count[2] > '9') {
                                count[2] = '0';
                                if (++count[1] > '9') {
                                    count[1] = '0';
                                    if (++count[0] > '9') {
                                        count[0] = '0';
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        /* メモリプールから取得 */
        get_mpf(MPID_TEST,(VP)&msg);
        strcpy(msg->buf,"This is test messages from Task");
        get_tid(&this);
        task_id[0] = this + '0';
        strcat(msg->buf,task_id);
        strcat(msg->buf,". count ");
        strcat(msg->buf,count);
        strcat(msg->buf,"\r\n");
        msg->len = strlen(msg->buf);
        msg->sender = this;

        snd_mbx(MID_TEST,(T_MSG *)msg);
    }
}
Esempio n. 8
0
// thread canceled by another thread
int th_kill(th_t *thread)
{
	int tid = get_tid(thread);
	if (tid == -1) return -1;

	entry_section();

	th_data *td = thread->u;
	td->status = 1;
	put_dead(tid);

	exit_section();
	return 0;
}
Esempio n. 9
0
/**
 * @brief Create thread
 *
 * @param thread - thread of the information contained threads structure
 * @param thread_stk - Created a pointer to the thread stack space
 * @param func - Generated a thread of the function
 * @param name - Thread name
 * @param prio - The priority of threads
 * @param pdata - Pass parameters to the function of a thread running
 * @retval RET_NO_ERR
 * @retval RET_ERR
 */
tid_t thread_create(thread_struct *thread,
		    stk_t *thread_stk,
		    THREAD_FUNC func,
		    char *name,
		    u8_t prio,
		    void *pdata)
{
	cpu_sr_t cpu_sr;
	stk_t *pstk;
	thread_struct *pthread;
	tid_t tid;

	if (thread == NULL || thread_stk == NULL || func == NULL ||
	    name == NULL || (prio >= MAX_PRIO))
		return RET_ERR;

	pstk = thread_stk;
	pthread = thread;

	/* no failback */
	if ((tid = get_tid()) == RET_ERR) {
		return RET_ERR;
	}

	/* constrct thread_struct */
	pthread->tid = tid;
	pthread->stack_ptr = init_thread_stack(func, pdata, pstk);
	pthread->name = name;
	pthread->prio = prio;
	pthread->time_quantum = TIME_QUANTUM;
	pthread->delayed_time = 0;
	pthread->state = READY;

	cpu_sr = save_cpu_sr();
	thread_table[tid] = pthread;
	prio_exist_flag[prio] = true;
	total_thread_cnt++;
	insert_back_list(&ready_list[prio], &pthread->node);
	restore_cpu_sr(cpu_sr);

	/* if priority higher than existing thread, invoke the scheduler. */
	if (is_start_os == true && current_thread->prio > prio) {
		schedule(SCHED_THREAD_REQUEST);
	}

	printf("thread_create:%d\n", prio);

	return tid;
}
Esempio n. 10
0
void
tcp_echo_srv_task(intptr_t exinf)
{
	ID	tskid;
	ER	error;

	syscall(get_tid(&tskid));
	syslog(LOG_NOTICE, "[TCP ECHO SRV:%d,%d] started.", tskid, (ID)exinf);
	while (true) {
		while ((error = tcp_echo_srv((ID)exinf, TCP_ECHO_SRV_REPID)) == E_OK)
			;
		syslog(LOG_NOTICE, "[TES:%02d] goto sleep 60[s], error: %s", (ID)exinf, itron_strerror(error));
		tslp_tsk(60 * 1000);
		}
	}
Esempio n. 11
0
void get_mul(int x, int y)
{
	++num ;
	sum += x*y ;
	printf("[%s][get_mul]:num=%d, sum=%d\n",myname, num, sum) ;
	if(num == 5)
	{
		int end_tid = get_tid("end") ;
		pvm_initsend(PvmDataDefault) ;
		pvm_pkint(&sum, 1, 1) ;
		printf("[%s][get_mul]:endtid=%d, receiving data...\n",myname,end_tid) ;
                pvm_send(end_tid, 1) ;
		//pvm_exit() ;
        }
return ;
}
Esempio n. 12
0
void
ppp_output_task(intptr_t exinf)
{
	T_NET_BUF	*output;
	ID		tskid;

	get_tid(&tskid);
	syslog(LOG_NOTICE, "[PPP OUTPUT:%d] started.", tskid);

	while (true) {
		while (rcv_dtq(DTQ_PPP_OUTPUT, (intptr_t*)&output) == E_OK) {
			NET_COUNT_PPP(net_count_ppp.out_octets,  output->len);
			NET_COUNT_PPP(net_count_ppp.out_packets, 1);
			syscall(HDLC_write(output));
			syscall(rel_net_buf(output));
			}
		}
	}
Esempio n. 13
0
void
if_loop_output_task (intptr_t exinf)
{
	T_NET_BUF	*output;
	ER		error;
	ID		tskid;

	get_tid(&tskid);
	syslog(LOG_NOTICE, "[LOOP OUTPUT:%d] started.", tskid);
	while (true) {
		if (rcv_dtq(DTQ_LOOP_OUTPUT, (intptr_t*)&output) == E_OK) {
			NET_COUNT_LOOP(net_count_loop.in_octets,  output->len);
			NET_COUNT_LOOP(net_count_loop.in_packets, 1);
			if ((error = snd_dtq(DTQ_LOOP_INPUT, output)) != E_OK)
				syslog(LOG_NOTICE, "[LOOP OUTPUT] drop error: %s", itron_strerror(error));
			}
		}
	}
Esempio n. 14
0
void pass_closed_expression()
{
	int d=0;
	do{
		if(get_tval()=="(") {
			++d;
			fprintf(OUTF,"(");
			try_lex();
		} else if(get_tval()==")") {
			--d;
			fprintf(OUTF,")");
			try_lex();
		} else {
			step();
			while(is_space(get_tid())) step();
		}
	} while(d || (get_tval()!="," && get_tval()!=")"));
}
Esempio n. 15
0
void task2( unsigned int arg )
{
    ER ercd;
    int i;
    CYG_TEST_INFO( "Task 2 running" );
    ercd = get_tid( &i );
    CYG_TEST_CHECK( E_OK == ercd, "get_tid bad ercd" );
    CYG_TEST_CHECK( 2 == i, "tid not 2" );
    if ( 22222 != arg )
        CYG_TEST_FAIL( "Task 2 arg not 22222" );

    for ( i = 0 ; i < 100; i++ ) {
        ercd = rel_wai( 1 );
        CYG_TEST_CHECK( E_OK == ercd, "rel_wai bad ercd" );
    }        
    // we expect task2 to be killed here
    CYG_TEST_FAIL( "Task 2 ran to completion!" );
}
Esempio n. 16
0
void pass_case_or_scope()
{
	int d=0;
	do{
		if(get_tval()=="{") {
			++d;
			fprintf(OUTF,"{");
			try_lex();
		} else if(get_tval()=="}") {
			--d;
			fprintf(OUTF,"}");
			try_lex();
		} else {
			step();
			while(is_space(get_tid())) step();
		}
	} while(d || (get_tval()!="case" && get_tval()!="}"));

}
Esempio n. 17
0
// thread joining, wait for thread termination
int th_wait(th_t *thread, void *status)
{
	if (thread && thread->state == TERMINATED) {
		if (status) *((int * )status) = wstatus[thread->tid];
		return 0;
	}

	int tid = get_tid(thread);
	if (tid == -1) return -1;
	entry_section();

	th_data *td = threads[curr]->u;
	td->waitfor = tid;
	threads[curr]->state = WAITING;
	th_yield();

	if (status) *((int * )status) = wstatus[tid];

	return 0;
}
Esempio n. 18
0
//TODO: this looks hideous, clean it up
void printstr(const char* str){
	unsigned count=0;
	int i;
	unsigned tid = get_tid();
	unsigned idx = *(unsigned*)(2*tid*TERM_ALIGN + TERM_BASE);
	char *data = (char*)(TERM_BASE + (2*tid*TERM_ALIGN) + 128);
	while(*str){
		data[(idx+count++)%TERM_BUF] = *str++;
	}

	for(i=0; i < count; i+=64){
		clean_dcache(&data[(idx+i)%TERM_BUF]);
	}

	if( ((unsigned)&data[(idx+i-64)%TERM_BUF]) >> 6 != ((unsigned)&data[(idx+count)%TERM_BUF]) >> 6)
		clean_dcache(&data[(idx+count)%TERM_BUF]);
	idx+=count;
	*(unsigned*)(2*tid*TERM_ALIGN + TERM_BASE) = idx%TERM_BUF;
	clean_dcache((void*)(2*tid*TERM_ALIGN + TERM_BASE));
}
Esempio n. 19
0
static ER
get_tcp_rep (ID *repid)
{
	ID		tskid;
	T_TCP_CREP	crep;

	get_tid(&tskid);

	crep.repatr = UINT_C(0);
	crep.myaddr.portno = UINT_C(7);

#if defined(SUPPORT_INET4)
	crep.myaddr.ipaddr = IPV4_ADDRANY;
#endif

#if defined(SUPPORT_INET6)
	memcpy(&crep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
#endif

	return alloc_tcp_rep(repid, tskid, &crep);
	}
Esempio n. 20
0
static ER
get_tcp_cep (ID *cepid)
{
	ID		tskid;
	T_TCP_CCEP	ccep;

	get_tid(&tskid);

	ccep.cepatr = UINT_C(0);
	ccep.sbuf = NADR;
	ccep.sbufsz = 0;
	ccep.rbufsz = TCP_DISCARD_SRV_RWBUF_SIZE;
	ccep.callback = NULL;

#ifdef TCP_CFG_RWBUF_CSAVE
	ccep.rbuf = NADR;
#else
	ccep.rbuf = tcp_discard_srv_rwbuf;
#endif

	return alloc_tcp_cep(cepid, tskid, &ccep);
	}
Esempio n. 21
0
void do_read_match()
{
	CMatch m;

	if(get_tval()!="(") error("Expected ( after match.");
	try_lex();
	while(get_tval()!=")") {
		char buf[16];
		sprintf(buf,"_fv%d",freshgen);
		m.inputs.push_back(buf);
		fprintf(OUTF,"auto _fv%d=",freshgen);
		++freshgen;
		pass_closed_expression();
		fprintf(OUTF,";\n");
		if(get_tval()==",") try_lex();
	}
	try_lex();
	
	if(get_tval()!="{") error("Missing match body.");
	try_lex();

	while(get_tval()!="}") {
		if(get_tval()!="case") error("Expecting case.");
		try_lex();
		
		std::vector<std::pair<int,std::string> > pat;
		while(get_tval()!=":") {
			pat.push_back(std::pair<int,std::string>(get_tid(),get_tval()));
			try_lex();
		}
		try_lex();
		
		m.emit_case(pat,OUTF);
		if(get_tval()!="}" && get_tval()!="case") pass_case_or_scope();
		m.emit_caseend(OUTF);
	}
	try_lex();
}
Esempio n. 22
0
void do_read_ctor()
{
	std::string nm=get_tval();
	fprintf(OUTF,"_algebraize(ctor_%s",nm.c_str());
	try_lex();
	if(get_tval()=="<") {
		int d=1;
		fprintf(OUTF,"<");
		do{
			try_lex();
			if(get_tval()=="<") ++d;
			else if(get_tval()==">") --d;
			fprintf(OUTF,get_tval().c_str());
		}while(d);
		try_lex();
	}
	if(!constructors[nm]->params.size()) fprintf(OUTF,"())");
	else {
		if(get_tval()=="(") {
			int d=0;
			do{
				if(get_tval()=="(") {
					++d;
					fprintf(OUTF,"(");
					try_lex();
				} else if(get_tval()==")") {
					--d;
					fprintf(OUTF,")");
					try_lex();
				} else {
					step();
					while(is_space(get_tid())) step();
				}
			} while(d);
		}
		fprintf(OUTF,")");
	}
}
Esempio n. 23
0
File: main.c Progetto: monaka/B-Free
/*
 * 初期化
 *
 * o 要求受けつけ用のメッセージバッファ ID をポートマネージャに登録
 */
W
init_keyboard (void)
{
  int		i;
  ER		error;

  /*
   * 要求受けつけ用のポートを初期化する。
   */
  recvport = get_port (sizeof (DDEV_REQ), sizeof (DDEV_REQ));
  if (recvport <= 0)
    {
      dbg_printf ("KEYBOARD: cannot make receive port.\n");
      slp_tsk ();
      /* メッセージバッファ生成に失敗 */
    }

  error = regist_port (KEYBOARD_DRIVER, recvport);
  if (error != E_OK)
    {
      dbg_printf ("keyboard: cannot regist port (error = %d)\n", error);
    }

  init_keyboard_interrupt ();	/* 割り込みハンドラの登録 */
  init_keybuffer ();		/* キーボードバッファの初期化 */

  /* キー入力を待つ時に使用するイベントフラグの初期化 */
  waitflag = get_flag (TA_WSGL, 0);
  dbg_printf ("keyboard: eventflag = %d\n", waitflag);	/* */

  driver_mode = WAITMODE;

  initialized = 1;

  get_tid(&my_tskid);
}
Esempio n. 24
0
/**
 * Used to start profiling a section of code. A section started by profile_begin needs to be closed off by calling
 * profile_end with the same argument.
 * @param name A globally unique string that will be displayed in the HUD readout
 */
void profile_begin(const char* name)
{
    if (Cmdline_json_profiling)
    {
        std::lock_guard<std::mutex> guard(json_mutex);

        tracing_data data;

        data.name = name;

        data.pid = get_pid();
        data.tid = get_tid();

        data.enter = true;
        data.time = timer_get_nanoseconds();

        if (do_gpu_queries) {
            data.gpu_query = get_query_object();
            gr_query_value(data.gpu_query, QueryType::Timestamp);
        } else {
            data.gpu_query = -1;
        }

        current_frame_data.push_back(data);
    }

    if (Cmdline_frame_profile)
    {
        int parent = -1;
        for (int i = 0; i < (int)samples.size(); i++) {
            if ( !samples[i].open_profiles ) {
                continue;
            }

            samples[i].num_children++;

            if (samples[i].num_children == 1) {
                // this is our direct parent for this new sample
                parent = i;
            }
        }

        for(int i = 0; i < (int)samples.size(); i++) {
            if( !strcmp(samples[i].name.c_str(), name) && samples[i].parent == parent ) {
                // found the profile sample
                samples[i].open_profiles++;
                samples[i].profile_instances++;
                samples[i].start_time = timer_get_microseconds();
                Assert(samples[i].open_profiles == 1); // max 1 open at once
                return;
            }
        }

        // create a new profile sample
        profile_sample new_sample;

        new_sample.name = SCP_string(name);
        new_sample.open_profiles = 1;
        new_sample.profile_instances = 1;
        new_sample.accumulator = 0;
        new_sample.start_time = timer_get_microseconds();
        new_sample.children_sample_time = 0;
        new_sample.num_children = 0;
        new_sample.parent = parent;

        samples.push_back(new_sample);
    }
}
Esempio n. 25
0
void *select_and_execute(void *arg)
{
	fd_set io;
	int i, rv, rlen, les, es;
	unsigned char buf[2001];
	int err;
	struct pollfd pf[MAX_SOCKS];
	int64_t lt, c_time;
	int read_ok;
	char ra[50];

	if (arg)
		thread_name = (char *) arg;
	else
		thread_name = "main";

	tid = get_tid();
	les = 1;
	es = 0;
	lt = getTick();
	memset(&pf, -1, sizeof(pf));
	LOG("Starting select_and_execute on thread ID %x, thread_name %s", tid,
			thread_name);
	while (run_loop)
	{
		c_time = getTick();
		es = 0;
		clean_mutexes();
		for (i = 0; i < max_sock; i++)
			if (s[i] && s[i]->enabled && s[i]->tid == tid)
			{
				pf[i].fd = s[i]->sock;
				pf[i].events = s[i]->events;
				pf[i].revents = 0;
				s[i]->last_poll = c_time;
				es++;
			}
			else
			{
				pf[i].fd = -1;
				pf[i].events = pf[i].revents = 0;
			}
		i = -1;
		if (les == 0 && es == 0 && tid != main_tid)
		{
			LOG("No enabled sockets for Thread ID %lx name %s ... exiting ",
					tid, thread_name);
			break;
		}
		les = es;
		//    LOG("start select");
		if ((rv = poll(pf, max_sock, 100)) < 0)
		{
			LOG("select_and_execute: select() error %d: %s", errno,
					strerror(errno));
			continue;
		}
		//              LOG("select returned %d",rv);
		if (rv > 0)
			while (++i < max_sock)
				if ((pf[i].fd >= 0) && pf[i].revents)
				{
					sockets *ss = s[i];
					if (!ss)
						continue;

					c_time = getTick();

					LOGL(6,
							"event on socket index %d handle %d type %d (poll fd:%d, revents=%d)",
							i, ss->sock, ss->type, pf[i].fd, pf[i].revents);
					sockets_lock(ss);

					if (pf[i].revents & POLLOUT)
					{
						ss->events &= ~POLLOUT;
					}
					if (!ss->buf || ss->buf == buf)
					{
						ss->buf = buf;
						ss->lbuf = sizeof(buf) - 1;
						ss->rlen = 0;
					}
					if (ss->rlen >= ss->lbuf)
					{
						LOG(
								"Socket buffer full, handle %d, sock_id %d, type %d, lbuf %d, rlen %d, ss->buf = %p, buf %p",
								ss->sock, i, ss->type, ss->lbuf, ss->rlen,
								ss->buf, buf);
						ss->rlen = 0;
					}
					rlen = 0;
					if (opts.bw > 0 && bw > opts.bw && ss->type == TYPE_DVR)
					{
						int64_t ms = 1000 - c_time + bwtt;
						if (bwnotify++ == 0)
							LOG(
									"capping %d sock %d for the next %jd ms, sleeping for the next %jd ms",
									i, ss->sock, ms, ms / 50);
						if (ms > 50)
							usleep(ms * 20);
						sockets_unlock(ss);
						continue;

					}

					read_ok = ss->read(ss->sock, &ss->buf[ss->rlen],
							ss->lbuf - ss->rlen, ss, &rlen);

					if (opts.log >= 1)
					{
						int64_t now = getTick();
						if (now - c_time > 100)
							LOG(
									"WARNING: read on socket id %d, handle %d, took %jd ms",
									ss->id, ss->sock, now - c_time);
					}

					err = 0;
					if (rlen < 0)
						err = errno;
					if (rlen > 0)
						ss->rtime = c_time;
					if (read_ok && rlen >= 0)
						ss->rlen += rlen;
					else
						ss->rlen = 0;
					//force 0 at the end of the string
					if (ss->lbuf >= ss->rlen)
						ss->buf[ss->rlen] = 0;
					LOGL(6,
							"Read %s %d (rlen:%d/total:%d) bytes from %d -> %p - iteration %d action %p",
							read_ok ? "OK" : "NOK", rlen, ss->rlen, ss->lbuf,
							ss->sock, ss->buf, it++, ss->action);

					if (((ss->rlen > 0) || err == EWOULDBLOCK) && ss->action
							&& (ss->type != TYPE_SERVER))
						ss->action(ss);
					sockets_unlock(ss);

					if (!read_ok && ss->type != TYPE_SERVER)
					{
						char *err_str;
						char *types[] =
						{ "udp", "tcp", "server", "http", "rtsp", "dvr" };
						if (rlen == 0)
						{
							err = 0;
							err_str = "Close";
						}
						else if (err == EOVERFLOW)
							err_str = "EOVERFLOW";
						else if (err == EWOULDBLOCK)
							err_str = "Connected";
						else
							err_str = strerror(err);

						if (ss->type == TYPE_RTCP || ss->sock == SOCK_TIMEOUT)
						{
							LOG(
									"ignoring error on sock_id %d handle %d type %d error %d : %s",
									ss->id, ss->sock, ss->type, err, err_str);
							continue; // do not close the RTCP socket, we might get some errors here but ignore them
						}
						LOG(
								"select_and_execute[%d]: %s on socket %d (sid:%d) from %s:%d - type %s errno %d",
								i, err_str, ss->sock, ss->sid,
								get_socket_rhost(ss->id, ra, sizeof(ra)),
								ntohs(ss->sa.sin_port), types[ss->type], err);
						if (err == EOVERFLOW || err == EWOULDBLOCK)
							continue;
						if (err == EAGAIN)
						{
							ss->err++;
							if (ss->err < 10)
								continue;
						}
						sockets_del(i);

						LOG("Delete socket %d done: sid %d", i, ss->sid);
						continue;
					}

//					ss->err = 0;					
				}
		// checking every 60seconds for idle connections - or if select times out
		c_time = getTick();
		if (rv == 0 || (c_time - lt >= 200))
		{
			sockets *ss;
			lt = c_time;
			i = -1;
			while (++i < max_sock)
				if ((ss = get_sockets(i)) && (ss->tid == tid)
						&& ((ss->timeout_ms > 0
								&& lt - ss->rtime > ss->timeout_ms)
								|| (ss->timeout_ms == 1)))
				{
					if (ss->timeout)
					{
						int rv;
						if (ss->sock == SOCK_TIMEOUT)
							ss->rtime = getTick();
						sockets_lock(ss);
						rv = ss->timeout(ss);
						sockets_unlock(ss);
						if (rv)
							sockets_del(i);
					}

					if (!ss->timeout)
						sockets_del(i);
				}
		}
	}

	clean_mutexes();

	if (tid == main_tid)
		LOG("The main loop ended, run_loop = %d", run_loop);
	add_join_thread(tid);

	return NULL;
}
Esempio n. 26
0
/**
 * Used to end profiling of a section of code. Note that the parameter given MUST match that of the preceding call
 * to profile_begin
 * @param name A globally unique string that will be displayed in the HUD readout
 */
void profile_end(const char* name)
{
    if (Cmdline_json_profiling)
    {
        std::lock_guard<std::mutex> guard(json_mutex);

        tracing_data data;

        data.name = name;

        data.pid = get_pid();
        data.tid = get_tid();

        data.enter = false;
        data.time = timer_get_nanoseconds();

        if (do_gpu_queries) {
            data.gpu_query = get_query_object();
            gr_query_value(data.gpu_query, QueryType::Timestamp);
        } else {
            data.gpu_query = -1;
        }

        current_frame_data.push_back(data);
    }

    if (Cmdline_frame_profile) {
        int num_parents = 0;
        int child_of = -1;

        for ( int i = 0; i < (int)samples.size(); i++ ) {
            if ( samples[i].open_profiles ) {
                if ( samples[i].num_children == 1 ) {
                    child_of = i;
                }
            }
        }

        for ( int i = 0; i < (int)samples.size(); i++ ) {
            if ( !strcmp(samples[i].name.c_str(), name) && samples[i].parent == child_of ) {
                int inner = 0;
                int parent = -1;
                std::uint64_t end_time = timer_get_microseconds();
                samples[i].open_profiles--;

                // count all parents and find the immediate parent
                while ( inner < (int)samples.size() ) {
                    if ( samples[inner].open_profiles > 0 ) {
                        // found a parent (any open profiles are parents)
                        num_parents++;

                        if (parent < 0) {
                            // replace invalid parent (index)
                            parent = inner;
                        }
                        else if (samples[inner].start_time >= samples[parent].start_time) {
                            // replace with more immediate parent
                            parent = inner;
                        }
                    }
                    inner++;
                }

                // remember the current number of parents of the sample
                samples[i].num_parents = num_parents;

                if ( parent >= 0 ) {
                    // record this time in children_sample_time (add it in)
                    samples[parent].children_sample_time += end_time - samples[i].start_time;
                }

                // save sample time in accumulator
                samples[i].accumulator += end_time - samples[i].start_time;

                break;
            }
        }

        for (int i = 0; i < (int)samples.size(); i++) {
            if (samples[i].open_profiles) {
                samples[i].num_children--;
                samples[i].num_children = MAX(samples[i].num_children, 0);
            }
        }
    }
}
Esempio n. 27
0
void _System_PowerOff(void)
{
    //register int i;
    DBG_FUNC_BEGIN("\r\n");

#if _MIPS_TODO
    //when flow is very slow after case POWERON_CB_END: g_bIsInitSystemFinish = TRUE;
    //press power off key will cause system hang
    //=> should wait for power on finish before power off
    if((pwrOffType == SYS_POWEROFF_NORMAL))
    {
        ID currTid = 0;
        get_tid(&currTid);
        if (INITTSK_ID != currTid)
        {
            InitMain_WaitFinish();
        }
    }
#endif


#if 0
    ///////////////////////////////////////////
    if(System_GetState(SYS_STATE_POWEROFF) == SYS_POWEROFF_NORMAL)
    {
        //"normal power-off sequence"
        DBG_MSG("Power Off Sequence = Normal\r\n");

        //shut down FW subsystems
            DevMan[SYS]->CmdAsync(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[CARD]->CmdAsync(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[SENSOR]->CmdAsync(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[LENS]->CmdAsync(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[CARD]->WaitSync(DEVMAN_SYNC_EXIT_POSTCLOSE);//wait until Card finish
            DevMan[NAND]->CmdAsync(DEVMAN_CMD_EXIT, 0, 0);

        //shut down HW devices
            DevMan[AUDIO]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[USB]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[DISP]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
    }
    else if(System_GetState(SYS_STATE_POWEROFF) == SYS_POWEROFF_SAFE)
    {
        //"safe power-off sequence"
        DBG_MSG("Power Off Sequence = Safe\r\n");

        //shut down FW subsystems
            DevMan[SYS]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[CARD]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[NAND]->CmdAsync(DEVMAN_CMD_EXIT, 0, 0);

        //shut down HW devices
            DevMan[AUDIO]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[USB]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[SENSOR]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[LENS]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[DISP]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
    }
    else if(System_GetState(SYS_STATE_POWEROFF) == SYS_POWEROFF_LOWPOWER)
    {
        //"lowpower power-off sequence"
        DBG_MSG("Power Off Sequence = LowPower\r\n");

        //shut down FW subsystems
            DevMan[SYS]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            //DevMan[CARD]->SetSync(DEVMAN_CMD_EXIT, 0, 0);

        //shut down HW devices
            DevMan[AUDIO]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            //DevMan[USB]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            //DevMan[SENSOR]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            //DevMan[LENS]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[DISP]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
    }
    else if(System_GetState(SYS_STATE_POWEROFF) == SYS_POWEROFF_CHARGE)
    {
        //"charge power-off sequence"
        DBG_MSG("Power Off Sequence = Charge\r\n");

        //shut down FW subsystems
            DevMan[SYS]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            //DevMan[CARD]->SetSync(DEVMAN_CMD_EXIT, 0, 0);

        //shut down HW devices
            DevMan[AUDIO]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[USB]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            //DevMan[SENSOR]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            //DevMan[LENS]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
            DevMan[DISP]->Cmd(DEVMAN_CMD_EXIT, 0, 0);
    }

    ///////////////////////////////////////////
    //wait until all device manager exit finish
    for(i=0;i<DEVICE_ID_MAX;i++)
        DevMan[i]->WaitFinish(DEVMAN_CMD_EXIT);

    ///////////////////////////////////////////
    //close all device manager
    for(i=0;i<DEVICE_ID_MAX;i++)
        DevMan[i]->Close();
#endif
    DBG_FUNC_END("\r\n");
}
Esempio n. 28
0
/**
 * The thread workloop with nanosleeps, executed from
 * thread_run,
 */
static void thread_workloop(int tid, int loop_count_max){

	unsigned int loop_count;       
	
#ifdef HAVE_GSL
	timespec_t sleep_time = {
		.tv_sec = 0,
		.tv_nsec = gsl_ran_poisson(Nsleep_rng, (double)DEFAULT_SLEEP_NSECS)
	};
#endif	/* HAVE_GSL */

	timespec_t remaining_time;

	DSTRM_EVENT(THREAD, WORKLOOP_BEGIN, tid);


#ifdef HAVE_GSL
	DSTRM_EVENT_DATA(THREAD, NANOSLEEP, tid, sizeof(long), &sleep_time.tv_nsec, "print_long");

	for (loop_count = 0; loop_count < loop_count_max; loop_count++){
		; /* Lame upcount loop */ 
	} 

        if (nanosleep(&sleep_time, &remaining_time)) {
#else  /* HAVE_GSL */
	if (nanosleep(&default_sleep_time, &remaining_time)) {
#endif /* HAVE_GSL */
	
		fprintf(stderr,
			"[%d]nanosleep: stopped with %ld sec %ld ns remaining",
			tid,
			(unsigned long)remaining_time.tv_sec,
			remaining_time.tv_nsec);
		
	}


	DSTRM_EVENT(THREAD, WORKLOOP_END, tid);
}



void* thread_run(void* arg)
{

	cpu_set_t          cpuset;
	unsigned int         period_count;
	threadspec        *targs = (threadspec*) arg;
	int                   ret;             

	DSTRM_EVENT(THREAD, BEGIN, targs->id);

	CPU_ZERO(&cpuset);
	if (targs->cpu < get_maxcpus()) {
		
		CPU_SET(targs->cpu, &cpuset);
	} else {
		fprintf(stderr,
			"CPU_SET: Unable to set thread cpu to %d",
			targs->cpu);
		fprintf(stderr, "CPU_SET: defaulting to CPU-0");
	}
	
	DSTRM_EVENT_DATA(THREAD, SET_CPU, targs->id, sizeof(cpu_set_t), &cpuset, "print_int");
	sched_setaffinity(get_tid(), sizeof(cpu_set_t), &cpuset);

#ifdef HAVE_KUSP
 	/* If we are supposed to identify the components of the application then
	 * create a component that represents this thread and add the component
	 * to the set that represents the pipeline.
	 */	

	printf("ccsm_create_component: Creating component for [%d] : %s\n", 
	       targs->id, targs->name);

	if (ccsm_create_component_self(Ccsm_fd, targs->name)) {
		perror("ccsm_create_component_self");
		pthread_exit(NULL);
	}

	printf("ccsm_add_member: Adding [%d] : %s to the set\n", 
	       targs->id, targs->name);

	if (ccsm_add_member(Ccsm_fd, HGS_GROUP_NAME, targs->name)) {
		perror("ccsm_add_member");
		pthread_exit(NULL);
	}

	printf("sdf_edf_set_member_deadline:%s-> %ld:%ld\n", targs->name, 
	       (unsigned long)targs->deadline.tv_sec, targs->deadline.tv_nsec);

	if (sdf_edf_set_member_deadline(Hgs_fd, HGS_GROUP_NAME, 
					targs->name, &targs->deadline)) {
		perror("sdf_edf_set_member_deadline");
		pthread_exit(NULL);
	}		

#endif	/* HAVE_KUSP */


 	for (period_count = 0; period_count < targs->intervals; period_count++) {	
	
#ifdef HAVE_KUSP		
		ret = sdf_edf_next_instance(Hgs_fd, HGS_GROUP_NAME, targs->name);
		if (ret) {
			perror("sdf_edf_next_instance");
			pthread_exit(NULL);
		}
#endif /* HAVE_KUSP */

		thread_workloop(targs->id, targs->loop_count);
		/* printf("%s - %d\n", targs->name, period_count); */
	}
	
	DSTRM_EVENT(THREAD, END, targs->id);
	printf("%s Completed!\n", targs->name);

	pthread_exit(NULL);
} 



/**
 *  This subroutine processes the command line options 
 */
void process_options (int argc, char *argv[])
{

	int error = 0;
	int c;
	for (;;) {
		int option_index = 0;

		static struct option long_options[] = {
			{"config",           required_argument, NULL, 'c'},
			{"pprint",           no_argument,       NULL, 'p'},
			{"help",             no_argument,       NULL, 'h'},
			{NULL, 0, NULL, 0}
		};

		/*
		 * c contains the last in the lists above corresponding to
		 * the long argument the user used.
		 */
		c = getopt_long(argc, argv, "c:p", long_options, &option_index);

		if (c == -1)
			break;
		switch (c) {
		case 0:
			switch (option_index) {
			case 0:
				printf(help_string, argv[0]);
				exit(EXIT_SUCCESS);
				break;
			}
			break;
			
		case 'c':
			/* Parse the whole config using the standard config parser */
			Params.config = kusp_parse_xml_config(optarg);

			/* Get the thread section for ease of use */
			Params.thread_config = get_test_config(Params.config, &Params.thread_count);

			if (!Params.thread_config || !Params.thread_count){
				
				printf("parse config: failed to parse any"
                                        "threads from config file %s (tc is"
                                        "null? %s) \n", 
				       optarg, 
				       Params.thread_config == NULL ? "yes" : "no");
			}
			
			break;
		case 'p':
			Params.pprint = TRUE;
			break;

		case 'h':
			error = 1;
			break;

		}
	}
	
	if (error) {
		printf(help_string, argv[0]);
		exit(EXIT_FAILURE);
	}
}
Esempio n. 29
0
/*
** STRATEGY
**
**	Attempts to limit access scan to less than the entire De.ov_source
**	relation by finding a key which can be used for associative
**	access to the De.ov_source reln or an index thereon.  The key is
**	constructed from domain-value specifications found in the
**	clauses of the qualification list using sub-routine findsimp
**	in findsimp.c and other subroutines in file key.c
*/
int
strategy(void)
{
	register int		i, allexact;
	acc_param_t	sourceparm, indexparm;
	index_t		itup, rtup;
	key_t		lowikey[MAX_2ND_KEYS+1], highikey[MAX_2ND_KEYS+1];
	key_t		lowbkey[MAX_2ND_KEYS+1], highbkey[MAX_2ND_KEYS+1];
	register desc_t		*d;
	extern desc_t		Inddes;
	char 			*tp;
	long			l_lid[MAXLID], h_lid[MAXLID];
	int			keytype;
	long			page, l, t;
	int			lidsize;
	locator_t		tidloc;

	keytype = allexact = 0;
#ifdef xOTR1
	if (tTf(70, 0))
		printf("STRATEGY\tSource=%.12s\tNewq = %d\n",
		       De.ov_source ? De.ov_source->d_r.r_id : "(none)",
		       De.de_newq);
#endif

	while (De.de_newq)	/* if De.de_newq=TRUE then compute a new strategy */
			/* NOTE: This while loop is executed only once */ {
		De.ov_scanr = De.ov_source;
	
		if (!De.ov_scanr)
			return (1);	/* return immediately if there is no source relation */
	
		De.ov_fmode = NOKEY;	/* assume a find mode with no key */
	
		if (!De.ov_qlist)
			break;	/* if no qualification then you must scan entire rel */
		/*
		** Here we check for the special condition
		** of a where clause consisting only of a tid.
		*/
		if (tid_only_test())
			return(1);

		/* copy structure of source relation into sourceparm */
		paramd(De.ov_source, &sourceparm);
	
		/* if source is unkeyed and has no sec index then give up */
		if (sourceparm.mode == NOKEY && De.ov_source->d_r.r_indexed <= 0 && !De.ov_source->d_r.r_dim)
			break;

		/* find all simple clauses if any */
		if (!findsimps())
			break;	/* break if there are no simple clauses */
	
		/* Four steps are now performed to try and find a key.
		** First if the relation is hashed then an exact key is search for
		**
		** Second if there are secondary indices, then a search is made
		** for an exact key. If that fails then a  check is made for
		** a range key. The result of the rangekey check is saved.
		**
		** A step to check for possible use of Btrees is made here,
		** although in actuality, an exact btreekey search is used
		** after an exact range key search but before a range key search.
		** A BTree range search is used only as a last alternative
		** to a no key search.
		**
		** Third if the relation is an ISAM a check is  made for
		** an exact key or a range key.
		**
		** Fourth if there is a secondary index, then if step two
		** found a key, that key is used.
		**
		**  Lastly, give up and scan the  entire relation
		*/
	
		/* step one. Try to find exact key on primary */
		if (exactkey(&sourceparm, De.ov_lkey_struct)) {
			De.ov_fmode = EXACTKEY;
			break;
		}
	
		/* step two. If there is an index, try to find an exactkey on one of them */
		if (De.ov_source->d_r.r_indexed > 0) {
	
			opencatalog("indices", OR_READ);
			ingres_setkey(&Inddes, &itup, De.ov_source->d_r.r_id, IRELIDP);
			ingres_setkey(&Inddes, &itup, De.ov_source->d_r.r_owner, IOWNERP);
			if ((i = find(&Inddes, EXACTKEY, &De.ov_lotid, &De.ov_hitid, (char *)&itup)) != 0)
				syserr("strategy:find indices %d", i);
	
			while (!(i = get(&Inddes, &De.ov_lotid, &De.ov_hitid, (char *)&itup, NXTTUP))) {
#ifdef xOTR1
				if (tTf(70, 3))
					printup(&Inddes, (char *)&itup);
#endif
				if (!bequal(itup.i_relname, De.ov_source->d_r.r_id, MAX_NAME_SIZE) ||
				    !bequal(itup.i_owner, De.ov_source->d_r.r_owner, 2))
					continue;
				parami(&itup, &indexparm);
				if (exactkey(&indexparm, De.ov_lkey_struct)) {
					De.ov_fmode = EXACTKEY;
					d = openindex(itup.i_index);
					/* temp check for 6.0 index */
					if ((int) d->d_r.r_indexed == -1)
						ov_err(BADSECINDX);
					De.ov_scanr = d;
					break;
				}
				if (De.ov_fmode == LRANGEKEY)
					continue;	/* a range key on a s.i. has already been found */
				if ((allexact = rangekey(&indexparm, lowikey, highikey)) != 0) {
					bmove((char *)&itup, (char *)&rtup, sizeof(itup));	/* save tuple */
					De.ov_fmode = LRANGEKEY;
				}
			}
			if (i < 0)
				syserr("stragery:bad get from index-rel %d", i);
			/* If an exactkey on a secondary index was found, look no more. */
			if (De.ov_fmode == EXACTKEY)
				break;
		}
	
		/* attempt to use Btree in aiding search */
		if ((i = btreekey(lowbkey, highbkey)) != 0) {
			if (i > 0)
				De.ov_fmode = BTREEKEY; 
			else if (De.ov_fmode != LRANGEKEY) {
			/* use range key search over btree range search */
				keytype = i;
				De.ov_fmode = BTREERANGE;
			}
		}

		/* step three. Look for a range key on primary */
		if ((i = rangekey(&sourceparm, De.ov_lkey_struct, De.ov_hkey_struct)) != 0) {
			if (i < 0)
				De.ov_fmode = EXACTKEY;
			else if (De.ov_fmode == BTREEKEY) {
			/* use exact btree search over range search */
				bmove((char *) lowbkey, (char *) De.ov_lkey_struct, sizeof(lowbkey));
				bmove((char *) highbkey, (char *) De.ov_hkey_struct, sizeof(highbkey));
			}
			else
				De.ov_fmode = LRANGEKEY;
			break;
		}

		if (De.ov_fmode == BTREEKEY) {
			bmove((char *) lowbkey, (char *) De.ov_lkey_struct, sizeof(lowbkey));
			bmove((char *) highbkey, (char *) De.ov_hkey_struct, sizeof(highbkey));
			break;
		}
	
		/* last step. If a secondary index range key was found, use it */
		if (De.ov_fmode == LRANGEKEY) {
			if (allexact < 0)
				De.ov_fmode = EXACTKEY;
			d = openindex(rtup.i_index);
			/* temp check for 6.0 index */
			if ((int) d->d_r.r_indexed == -1)
				ov_err(BADSECINDX);
			De.ov_scanr = d;
			bmove((char *)lowikey, (char *)De.ov_lkey_struct, sizeof(lowikey));
			bmove((char *)highikey, (char *)De.ov_hkey_struct, sizeof(highikey));
			break;
		}

		/* nothing will work. give up! */
		break;
	
	}

	/* check for De.de_newq = FALSE and no source relation */
	if (!De.ov_scanr)
		return (1);
	/*
	** At this point the strategy is determined.
	**
	** If De.ov_fmode is EXACTKEY then De.ov_lkey_struct contains
	** the pointers to the keys.
	**
	** If De.ov_fmode is LRANGEKEY then De.ov_lkey_struct contains
	** the pointers to the low keys and De.ov_hkey_struct
	** contains pointers to the high keys.
	**
	** If De.ov_fmode is BTREEKEY then De.ov_lkey_struct contains
	** pointers to the key lid.
	**
	** If De.ov_fmode is BTREERANGE then lowbkey contains pointers
	** to the low key lid and highbkey contains pointers to the
	** high key lid.
	**
	** If De.ov_fmode is NOKEY, then a full scan will be performed
	*/
#ifdef xOTR1
	if (tTf(70, -1))
		printf("De.ov_fmode= %d\n",De.ov_fmode);
#endif

	if (De.ov_fmode == BTREERANGE) {
	/* requires special type of search to limit tid scan */
		for (i = 0; i < De.ov_scanr->d_r.r_dim; ++i) {
			l_lid[i] = 0;
			h_lid[i] = 0;
		}
		lidsize = LIDSIZE * De.ov_scanr->d_r.r_dim;
		/* get low lids */
		if (keytype == -1 || keytype == -3) {
			tp = De.ov_keyl + De.ov_scanr->d_r.r_width - lidsize;
			bmove(l_lid, tp, lidsize);
			setallkey(lowbkey, De.ov_keyl);
			bmove(tp, l_lid, lidsize);
		}
		/* get high lids */
		if (keytype == -2 || keytype == -3) {
			tp = De.ov_keyh + De.ov_scanr->d_r.r_width - lidsize;
			bmove(h_lid, tp, lidsize);
			setallkey(highbkey, De.ov_keyh);
			bmove(tp, h_lid, lidsize);
		}
		setglobalint(BTREE_FD_NAME, De.ov_scanr->d_btreefd);
		/* scan through lids to fill in unprovided lids and to check
		** for lids that are too big
		*/
		page = RT;
		for (i = 0; i < De.ov_scanr->d_r.r_dim; ++i) {
			if (l_lid[i] <= 0) 
				l_lid[i] = 1;
			l = last_lid(page) - 1;
			if (h_lid[i] < 0)
				return(0);
			if (!h_lid[i] || h_lid[i] > l)
				h_lid[i] = l;
			if ((t = get_tid(page, h_lid[i], &tidloc)) < 0)
				syserr("bad gettid in strategy, lid = %ld\n", h_lid[i]);
			page = t;
		}
		/* check whether lo > hi */
		for (i = 0; i < De.ov_scanr->d_r.r_dim; ++i)
			if (l_lid[i] < h_lid[i])
				break;
			else if (l_lid[i] > h_lid[i])
				return(0);
#ifdef xOTR1
		if (tTf(70,0))
			for (i = 0 ; i < De.ov_scanr->d_r.r_dim; ++i)
				printf("hi = %ld, lo = %ld\n", h_lid[i], l_lid[i]);
#endif
		/* find the smallest and largest possible tids of the lids
		** within the provided range */
		btreerange(De.ov_scanr, l_lid, h_lid, &De.ov_lotid, &De.ov_hitid);
	} else {
		/* set up the key tuples */
		if (De.ov_fmode != NOKEY) {
			if (setallkey(De.ov_lkey_struct, De.ov_keyl))
				return (0);	/* query false. There is a simple
						** clause which can never be satisfied.
						** These simple clauses can be choosey!
						*/
		}
	
		if ((i = find(De.ov_scanr, De.ov_fmode, &De.ov_lotid, &De.ov_hitid, De.ov_keyl)) != 0)
			syserr("strategy:find1 %.12s, %d", De.ov_scanr->d_r.r_id, i);

		if (De.ov_fmode == LRANGEKEY) {
			setallkey(De.ov_hkey_struct, De.ov_keyh);
		if ((i = find(De.ov_scanr, HRANGEKEY, &De.ov_lotid, &De.ov_hitid, De.ov_keyh)) != 0)
				syserr("strategy:find2 %.12s, %d", De.ov_scanr->d_r.r_id, i);
		}
	}
	
#ifdef xOTR1
	if (tTf(70, 1)) {
		printf("Lo");
		dumptid(&De.ov_lotid);
		printf("Hi");
		dumptid(&De.ov_hitid);
	}
#endif

	return (1);
}
Esempio n. 30
0
void
ppp_input_task(intptr_t exinf)
{
	T_NET_BUF	*input;
	T_PPP_PROTENT	*proto;
	ID		tskid;
	int_t		ix;

	/* ポートを初期設定する */
	syscall(serial_opn_por(HDLC_PORTID));
	syscall(serial_ctl_por(HDLC_PORTID, IOCTL_FCSND | IOCTL_FCRCV));

	get_tid(&tskid);

#ifdef PPP_CFG_MODEM

	init_modem();
	syslog(LOG_NOTICE, "[PPP INPUT:%d] started with modem on port %d.", tskid, HDLC_PORTID);

#else	/* of #ifdef PPP_CFG_MODEM */

	syslog(LOG_NOTICE, "[PPP INPUT:%d] started on port %d.", tskid, HDLC_PORTID);

#endif	/* of #ifdef PPP_CFG_MODEM */

	/* ネットワークタイマタスクを起動する */
	syscall(act_tsk(NET_TIMER_TASK));

	/* 上位プロトコルを初期化する */
	for (ix = 0; (proto = protocols[ix]) != NULL; ix ++)
		if (proto->init != NULL)
			(*proto->init)();

	lcp_lowerup();
	lcp_open(PPP_OPEN_PASSIVE);

	/* PPP 出力タスクを起動する */
	syscall(act_tsk(PPP_OUTPUT_TASK));

	while (true) {
		if (tget_net_buf(&input, IF_PDU_SIZE, TMO_PPP_GET_NET_BUF) == E_OK) {
			while (HDLC_read(input, IF_PDU_SIZE) != E_OK)
				;
			if (input->len > 0) {

	#ifdef PPP_IDLE_TIMEOUT
				wai_sem(SEM_IDLE_TIMEOUT);
				if (idle && ntohs(*GET_PPP_HDR(input)) != PPP_LCP) {
					untimeout((FP)idle_timeout, NULL);
					idle = false;
					}
				sig_sem(SEM_IDLE_TIMEOUT);
	#endif	/* of #ifdef PPP_IDLE_TIMEOUT */

				parse_input(input);
				}
			else
				syscall(rel_net_buf(input));

	#ifdef PPP_IDLE_TIMEOUT
			wai_sem(SEM_IDLE_TIMEOUT);
			if (!idle && ppp_phase == PPP_PHASE_NETWORK) {
				timeout((FP)idle_timeout, NULL, PPP_IDLE_TIMEOUT);
				idle = true;
				}
			else if (idle && ppp_phase != PPP_PHASE_NETWORK) {
				untimeout((FP)idle_timeout, NULL);
				idle = false;
				}
			sig_sem(SEM_IDLE_TIMEOUT);
	#endif	/* of #ifdef PPP_IDLE_TIMEOUT */

			}
		else {
			HDLC_dummy_read();
			NET_COUNT_PPP(net_count_ppp.in_err_packets, 1);
			NET_COUNT_PPP(net_count_ppp_no_bufs, 1);
			}
		}
	}