70 }
71
72 void JfrPostBox::post(JFR_Msg msg) {
73 const int the_message = MSGBIT(msg);
74 if (is_thread_lock_aversive()) {
75 deposit(the_message);
76 return;
77 }
78 if (!is_synchronous(the_message)) {
79 asynchronous_post(the_message);
80 return;
81 }
82 synchronous_post(the_message);
83 }
84
85 void JfrPostBox::deposit(int new_messages) {
86 while (true) {
87 const int current_msgs = Atomic::load(&_messages);
88 // OR the new message
89 const int exchange_value = current_msgs | new_messages;
90 const int result = Atomic::cmpxchg(exchange_value, &_messages, current_msgs);
91 if (result == current_msgs) {
92 return;
93 }
94 /* Some other thread just set exactly what this thread wanted */
95 if ((result & new_messages) == new_messages) {
96 return;
97 }
98 }
99 }
100
101 void JfrPostBox::asynchronous_post(int msg) {
102 assert(!is_synchronous(msg), "invariant");
103 deposit(msg);
104 JfrMonitorTryLock try_msg_lock(JfrMsg_lock);
105 if (try_msg_lock.acquired()) {
106 JfrMsg_lock->notify_all();
107 }
108 }
109
110 void JfrPostBox::synchronous_post(int msg) {
|
70 }
71
72 void JfrPostBox::post(JFR_Msg msg) {
73 const int the_message = MSGBIT(msg);
74 if (is_thread_lock_aversive()) {
75 deposit(the_message);
76 return;
77 }
78 if (!is_synchronous(the_message)) {
79 asynchronous_post(the_message);
80 return;
81 }
82 synchronous_post(the_message);
83 }
84
85 void JfrPostBox::deposit(int new_messages) {
86 while (true) {
87 const int current_msgs = Atomic::load(&_messages);
88 // OR the new message
89 const int exchange_value = current_msgs | new_messages;
90 const int result = Atomic::cmpxchg(&_messages, current_msgs, exchange_value);
91 if (result == current_msgs) {
92 return;
93 }
94 /* Some other thread just set exactly what this thread wanted */
95 if ((result & new_messages) == new_messages) {
96 return;
97 }
98 }
99 }
100
101 void JfrPostBox::asynchronous_post(int msg) {
102 assert(!is_synchronous(msg), "invariant");
103 deposit(msg);
104 JfrMonitorTryLock try_msg_lock(JfrMsg_lock);
105 if (try_msg_lock.acquired()) {
106 JfrMsg_lock->notify_all();
107 }
108 }
109
110 void JfrPostBox::synchronous_post(int msg) {
|