xref: /haiku/src/add-ons/kernel/generic/tty/module.cpp (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 /*
2  * Copyright 2010, Michael Lotz, mmlr@mlotz.ch.
3  * Copyright 2004, Axel Dörfler, axeld@pinc-software.de.
4  * Distributed under the terms of the MIT License.
5  */
6 
7 #include <new>
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 
13 #include <lock.h>
14 
15 #include <tty/tty_module.h>
16 
17 #include "tty_private.h"
18 
19 struct mutex gGlobalTTYLock;
20 struct mutex gTTYCookieLock;
21 struct recursive_lock gTTYRequestLock;
22 
23 
24 static status_t
25 init_tty_module()
26 {
27 	// create the request mutex
28 	recursive_lock_init(&gTTYRequestLock, "tty requests");
29 
30 	// create the global mutex
31 	mutex_init(&gGlobalTTYLock, "tty global");
32 
33 	// create the cookie mutex
34 	mutex_init(&gTTYCookieLock, "tty cookies");
35 
36 	return B_OK;
37 }
38 
39 
40 static void
41 uninit_tty_module()
42 {
43 	recursive_lock_destroy(&gTTYRequestLock);
44 	mutex_destroy(&gTTYCookieLock);
45 	mutex_destroy(&gGlobalTTYLock);
46 }
47 
48 
49 static int32
50 tty_module_std_ops(int32 op, ...)
51 {
52 	switch (op) {
53 		case B_MODULE_INIT:
54 			return init_tty_module();
55 
56 		case B_MODULE_UNINIT:
57 			uninit_tty_module();
58 			return B_OK;
59 	}
60 
61 	return B_BAD_VALUE;
62 }
63 
64 
65 static struct tty_module_info sTTYModule = {
66 	{
67 		B_TTY_MODULE_NAME,
68 		0, //B_KEEP_LOADED,
69 		tty_module_std_ops
70 	},
71 
72 	&tty_create,
73 	&tty_destroy,
74 	&tty_create_cookie,
75 	&tty_close_cookie,
76 	&tty_destroy_cookie,
77 	&tty_read,
78 	&tty_write,
79 	&tty_control,
80 	&tty_select,
81 	&tty_deselect,
82 	&tty_hardware_signal
83 };
84 
85 
86 module_info *modules[] = {
87 	(module_info *)&sTTYModule,
88 	NULL
89 };
90