AllWeather

Untitled

Apr 15th, 2021
533
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. std::shared_ptr<Node> RemoveNode(std::shared_ptr<Node> remNode) {
  2.     auto remlock = std::unique_lock<std::mutex>(remNode->mutex);
  3.  
  4.     remNode->data->ShowName();
  5.  
  6.     // The one behind me should link to my next value, we're editing it so lock
  7.     if (remNode->prev) {
  8.         auto prevlock = std::unique_lock<std::mutex>(remNode->prev->mutex);
  9.         remNode->prev->next = remNode->next;
  10.     }
  11.     else { // Handle head behaviour if front of list. Only changing a ptr, lock not needed
  12.         if (head == remNode) {
  13.             if (remNode->next) {
  14.                 head = remNode->next;
  15.             }
  16.             else {
  17.                 head = nullptr;
  18.             }
  19.         }
  20.     }
  21.  
  22.     // My next value should link to the value behind me
  23.     if (remNode->next) {
  24.         auto nextlock = std::unique_lock<std::mutex>(remNode->next->mutex);
  25.         remNode->next->prev = remNode->prev;
  26.     }
  27.     else { // Handle tail behaviour if end of list
  28.         if (tail == remNode) {
  29.             if (remNode->prev) {
  30.                 tail = remNode->prev;
  31.             }
  32.             else {
  33.                 tail = nullptr;
  34.             }
  35.         }
  36.     }
  37.  
  38.     // Store next step;
  39.     std::shared_ptr<Node> tmp = remNode->next;
  40.  
  41.     // Clear up my values;
  42.     remNode->next = nullptr;
  43.     remNode->prev = nullptr;
  44.     remNode->data = nullptr;
  45.  
  46.     // No one should reference me,
  47.     // and I don't reference anyone now
  48.     // so replace to finish cleanup
  49.     return tmp;
  50. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×