void fs_fsm_init(void) { linkedlist_create(&fsdriverslist, LINKEDLIST_MUTEX); linkedlist_create(&fslist, LINKEDLIST_MUTEX); hash_create(&fsdrivershash, 0, 10); devfs = fs_filesystem_create(); linkedlist_insert(&fslist, &devfs->listnode, devfs); }
void vfs_icache_init(void) { icache = hash_create(0, 0, 0x4000); ic_dirty = linkedlist_create(0, LINKEDLIST_MUTEX); ic_inuse = linkedlist_create(0, LINKEDLIST_MUTEX); ic_lru = queue_create(0, 0); ic_lock = mutex_create(0, 0); mm_reclaim_register(fs_inode_reclaim_lru, sizeof(struct inode)); }
/** * Initialization of NAT tables. */ void nat_init(void) { nat6_tcp = radixtree_create(); nat6_udp = radixtree_create(); nat6_icmp = radixtree_create(); nat4_tcp = radixtree_create(); nat4_udp = radixtree_create(); nat4_icmp = radixtree_create(); nat4_tcp_fragments = radixtree_create(); timeout_icmp = linkedlist_create(); timeout_udp = linkedlist_create(); timeout_tcp_est = linkedlist_create(); timeout_tcp_trans = linkedlist_create(); timeout_tcp_fragments = linkedlist_create(); }
int hash_insert(struct hash *h, const void *key, size_t keylen, struct hashelem *elem, void *data) { __lock(h); size_t index = __hashfn(key, keylen, h->length); elem->ptr = data; elem->key = key; elem->keylen = keylen; if(h->table[index] == NULL) { /* lazy-init the buckets */ h->table[index] = linkedlist_create(0, LINKEDLIST_LOCKLESS); } else { struct linkedentry *ent = linkedlist_find(h->table[index], __ll_check_exist, elem); if(ent) { __unlock(h); return -EEXIST; } } linkedlist_insert(h->table[index], &elem->entry, elem); h->count++; __unlock(h); return 0; }
void mm_reclaim_init(void) { linkedlist_create(&reclaimers, LINKEDLIST_MUTEX); }
int main() { struct linkedlist *l; struct node *n, *before; printf("testing list create..."); if ((l = linkedlist_create()) == NULL) goto fail; printf("[ok]\n"); printf("testing node create..."); if ((n = node_create('a')) == NULL) goto fail; printf("[ok]\n"); printf("testing insert of 1st node..."); linkedlist_insert_before(l, NULL, n); if (l->head != n) goto fail; printf("[ok]\n"); printf("testing insert at head..."); n = node_create('c'); linkedlist_insert_before(l, l->head, n); if (l->head != n) goto fail; printf("[ok]\n"); printf("testing get node..."); before = linkedlist_get_node(l, 1); if (before->c != 'a') goto fail; printf("[ok]\n"); printf("testing insert in middle..."); n = node_create('b'); linkedlist_insert_before(l, before, n); n = linkedlist_get_node(l, 1); if (n->c != 'b') goto fail; printf("[ok]\n"); printf("testing count..."); if (linkedlist_count(l) != 3) goto fail; printf("[ok]\n"); printf("testing del..."); linkedlist_del(l, n); printf("[ok]\n"); printf("testing free..."); linkedlist_free(l); printf("[ok]\n"); return 0; fail: printf("[failed]\n"); return -1; }
int network_create() { struct network *n = malloc(sizeof(struct network)); if (!n) return 1; n->users = linkedlist_create(); if (!n->users) { free(n); return 1; } n->games = linkedlist_create(); if (!n->games) { free(n->users); free(n); return 1; } n->m = SDL_CreateMutex();//I think this doesn't fail IPaddress ip; if (SDLNet_ResolveHost(&ip, 0, 3737)) { free(n->games); free(n->users); free(n); return 1; } TCPsocket m = SDLNet_TCP_Open(&ip); if (!m) { free(n->games); free(n->users); free(n); return 1; } while (1) { TCPsocket temp = SDLNet_TCP_Accept(m); if (temp) { struct network_client *nc = malloc(sizeof(struct network_client)); if (!nc) { //No more memory SDLNet_TCP_Close(temp); continue; } memset(nc, 0, sizeof(struct network_client)); nc->s = temp; nc->n = n; linkedlist_add_last(n->users,nc); //Send over the list of games, and their names linkedlist_node *ga = n->games->first; for (;ga;ga = ga->next) { struct game *g = ga->data; uint8_t name_len = 0; if (g->name) { uint32_t len = strlen(g->name); if (len > 0xff) name_len = 0xff; else name_len = len; } uint8_t data [262];//256 + 6 *data = 5; *(data + 1) = name_len; //Copy the game identification *(uint32_t *)(data + 2) = htonl(g->ident); //Copy the name memcpy(data + 6, g->name, name_len); SDLNet_TCP_Send(temp, data, name_len + 6); } SDL_CreateThread(network_listen, nc); } SDL_Delay(500); } return 0; }
void tm_init_multitasking(void) { printk(KERN_DEBUG, "[sched]: Starting multitasking system...\n"); sysgate_page = mm_physical_allocate(PAGE_SIZE, true); mm_physical_memcpy((void *)sysgate_page, (void *)signal_return_injector, MEMMAP_SYSGATE_ADDRESS_SIZE, PHYS_MEMCPY_MODE_DEST); process_table = hash_create(0, 0, 128); process_list = linkedlist_create(0, LINKEDLIST_MUTEX); mutex_create(&process_refs_lock, 0); mutex_create(&thread_refs_lock, 0); thread_table = hash_create(0, 0, 128); struct thread *thread = kmalloc(sizeof(struct thread)); struct process *proc = kernel_process = kmalloc(sizeof(struct process)); proc->refs = 2; thread->refs = 1; hash_insert(process_table, &proc->pid, sizeof(proc->pid), &proc->hash_elem, proc); hash_insert(thread_table, &thread->tid, sizeof(thread->tid), &thread->hash_elem, thread); linkedlist_insert(process_list, &proc->listnode, proc); valloc_create(&proc->mmf_valloc, MEMMAP_MMAP_BEGIN, MEMMAP_MMAP_END, PAGE_SIZE, 0); linkedlist_create(&proc->threadlist, 0); mutex_create(&proc->map_lock, 0); mutex_create(&proc->stacks_lock, 0); mutex_create(&proc->fdlock, 0); hash_create(&proc->files, HASH_LOCKLESS, 64); proc->magic = PROCESS_MAGIC; blocklist_create(&proc->waitlist, 0, "process-waitlist"); mutex_create(&proc->fdlock, 0); memcpy(&proc->vmm_context, &kernel_context, sizeof(kernel_context)); thread->process = proc; /* we have to do this early, so that the vmm system can use the lock... */ thread->state = THREADSTATE_RUNNING; thread->magic = THREAD_MAGIC; workqueue_create(&thread->resume_work, 0); thread->kernel_stack = (addr_t)&initial_kernel_stack; spinlock_create(&thread->status_lock); primary_cpu->active_queue = tqueue_create(0, 0); primary_cpu->idle_thread = thread; primary_cpu->numtasks=1; ticker_create(&primary_cpu->ticker, 0); workqueue_create(&primary_cpu->work, 0); tm_thread_add_to_process(thread, proc); tm_thread_add_to_cpu(thread, primary_cpu); atomic_fetch_add_explicit(&running_processes, 1, memory_order_relaxed); atomic_fetch_add_explicit(&running_threads, 1, memory_order_relaxed); set_ksf(KSF_THREADING); *(struct thread **)(thread->kernel_stack) = thread; primary_cpu->flags |= CPU_RUNNING; #if CONFIG_MODULES loader_add_kernel_symbol(tm_thread_delay_sleep); loader_add_kernel_symbol(tm_thread_delay); loader_add_kernel_symbol(tm_timing_get_microseconds); loader_add_kernel_symbol(tm_thread_set_state); loader_add_kernel_symbol(tm_thread_exit); loader_add_kernel_symbol(tm_thread_poke); loader_add_kernel_symbol(tm_thread_block); loader_add_kernel_symbol(tm_thread_got_signal); loader_add_kernel_symbol(tm_thread_unblock); loader_add_kernel_symbol(tm_blocklist_wakeall); loader_add_kernel_symbol(kthread_create); loader_add_kernel_symbol(kthread_wait); loader_add_kernel_symbol(kthread_join); loader_add_kernel_symbol(kthread_kill); loader_add_kernel_symbol(tm_schedule); loader_add_kernel_symbol(arch_tm_get_current_thread); #endif }