Example #1
0
int btree_thread_ui_addfile_open(struct bthread_info *bi, const char *filename, int *add, int *update)
{
    if (filename && bi) {
        int fd, len, idx = 0;
#define BUFMAX 128
        char buffer[BUFMAX];

        fd = open(filename, O_RDONLY);
        if (fd < 0)
            return -1;

        while (1) {
            char *p;
            len = read(fd, buffer + idx, BUFMAX - idx);
            if (len <= 0)
                break;
            p = buffer;
            while (idx < len) {
                char *x = strchr(p, '\n');
                if (x) {
                    *x = 0;
                    int mon;
                    struct info_node *node = mq_get(bi->free_queue, 0);

                    strncpy(node->str, p, sizeof(node->str) - 1);

                    if (strlen(node->str) < 8) {
                        mq_append(bi->free_queue, node, 1);
                        continue;
                    }

                    mon = FAST_HASH(node->str) % MAX_THREAD;
                    mq_append(bi->node[mon].info_queue, node, 1);

                    p = x + 1;
                }
                else {
                    idx = BUFMAX - (p - buffer);
                    memmove(buffer, p, idx);
                    break;
                }
            }
        }
        close(fd);
    }

    return -1;
}
Example #2
0
void *insert_thread(struct bthread_node *thread_node)
{
    struct info_node *str_node;

    thread_node->add = thread_node->update = 1;

    while (!thread_node->eof) {
        str_node = mq_get(thread_node->info_queue, 1);

        if (str_node) {
            thread_node->count++;
            userinfo_insert(thread_node->tree, str_node->str, str_node->seek, &thread_node->add, &thread_node->update);
            mq_append(thread_node->bi->free_queue, str_node, 1);
        }
        else  {
            break;
        }
    }

//	printf("insert %d pthread exit\n", thread_node->count);
    pthread_exit(0);

    return NULL;
}
Example #3
0
PUBLIC void main()
{
	mq_t *mq;
	int r;
	int source, timerand, fd;
	struct fssignon device;
#ifdef __minix_vmd
	struct systaskinfo info;
#endif
	u8_t randbits[32];
	struct timeval tv;

#if DEBUG
	printf("Starting inet...\n");
	printf("%s\n", version);
#endif

	/* Read configuration. */
	nw_conf();

	/* Get a random number */
	timerand= 1;
	fd= open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK);
	if (fd != -1)
	{
		r= read(fd, randbits, sizeof(randbits));
		if (r == sizeof(randbits))
			timerand= 0;
		else
		{
			printf("unable to read random data from %s: %s\n",
				RANDOM_DEV_NAME, r == -1 ? strerror(errno) :
				r == 0 ? "EOF" : "not enough data");
		}
		close(fd);
	}
	else
	{
		printf("unable to open random device %s: %s\n",
			RANDOM_DEV_NAME, strerror(errno));
	}
	if (timerand)
	{
		printf("using current time for random-number seed\n");
#ifdef __minix_vmd
		r= sysutime(UTIME_TIMEOFDAY, &tv);
#else /* Minix 3 */
		r= gettimeofday(&tv, NULL);
#endif
		if (r == -1)
		{
			printf("sysutime failed: %s\n", strerror(errno));
			exit(1);
		}
		memcpy(randbits, &tv, sizeof(tv));
	}
	init_rand256(randbits);

#ifdef __minix_vmd
	if (svrctl(SYSSIGNON, (void *) &info) == -1) pause();

	/* Our new identity as a server. */
	this_proc = info.proc_nr;
#else /* Minix 3 */

	/* Our new identity as a server. */
	if ((this_proc = getprocnr()) < 0)
		ip_panic(( "unable to get own process nr\n"));
#endif

	/* Register the device group. */
	device.dev= ip_dev;
	device.style= STYLE_CLONE;
	if (svrctl(FSSIGNON, (void *) &device) == -1) {
		printf("inet: error %d on registering ethernet devices\n",
			errno);
		pause();
	}

#ifdef BUF_CONSISTENCY_CHECK
	inet_buf_debug= (getenv("inetbufdebug") && 
		(strcmp(getenv("inetbufdebug"), "on") == 0));
	inet_buf_debug= 100;
	if (inet_buf_debug)
	{
		ip_warning(( "buffer consistency check enabled" ));
	}
#endif

	if (getenv("killerinet"))
	{
		ip_warning(( "killer inet active" ));
		killer_inet= 1;
	}

#ifdef __minix_vmd
	r= sys_findproc(SYN_AL_NAME, &synal_tasknr, 0);
	if (r != OK)
		ip_panic(( "unable to find synchronous alarm task: %d\n", r ));
#endif

	nw_init();
	while (TRUE)
	{
#ifdef BUF_CONSISTENCY_CHECK
		if (inet_buf_debug)
		{
			static int buf_debug_count= 0;

			if (++buf_debug_count >= inet_buf_debug)
			{
				buf_debug_count= 0;
				if (!bf_consistency_check())
					break;
			}
		}
#endif
		if (ev_head)
		{
			ev_process();
			continue;
		}
		if (clck_call_expire)
		{
			clck_expire_timers();
			continue;
		}
		mq= mq_get();
		if (!mq)
			ip_panic(("out of messages"));

		r= receive (ANY, &mq->mq_mess);
		if (r<0)
		{
			ip_panic(("unable to receive: %d", r));
		}
		reset_time();
		source= mq->mq_mess.m_source;
		if (source == FS_PROC_NR)
		{
			sr_rec(mq);
		}
#ifdef __minix_vmd
		else if (source == synal_tasknr)
		{
			clck_tick (&mq->mq_mess);
			mq_free(mq);
		}
#else /* Minix 3 */
		else if (mq->mq_mess.m_type == SYN_ALARM)
		{
			clck_tick(&mq->mq_mess);
			mq_free(mq);
		} 
		else if (mq->mq_mess.m_type == SYS_SIG)
		{
			/* signaled */ 
			/* probably SIGTERM */
			mq_free(mq);
		} 
		else if (mq->mq_mess.m_type & NOTIFY_MESSAGE)
		{
			/* A driver is (re)started. */
			eth_check_drivers(&mq->mq_mess);
			mq_free(mq);
		}
#endif
		else
		{
compare(mq->mq_mess.m_type, ==, DL_TASK_REPLY);
			eth_rec(&mq->mq_mess);
			mq_free(mq);
		}
	}
	ip_panic(("task is not allowed to terminate"));
}
Example #4
0
void main(void)
{
	mq_t *mq;
	int r;
	int source, m_type, timerand, fd;
	u32_t tasknr;
	struct fssignon device;
	u8_t randbits[32];
	struct timeval tv;

#if DEBUG
	printk("Starting inet...\n");
	printk("%s\n", version);
#endif

#if HZ_DYNAMIC
	system_hz = sys_hz();
#endif

	/* Read configuration. */
	nw_conf();

	/* Get a random number */
	timerand= 1;
	fd= open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK);
	if (fd != -1)
	{
		r= read(fd, randbits, sizeof(randbits));
		if (r == sizeof(randbits))
			timerand= 0;
		else
		{
			printk("inet: unable to read random data from %s: %s\n",
				RANDOM_DEV_NAME, r == -1 ? strerror(errno) :
				r == 0 ? "EOF" : "not enough data");
		}
		close(fd);
	}
	else
	{
		printk("inet: unable to open random device %s: %s\n",
			RANDOM_DEV_NAME, strerror(errno));
	}
	if (timerand)
	{
		printk("inet: using current time for random-number seed\n");
		r= gettimeofday(&tv, NULL);
		if (r == -1)
		{
			printk("sysutime failed: %s\n", strerror(errno));
			exit(1);
		}
		memcpy(randbits, &tv, sizeof(tv));
	}
	init_rand256(randbits);

	/* Our new identity as a server. */
	r= ds_retrieve_u32("inet", &tasknr);
	if (r != 0)
		ip_panic(("inet: ds_retrieve_u32 failed for 'inet': %d", r));
	this_proc= tasknr;

	/* Register the device group. */
	device.dev= ip_dev;
	device.style= STYLE_CLONE;
	if (svrctl(FSSIGNON, (void *) &device) == -1) {
		printk("inet: error %d on registering ethernet devices\n",
			errno);
		pause();
	}

#ifdef BUF_CONSISTENCY_CHECK
	inet_buf_debug= (getenv("inetbufdebug") && 
		(strcmp(getenv("inetbufdebug"), "on") == 0));
	inet_buf_debug= 100;
	if (inet_buf_debug)
	{
		ip_warning(( "buffer consistency check enabled" ));
	}
#endif

	if (getenv("killerinet"))
	{
		ip_warning(( "killer inet active" ));
		killer_inet= 1;
	}

	nw_init();
	while (TRUE)
	{
#ifdef BUF_CONSISTENCY_CHECK
		if (inet_buf_debug)
		{
			static int buf_debug_count= 0;

			if (++buf_debug_count >= inet_buf_debug)
			{
				buf_debug_count= 0;
				if (!bf_consistency_check())
					break;
			}
		}
#endif
		if (ev_head)
		{
			ev_process();
			continue;
		}
		if (clck_call_expire)
		{
			clck_expire_timers();
			continue;
		}
		mq= mq_get();
		if (!mq)
			ip_panic(("out of messages"));

		r = kipc_module_call(KIPC_RECEIVE, 0, ENDPT_ANY, &mq->mq_mess);
		if (r<0)
		{
			ip_panic(("unable to receive: %d", r));
		}
		reset_time();
		source= mq->mq_mess.m_source;
		m_type= mq->mq_mess.m_type;

		if (source == VFS_PROC_NR) {
			sr_rec(mq);
		} else if (is_notify(m_type)) {
			if (_ENDPOINT_P(source) == CLOCK) {
				clck_tick(&mq->mq_mess);
				mq_free(mq);
			} else if (_ENDPOINT_P(source) == PM_PROC_NR) {
				/* signaled */
				/* probably SIGTERM */
				mq_free(mq);
			} else {
				/* A driver is (re)started. */
				eth_check_drivers(&mq->mq_mess);
				mq_free(mq);
			}
		} else if (m_type == DL_CONF_REPLY || m_type == DL_TASK_REPLY ||
			m_type == DL_NAME_REPLY || m_type == DL_STAT_REPLY) {
			eth_rec(&mq->mq_mess);
			mq_free(mq);
		} else {
			printk("inet: got bad message type 0x%x from %d\n",
				mq->mq_mess.m_type, mq->mq_mess.m_source);
			mq_free(mq);
		}
	}
	ip_panic(("task is not allowed to terminate"));
}
Example #5
0
int btree_thread_ui_addfile_fopen(struct bthread_info *bi, const char *filename, int *add, int *update)
{
    if (filename && bi) {
        size_t seek;
        index_add_file(filename);

        while (1) {
            struct info_node *node = mq_get(bi->free_queue, 0);

            seek = index_read_line(node->str, sizeof(node->str) - 1);

            printf("[%u], %s\n", seek, node->str);

            if (seek >= 0) {
                int mon;

                if (strlen(node->str) < 8) {
                    mq_append(bi->free_queue, node, 1);
                    continue;
                }
                mon = FAST_HASH(node->str) % MAX_THREAD;

                mq_append(bi->node[mon].info_queue, node, 1);
            }
            else {
                mq_append(bi->free_queue, node, 1);
                break;
            }
        }



#if 0
        if ((fp  = fopen(filename, "r")) != NULL) {
            while (!feof(fp)) {
                struct info_node *node = mq_get(bi->free_queue, 0);

                node->seek = ftell(fp);
                if (fgets(node->str, sizeof(node->str) - 1, fp)) {
                    int mon;

                    if (strlen(node->str) < 8) {
                        mq_append(bi->free_queue, node, 1);
                        continue;
                    }

                    mon = FAST_HASH(node->str) % MAX_THREAD;

                    mq_append(bi->node[mon].info_queue, node, 1);
                }
                else
                    mq_append(bi->free_queue, node, 1);
            }
            fclose(fp);

            return 0;
        }
#endif
    }

    return -1;
}
Example #6
0
PUBLIC int main(int argc, char *argv[])
{
	mq_t *mq;
	int ipc_status;
	int r;
	endpoint_t source;
	int m_type;

	/* SEF local startup. */
	sef_local_startup();

	while (TRUE)
	{
#ifdef BUF_CONSISTENCY_CHECK
		if (inet_buf_debug)
		{
			static int buf_debug_count= 0;

			if (++buf_debug_count >= inet_buf_debug)
			{
				buf_debug_count= 0;
				if (!bf_consistency_check())
					break;
			}
		}
#endif
		if (ev_head)
		{
			ev_process();
			continue;
		}
		if (clck_call_expire)
		{
			clck_expire_timers();
			continue;
		}
		mq= mq_get();
		if (!mq)
			ip_panic(("out of messages"));

		r= sef_receive_status(ANY, &mq->mq_mess, &ipc_status);
		if (r<0)
		{
			ip_panic(("unable to receive: %d", r));
		}
		reset_time();
		source= mq->mq_mess.m_source;
		m_type= mq->mq_mess.m_type;
		if (source == VFS_PROC_NR)
		{
			sr_rec(mq);
		}
		else if (is_ipc_notify(ipc_status))
		{
			if (source == CLOCK)
			{
				clck_tick(&mq->mq_mess);
				mq_free(mq);
			} 
			else if (source == PM_PROC_NR)
			{
				/* signaled */ 
				/* probably SIGTERM */
				mq_free(mq);
			} 
			else if (source == DS_PROC_NR)
			{
				/* DS notifies us of an event. */
				ds_event();
				mq_free(mq);
			}
			else
			{
				printf("inet: got unexpected notify from %d\n",
					mq->mq_mess.m_source);
				mq_free(mq);
			}
		}
		else if (m_type == DL_CONF_REPLY || m_type == DL_TASK_REPLY ||
			m_type == DL_STAT_REPLY)
		{
			eth_rec(&mq->mq_mess);
			mq_free(mq);
		}
		else
		{
			printf("inet: got bad message type 0x%x from %d\n",
				mq->mq_mess.m_type, mq->mq_mess.m_source);
			mq_free(mq);
		}
	}
	ip_panic(("task is not allowed to terminate"));
	return 1;
}
Example #7
0
int main(void)
{
    message_t message;
    uint8_t next_grid[32];
    uint16_t interval = 150;
    uint8_t current_pattern = 0;

    initialise();
    set_up_timers();
    init_timers();
    HTbrightness(1);

    goto init;
    while (1) {
        if (mq_get(&message)) {
            switch (msg_get_event(message)) {
            case M_TIMER:
                memset(next_grid, 0, 32);
                for (uint8_t x = 0; x < 32; x++) {
                    for (uint8_t y = 0; y < 8; y++) {
                        uint8_t c = count(x, y);
                        if (c == 3)
                            next_grid[x] |= 1 << y;
                        else if (c == 4)
                            next_grid[x] |= leds[x] & (1 << y);
                    }
                }
                memcpy(leds, next_grid, 32);
                HTsendscreen();
                break;

            case M_KEY_DOWN:
            case M_KEY_REPEAT:
                switch (msg_get_param(message)) {
                case KEY_LEFT:
                    if (interval > MIN_INTERVAL) {
                        interval -= INTERVAL_INCREMENT;
                        set_timer(interval, 0, true);
                    }
                    break;

                case KEY_RIGHT:
                    if (interval < MAX_INTERVAL) {
                        interval += INTERVAL_INCREMENT;
                        set_timer(interval, 0, true);
                    }
                    break;

                case KEY_MIDDLE:
                    current_pattern = (current_pattern + 1) % (sizeof(patterns) / sizeof(character));
                init:
                    memset(leds, 0, 32);
                    write_offset(patterns[current_pattern], 10, 2);
                    HTsendscreen();
                    set_timer(interval, 0, true);
                    break;
                }
                break;
            }
        }
    }
}