Пример #1
0
static void sock_init(struct sock *sk, int family, int type,
		int protocol, const struct sock_family_ops *f_ops,
		const struct sock_proto_ops *p_ops,
		const struct net_pack_out_ops *o_ops) {
	assert(sk != NULL);
	assert(f_ops != NULL);
	assert(p_ops != NULL);

	dlist_head_init(&sk->lnk);
	sock_opt_init(&sk->opt, family, type, protocol);
	skb_queue_init(&sk->rx_queue);
	skb_queue_init(&sk->tx_queue);
	sk->rx_data_len = 0;
	sock_set_state(sk, SS_UNKNOWN);
	sk->shutdown_flag = 0;
	sk->p_sk = sk->p_sk; /* setup in sock_alloc() */
	sk->f_ops = f_ops;
	sk->p_ops = p_ops;
	sk->o_ops = o_ops;
	sk->src_addr = sk->dst_addr = NULL;
	sk->addr_len = 0;
	sk->err = 0;

	idesc_init(&sk->idesc, &task_idx_ops_socket, FS_MAY_READ | FS_MAY_WRITE);
	sock_xattr_init(sk);
	security_sock_create(sk);
}
Пример #2
0
void thread_init(struct thread *t, int priority,
		void *(*run)(void *), void *arg) {

	assert(t);
	assert(run);
	assert(thread_stack_get(t));
	assert(thread_stack_get_size(t));

	t->id = id_counter++; /* setup thread ID */

	dlist_head_init(&t->thread_link); /* default unlink value */

	t->task = NULL;

	t->critical_count = __CRITICAL_COUNT(CRITICAL_SCHED_LOCK);
	t->siglock = 0;

	t->state = TS_INIT;

	if (thread_local_alloc(t, MODOPS_THREAD_KEY_QUANTITY)) {
		panic("can't initialize thread_local");
	}

	t->joining = NULL;

	t->run = run;
	t->run_arg = arg;

	/* cpu context init */
	/* setup stack pointer to the top of allocated memory
	 * The structure of kernel thread stack follow:
	 * +++++++++++++++ top
	 *                  |
	 *                  v
	 * the thread structure
	 * xxxxxxx
	 * the end
	 * +++++++++++++++ bottom (t->stack - allocated memory for the stack)
	 */
	context_init(&t->context, CONTEXT_PRIVELEGED | CONTEXT_IRQDISABLE,
			thread_trampoline, thread_stack_get(t) + thread_stack_get_size(t));

	sigstate_init(&t->sigstate);

	schedee_init(&t->schedee, priority, thread_process);

	/* initialize everthing else */
	thread_wait_init(&t->thread_wait);
}
Пример #3
0
struct usb_hcd *usb_hcd_alloc(struct usb_hcd_ops *ops, void *args) {
    struct usb_hcd *hcd = pool_alloc(&usb_hcds);

    if (!hcd) {
        return NULL;
    }

    hcd->ops = ops;
    index_init(&hcd->enumerator, 1, USB_HC_MAX_DEV, &hcd->idx_data);

    dlist_head_init(&hcd->lnk);
    usb_queue_init(&hcd->reset_queue);

    if (ops->hcd_hci_alloc) {
        hcd->hci_specific = ops->hcd_hci_alloc(hcd, args);
        if (!hcd->hci_specific) {
            pool_free(&usb_hcds, hcd);
            return NULL;
        }
    }

    return hcd;
}
Пример #4
0
void runq_item_init(runq_item_t *runq_link) {
	dlist_head_init(runq_link);
}