41using namespace wayland;
53 auto queue = display.create_queue();
56 auto display_wrapper = display.proxy_create_wrapper();
57 display_wrapper.set_queue(queue);
58 registry = display_wrapper.get_registry();
62 registry = display.get_registry();
69 registry.
on_global() = [&seat, ®istry](std::uint32_t name,
const std::string& interface, std::uint32_t version)
71 if(interface == seat_t::interface_name)
72 registry.
bind(name, seat, version);
74 display.roundtrip_queue(queue);
76 throw std::runtime_error(
"Did NOT get seat interface - thread-safety issue!");
83 auto queue2 = display.create_queue();
86 seat = seat.proxy_create_wrapper();
90 bool have_keymap =
false;
91 kbd.
on_keymap() = [&have_keymap](keyboard_keymap_format ,
int fd, std::uint32_t )
96 display.roundtrip_queue(queue2);
99 throw std::runtime_error(
"Did NOT get keymap - thread-safety issue!");
103 std::thread bind_thread(
bool safe)
105 return std::thread{std::bind(&binder::bind,
this, safe)};
110 binder(
const binder&) =
delete;
111 binder(binder&&) noexcept = delete;
112 ~binder() noexcept = default;
113 binder& operator=(const binder&) = delete;
114 binder& operator=(binder&&) noexcept = delete;
116 void run(
int thread_count,
int round_count,
bool safe)
118 std::atomic<bool> stop{
false};
119 std::cout <<
"Using " << thread_count <<
" threads, safe: " << safe << std::endl;
120 for(
int round = 0; round < round_count; round++)
124 std::cout <<
"Round " << round <<
"/" << round_count << std::endl;
126 std::vector<std::thread> threads;
127 threads.reserve(thread_count);
128 for(
int i = 0; i < thread_count; i++)
130 threads.emplace_back(bind_thread(safe));
132 for(
auto& thread : threads)
141int main(
int argc,
char** argv)
145 std::cerr <<
"Usage: " << argv[0] <<
" <thread count> <run count> <use safe mechanism?>" << std::endl;
149 b.run(std::stoi(argv[1]), std::stoi(argv[2]), std::stoi(argv[3]));
std::function< void(keyboard_keymap_format, int, uint32_t)> & on_keymap()
keyboard mapping
void set_queue(event_queue_t queue)
Assign a proxy to an event queue.
std::function< void(uint32_t, std::string, uint32_t)> & on_global()
announce global object
proxy_t bind(uint32_t name, proxy_t &interface, uint32_t version)
bind an object to the display
keyboard_t get_keyboard()
return keyboard object