ADTast-experimental
Last change
on this file since b49310f was
88ac843e,
checked in by Thierry Delisle <tdelisle@…>, 2 years ago
|
Moved lockfree containers to containers/lockfree.hfa.
Added poison_list, which is a lock-free bag with push and poison as only operations.
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[0aec496] | 1 | #pragma once |
---|
| 2 | |
---|
[7f0ac12] | 3 | #include <iofwd.hfa> |
---|
[88ac843e] | 4 | #include <containers/lockfree.hfa> |
---|
[0aec496] | 5 | #include <thread.hfa> |
---|
| 6 | |
---|
| 7 | extern "C" { |
---|
| 8 | #include <sys/socket.h> |
---|
| 9 | } |
---|
| 10 | |
---|
[137974ae] | 11 | #include "printer.hfa" |
---|
| 12 | |
---|
[0aec496] | 13 | //============================================================================================= |
---|
| 14 | // Worker Thread |
---|
| 15 | //============================================================================================= |
---|
| 16 | |
---|
[7f0ac12] | 17 | struct connection { |
---|
[0aec496] | 18 | int pipe[2]; |
---|
[7f0ac12] | 19 | struct { |
---|
| 20 | sendfile_stats_t sendfile; |
---|
| 21 | } stats; |
---|
| 22 | }; |
---|
| 23 | |
---|
| 24 | static inline void ?{}( connection & this ) { |
---|
| 25 | this.pipe[0] = -1; |
---|
| 26 | this.pipe[1] = -1; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | thread AcceptWorker { |
---|
| 30 | connection conn; |
---|
[0aec496] | 31 | int sockfd; |
---|
| 32 | struct sockaddr * addr; |
---|
| 33 | socklen_t * addrlen; |
---|
| 34 | int flags; |
---|
[481ee28] | 35 | volatile bool done; |
---|
[32d1383] | 36 | acceptor_stats_t stats; |
---|
[7f0ac12] | 37 | }; |
---|
| 38 | void ?{}( AcceptWorker & this); |
---|
| 39 | void main( AcceptWorker & ); |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | struct PendingRead { |
---|
| 43 | PendingRead * volatile next; |
---|
| 44 | io_future_t f; |
---|
[ef3c383] | 45 | struct { |
---|
[7f0ac12] | 46 | void * buf; |
---|
| 47 | size_t len; |
---|
| 48 | } in; |
---|
| 49 | struct { |
---|
| 50 | volatile int fd; |
---|
| 51 | } out; |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | static inline PendingRead * volatile & ?`next ( PendingRead * node ) { |
---|
| 55 | return node->next; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | thread ChannelWorker { |
---|
| 59 | connection conn; |
---|
| 60 | volatile bool done; |
---|
| 61 | mpsc_queue(PendingRead) * queue; |
---|
| 62 | }; |
---|
| 63 | void ?{}( ChannelWorker & ); |
---|
| 64 | void main( ChannelWorker & ); |
---|
| 65 | |
---|
| 66 | thread Acceptor { |
---|
| 67 | mpsc_queue(PendingRead) * queue; |
---|
| 68 | int sockfd; |
---|
| 69 | struct sockaddr * addr; |
---|
| 70 | socklen_t * addrlen; |
---|
| 71 | int flags; |
---|
| 72 | volatile bool done; |
---|
[137974ae] | 73 | acceptor_stats_t stats; |
---|
[0aec496] | 74 | }; |
---|
[329e26a] | 75 | void ?{}( Acceptor &, int cli ); |
---|
[7f0ac12] | 76 | void main( Acceptor & ); |
---|
Note: See
TracBrowser
for help on using the repository browser.