1 /* 2 * Generic event loop functionality. 3 * 4 * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include "event-loop.h" 23 24 #include <pthread.h> 25 #include <pthread-l4.h> 26 27 #include <l4/re/event> 28 29 /* Main loop for event threads. */ 30 31 void * 32 Event_loop::event_loop(void *data) 33 { 34 Event_loop *self = reinterpret_cast<Event_loop *>(data); 35 36 while (1) self->handle(); 37 38 return 0; 39 } 40 41 /* Event loop initiation. */ 42 43 void 44 Event_loop::start() 45 { 46 pthread_attr_t thread_attr; 47 struct sched_param sp; 48 49 /* Thread initialisation boilerplate. */ 50 51 if (pthread_attr_init(&thread_attr)) 52 return; 53 54 sp.sched_priority = _priority; 55 pthread_attr_setschedparam(&thread_attr, &sp); 56 pthread_attr_setschedpolicy(&thread_attr, SCHED_L4); 57 pthread_attr_setinheritsched(&thread_attr, PTHREAD_EXPLICIT_SCHED); 58 59 /* Provide this instance as the private data. */ 60 61 pthread_create(&_pthread, &thread_attr, event_loop, this); 62 }