struct netsniff_ng_tx_thread_context * tx_thread_create(const cpu_set_t run_on, const int sched_prio, const int sched_policy, const char * dev_name, const char * bpf_path, const char * pcap_path) { int rc; struct netsniff_ng_tx_thread_context * thread_config = NULL; if ((thread_config = xzmalloc(sizeof(*thread_config))) == NULL) { warn("Cannot allocate tx thread configuration\n"); return (NULL); } if ((rc = thread_context_init(&thread_config->thread_ctx, run_on, sched_prio, sched_policy, TX_THREAD)) != 0) { goto error; } if ((rc = tx_nic_ctx_init(thread_config, dev_name, bpf_path, pcap_path)) != 0) { warn("Cannot initialize TX NIC context\n"); goto error; } if ((rc = pthread_create(&thread_config->thread_ctx.thread, &thread_config->thread_ctx.thread_attr, tx_thread_transmit, thread_config))) { warn("Could not start TX thread\n"); goto error; } return (thread_config); error: tx_thread_destroy(thread_config); return (NULL); }
/** * Przydziela deskryptor wątku. * @param type Poziom uprzywilejowania. * @param entry Adres procedury wejściowej. * @param arg Adres argumentu przekazywany do procedury wejściowej. * * Procedura przydziela ogólny deskryptor wątku. Wątek przydzielony * w ten sposób znajduje się w stanie surowym. */ thread_t * thread_create(int type, addr_t entry, addr_t arg) { thread_t *free_thr = kmem_cache_alloc(thread_cache, KM_SLEEP); if (free_thr) { thread_t *t = free_thr; t->thr_flags = THREAD_NEW | type; t->thr_entry_point = entry; t->thr_entry_arg = arg; t->thr_wakeup_time = 0; t->vm_space = NULL; t->thr_sleepq = NULL; list_insert_tail(&threads_list, t); vm_space_create_stack(&vm_kspace, &t->thr_kstack, thread_kstack_size); t->thr_kstack_size = thread_kstack_size; thread_context_init(t, &t->thr_context); return t; } else { kprintf("ERROR: no free threads!\n"); return NULL; } }