Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: include/kernel/port.h

Issue 1437453002: [kernel][ports] Add basic ports functionality (Closed) Base URL: https://github.com/travisg/lk.git@master
Patch Set: travis review Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | kernel/port.c » ('j') | kernel/port.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 Carlos Pizano-Uribe cpu@chromium.org
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #ifndef __KERNEL_PORT_H
24 #define __KERNEL_PORT_H
25
26 #include <sys/types.h>
27 #include <compiler.h>
28
29
30 __BEGIN_CDECLS;
31
32 /* Ports are named, opaque objects and come in tree flavors, the
33 * write-side, the read-side and a port group which is a collection
34 * of read-side ports.
35 */
36
37 #define PORT_NAME_LEN 12
38
39 typedef void* port_t;
40
41 typedef struct {
42 char value[8];
43 } port_packet_t;
44
45 typedef struct {
46 void* ctx;
47 port_packet_t packet;
48 } port_result_t;
49
50 typedef enum {
51 PORT_MODE_BROADCAST = 0,
52 PORT_MODE_UNICAST = 1,
53 PORT_MODE_BIG_BUFFER = 2,
54 } port_mode_t;
55
56 /* Inits the port subsystem
57 */
58 void port_init(void);
59
60 /* Make a named write-side port. broadcast ports can be opened by any
61 * number of read-clients. |name| can be up to PORT_NAME_LEN chars.
62 */
63 status_t port_create(const char* name, port_mode_t mode, port_t* port);
64
65 /* Make a read-side port. Only non-destroyed existing write ports can
66 * be opened with this api. Unicast ports can only be opened once.
67 */
68 status_t port_open(const char* name, void* ctx, port_t* port);
69
70 /* Creates a read-side port group which behaves just like a regular
71 * read-side port. A given port can only be assoicated with one port group.
72 */
73 status_t port_group(port_t* ports, size_t count, port_t* group);
74
75 /* Write to a port |count| packets, non-blocking, all or none atomic success.
76 */
77 status_t port_write(port_t port, const port_packet_t* pk, size_t count);
78
79 /* Read one packet from the port or port group, blocking. The |result| contains
80 * the port that the message was read from.
81 */
82 status_t port_read(port_t port, lk_time_t timeout, port_result_t* result);
83
84 /* Destroy the write-side port, flush queued packets and release all resources,
85 * all calls will now fail on that port.
86 */
87 status_t port_destroy(port_t port);
88
89 /* Close the read-side port or the write side port. A closed write side port
90 * can be opened and the pending packets read. closing a port group does not
91 * close the included ports.
92 */
93 status_t port_close(port_t port);
94
95 __END_CDECLS;
96
97 #endif
98
OLDNEW
« no previous file with comments | « no previous file | kernel/port.c » ('j') | kernel/port.c » ('J')

Powered by Google App Engine
This is Rietveld 408576698