#include #include #include "pslist.h" struct frotz { struct pslist_entry f_entry; }; struct { kmutex_t lock; struct pslist_head list; pserialize_t psz; } frobbotzim __cacheline_aligned; void frobbotzim_init(void) { mutex_init(&frobbotzim.lock); #if 1 PSLIST_INIT(&frobbotzim.list); #else pslist_init(&frobbotzim.list); #endif psz = pserialize_create(); } void frotz_create(int key) { struct frotz *f; f = ...; mutex_enter(&frobbotzim.lock); #if 1 PSLIST_WRITER_INSERT_HEAD(&frobbotzim.list, f, f_entry); #else pslist_writer_insert_head(&frobbotzim.list, &f->f_entry); #endif mutex_exit(&frobbotzim.lock); } int frotz_lookup(int key) { struct frotz *f; #if 0 struct pslist_entry *e; #endif int result = -1; int s; s = pserialize_read_enter(); #if 1 PSLIST_READER_FOREACH(f, &frobbotzim.list, struct frotz, f_entry) { if (f->f_key == key) { result = f->f_fnord; break; } } #else for (e = pslist_reader_first(&frobbotzim.list); e != NULL; e = pslist_reader_next(&f->f_entry)) { f = container_of(e, struct frotz, f_entry); if (f->f_key == key) { result = f->f_fnord; break; } } #endif pserialize_read_exit(s); return result; } void frotz_destroy(int key) { struct frotz *f; #if 0 struct pslist_entry *e; #endif mutex_enter(&frobbotzim.lock); #if 1 PSLIST_WRITER_FOREACH(f, &frobbotzim.list, struct frotz, f_entry) { if (f->f_key == key) { PSLIST_WRITER_REMOVE(f, f_entry); pserialize_perform(frobbotzim.psz); break; } } #else for (e = pslist_writer_first(&frobbotzim.list); e != NULL; e = pslist_writer_next(&f->f_entry)) { f = container_of(e, struct frotz, f_entry); if (f->f_key == key) { pslist_writer_remove(&f->f_entry); pserialize_perform(frobbotzim.psz); break; } } #endif mutex_exit(&frobbotzim.lock); if (f != NULL) kmem_free(f, sizeof(*f)); }