Skip to content

arceos-org/handler_table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

handler_table

Crates.io Docs.rs CI

A lock-free table of event handlers.

Examples

use handler_table::HandlerTable;

static TABLE: HandlerTable<8> = HandlerTable::new();

TABLE.register_handler(0, || {
   println!("Hello, event 0!");
});
TABLE.register_handler(1, || {
   println!("Hello, event 1!");
});

assert!(TABLE.handle(0)); // print "Hello, event 0!"
assert!(!TABLE.handle(2)); // unregistered

assert!(TABLE.unregister_handler(2).is_none());
let func = TABLE.unregister_handler(1).unwrap(); // retrieve the handler
func(); // print "Hello, event 1!"

assert!(!TABLE.handle(1)); // unregistered