int mutex_test(void) { static mutex_t imutex = MUTEX_INITIAL_VALUE(imutex); printf("preinitialized mutex:\n"); hexdump(&imutex, sizeof(imutex)); mutex_t m; mutex_init(&m); thread_t *threads[5]; for (uint i=0; i < countof(threads); i++) { threads[i] = thread_create("mutex tester", &mutex_thread, &m, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE); thread_resume(threads[i]); } for (uint i=0; i < countof(threads); i++) { thread_join(threads[i], NULL, INFINITE_TIME); } printf("done with simple mutex tests\n"); printf("testing mutex timeout\n"); mutex_t timeout_mutex; mutex_init(&timeout_mutex); mutex_acquire(&timeout_mutex); for (uint i=0; i < 2; i++) { threads[i] = thread_create("mutex timeout tester", &mutex_timeout_thread, (void *)&timeout_mutex, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE); thread_resume(threads[i]); } for (uint i=2; i < 4; i++) { threads[i] = thread_create("mutex timeout tester", &mutex_zerotimeout_thread, (void *)&timeout_mutex, DEFAULT_PRIORITY, DEFAULT_STACK_SIZE); thread_resume(threads[i]); } thread_sleep(5000); mutex_release(&timeout_mutex); for (uint i=0; i < 4; i++) { thread_join(threads[i], NULL, INFINITE_TIME); } printf("done with mutex tests\n"); mutex_destroy(&timeout_mutex); return 0; }
fscookie *cookie; int ref; const struct fs_api *api; }; struct filehandle { filecookie *cookie; struct fs_mount *mount; }; struct dirhandle { dircookie *cookie; struct fs_mount *mount; }; static mutex_t mount_lock = MUTEX_INITIAL_VALUE(mount_lock); static struct list_node mounts = LIST_INITIAL_VALUE(mounts); static struct list_node fses = LIST_INITIAL_VALUE(fses); // defined in the linker script extern const struct fs_impl __fs_impl_start; extern const struct fs_impl __fs_impl_end; static const struct fs_impl *find_fs(const char *name) { for (const struct fs_impl *fs = &__fs_impl_start; fs != &__fs_impl_end; fs++) { if (!strcmp(name, fs->name)) return fs; } return NULL; }