-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequestQueue_notifier.cpp
More file actions
92 lines (58 loc) · 2.56 KB
/
requestQueue_notifier.cpp
File metadata and controls
92 lines (58 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "node_controller.hpp"
#include "globals.hpp"
#include "message_buffer.hpp"
#include <list>
#include <iostream>
extern nodeController::Ricart_RequestQueue RQST_Q;
size_t compute_buffer_index( Action act, subAction sub_act );
extern unsigned MY_NODE_ID;
void * nodeController::request_queue_notifier( void* argument )
{
using namespace nodeController::requestQueue_notifier;
using std::list;
using std::cerr;
using std::endl;
thread_arg arg = *(thread_arg *) argument;
//delete (thread_arg *) argument;
size_t my_index = compute_buffer_index( arg.act, arg.sub_act );
while ( true ) {
if ( RQST_Q.peek_at_head( arg.act,
arg.sub_act,
&Ricart_RequestQueue::is_local_client_request ) ) {
//if here, then local client is at head of queue
Message msg;
RQST_Q.peek_at_head( arg.act, arg.sub_act,
[&msg]( Message m ){
return (msg = m );
} );
RQST_Q.pop_local_client_from_head( arg.act, arg.sub_act );
arg.outLocal_buffer->produce_msg( my_index, msg );
RQST_Q.wait_local_client_finished( arg.act, arg.sub_act );
//now that client message completely finished,
//we can free the loc_msg pointer
delete msg.loc_msg;
}
//if here, then we've either found a local client at head of queue
//and gave permission for local client to enter C.S. and local client
//finished in C.S.
//or there was not a local client at head of queue
//in both cases, pop_deferred_reply will construct list of all
//messages on queue up to but not including my next message and
//these are exactly the messages I need to REPLY to in either case.
list<Message> deferred_replies;
RQST_Q.pop_deferred_reply_list( arg.act, arg.sub_act, deferred_replies );
for ( auto next_msg : deferred_replies ) {
if ( next_msg.loc_msg ) {
if ( DO_DEBUG ) {
std::cerr << "ERROR: queue_notifier added local client message"
"to deferred reply list; here is the "
"local message: " << std::endl
<< next_msg << std::endl;
}
exit( EXIT_FAILURE );
}
arg.outPeer_buffer->produce_msg( 0, next_msg );
}
}
return nullptr;
}