1 /*
2 * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
4 *
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
8 */
9 #include "server.h"
10
11 #include <pthread.h>
12 #include <pthread-l4.h>
13 #include <cassert>
14 #include <cstdio>
15
16 #include <l4/sys/debugger.h>
17 #include <l4/re/error_helper>
18 #include <l4/re/env>
19
20 namespace Ned {
21
22 using L4Re::chksys;
23
Server()24 Server::Server()
25 {
26 pthread_mutex_init(&_start_mutex, NULL);
27 pthread_mutex_lock(&_start_mutex);
28
29 pthread_attr_t attr;
30 struct sched_param sp;
31
32 pthread_attr_init(&attr);
33 sp.sched_priority = 0xf1;
34 pthread_attr_setschedpolicy(&attr, SCHED_L4);
35 pthread_attr_setschedparam(&attr, &sp);
36 pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
37
38 int r = pthread_create(&_th, &attr, &__run, this);
39 if (r)
40 fprintf(stderr, "error: could not start server thread: %d\n", r);
41
42 l4_debugger_set_object_name(pthread_l4_cap(_th), "ned-svr");
43
44 pthread_attr_destroy(&attr);
45 pthread_mutex_lock(&_start_mutex);
46 pthread_mutex_unlock(&_start_mutex);
47 pthread_mutex_destroy(&_start_mutex);
48 }
49 void
run()50 Server::run()
51 {
52 _r = new Registry(this, Pthread::L4::cap(pthread_self()),
53 L4Re::Env::env()->factory());
54 pthread_mutex_unlock(&_start_mutex);
55 loop<L4::Runtime_error>(_r, l4_utcb());
56 }
57
58 void *
__run(void * a)59 Server::__run(void *a)
60 {
61 reinterpret_cast<Server*>(a)->run();
62 return a;
63 }
64
65
66
67 }
68