Compare commits

..

6 commits

Author SHA1 Message Date
8e4802501b Tweak compare_exchange_weak(...) in spin-lock 2023-12-19 13:47:19 +09:00
f28b1cb9f1 Fix invalid use of mutex in TSLQueue
Mutex was removed in favor of the custom SharedSpinLock.
2023-12-19 13:00:01 +09:00
e7a1fd18cc Don't fail on "try" fns if failed to get spinLock
In SharedSpinLock: Only fail on "try" fns after spinLock was acquired
and condition is not met.
2023-12-19 13:00:01 +09:00
748203630f Refactor shared-spin-lock to use atomic "spinLock" 2023-12-19 13:00:01 +09:00
12cc16d194 Minor refactorings 2023-12-19 13:00:01 +09:00
bc55264b6d Reland C++11 "shared_lock" with iter remove fix
On iterator remove, the iterator will trade the read lock for a write
lock, and trade back for a read lock once the remove has been completed.
2023-12-19 13:00:01 +09:00
2 changed files with 12 additions and 13 deletions

View file

@ -8,7 +8,6 @@ jobs:
doxygen-gen-and-publish: doxygen-gen-and-publish:
runs-on: archLinux runs-on: archLinux
steps: steps:
- run: git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/UDPConnection.git UDPC - run: git clone https://git.seodisparate.com/stephenseo/UDPConnection.git UDPC
- run: cd UDPC && git checkout master
- run: cd UDPC && doxygen - run: cd UDPC && doxygen
- run: rsync -r --delete UDPC/doxygen_out/html/ /srv/http/udpc_docs/ - run: rsync -rt --delete UDPC/doxygen_out/html/ /srv/http/udpc_docs/

View file

@ -27,7 +27,7 @@ UDPC::LockObj<false> UDPC::SharedSpinLock::spin_read_lock() {
bool expected; bool expected;
while (true) { while (true) {
expected = false; expected = false;
if(spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if(spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (!write) { if (!write) {
++read; ++read;
spinLock.store(false, std::memory_order_release); spinLock.store(false, std::memory_order_release);
@ -43,7 +43,7 @@ UDPC::LockObj<false> UDPC::SharedSpinLock::try_spin_read_lock() {
bool expected; bool expected;
while (true) { while (true) {
expected = false; expected = false;
if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (!write) { if (!write) {
++read; ++read;
spinLock.store(false, std::memory_order_release); spinLock.store(false, std::memory_order_release);
@ -62,7 +62,7 @@ void UDPC::SharedSpinLock::read_unlock(UDPC::Badge &&badge) {
bool expected; bool expected;
while (true) { while (true) {
expected = false; expected = false;
if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (read > 0) { if (read > 0) {
--read; --read;
badge.isValid = false; badge.isValid = false;
@ -78,7 +78,7 @@ UDPC::LockObj<true> UDPC::SharedSpinLock::spin_write_lock() {
bool expected; bool expected;
while (true) { while (true) {
expected = false; expected = false;
if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (!write && read == 0) { if (!write && read == 0) {
write = true; write = true;
spinLock.store(false, std::memory_order_release); spinLock.store(false, std::memory_order_release);
@ -94,7 +94,7 @@ UDPC::LockObj<true> UDPC::SharedSpinLock::try_spin_write_lock() {
bool expected; bool expected;
while (true) { while (true) {
expected = false; expected = false;
if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (!write && read == 0) { if (!write && read == 0) {
write = true; write = true;
spinLock.store(false, std::memory_order_release); spinLock.store(false, std::memory_order_release);
@ -113,7 +113,7 @@ void UDPC::SharedSpinLock::write_unlock(UDPC::Badge &&badge) {
bool expected; bool expected;
while(true) { while(true) {
expected = false; expected = false;
if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (write) { if (write) {
write = false; write = false;
badge.isValid = false; badge.isValid = false;
@ -130,7 +130,7 @@ UDPC::LockObj<false> UDPC::SharedSpinLock::trade_write_for_read_lock(UDPC::LockO
bool expected; bool expected;
while (true) { while (true) {
expected = false; expected = false;
if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (write && read == 0) { if (write && read == 0) {
read = 1; read = 1;
write = false; write = false;
@ -153,7 +153,7 @@ UDPC::LockObj<false> UDPC::SharedSpinLock::try_trade_write_for_read_lock(UDPC::L
bool expected; bool expected;
while (true) { while (true) {
expected = false; expected = false;
if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (write && read == 0) { if (write && read == 0) {
read = 1; read = 1;
write = false; write = false;
@ -176,7 +176,7 @@ UDPC::LockObj<true> UDPC::SharedSpinLock::trade_read_for_write_lock(UDPC::LockOb
bool expected; bool expected;
while (true) { while (true) {
expected = false; expected = false;
if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (!write && read == 1) { if (!write && read == 1) {
read = 0; read = 0;
write = true; write = true;
@ -199,7 +199,7 @@ UDPC::LockObj<true> UDPC::SharedSpinLock::try_trade_read_for_write_lock(UDPC::Lo
bool expected; bool expected;
while (true) { while (true) {
expected = false; expected = false;
if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire, std::memory_order_relaxed)) { if (spinLock.compare_exchange_weak(expected, true, std::memory_order_acquire)) {
if (!write && read == 1) { if (!write && read == 1) {
read = 0; read = 0;
write = true; write = true;