diff options
author | Alaa Eddine Elamri <alaeddine.elamri@bareos.com> | 2022-10-28 15:03:00 +0300 |
---|---|---|
committer | Andreas Rogge <andreas.rogge@bareos.com> | 2022-11-07 19:16:29 +0300 |
commit | ee9346d7c3d6ea2f6b483ed1aa8b85830ad45d60 (patch) | |
tree | 0a06236867d547a3a1895fb8cf2eb6f30ccc2076 | |
parent | 098a464acdcf74063d5412d9047a12a8cfb169eb (diff) |
vol_mgr: replace volatile with atomic for use_count_
volmgr
vol_mgr: use std::construct_at instead of placement new
-rw-r--r-- | core/src/stored/vol_mgr.cc | 4 | ||||
-rw-r--r-- | core/src/stored/vol_mgr.h | 28 |
2 files changed, 12 insertions, 20 deletions
diff --git a/core/src/stored/vol_mgr.cc b/core/src/stored/vol_mgr.cc index b49270f98..0d035e23a 100644 --- a/core/src/stored/vol_mgr.cc +++ b/core/src/stored/vol_mgr.cc @@ -261,10 +261,10 @@ static VolumeReservationItem* new_vol_item(DeviceControlRecord* dcr, const char* VolumeName) { VolumeReservationItem* vol; - VolumeReservationItem emptyVol; vol = (VolumeReservationItem*)malloc(sizeof(VolumeReservationItem)); - *vol = emptyVol; + std::construct_at(vol); + vol->vol_name = strdup(VolumeName); if (dcr) { vol->dev = dcr->dev; diff --git a/core/src/stored/vol_mgr.h b/core/src/stored/vol_mgr.h index 61f0c887b..b954b39d1 100644 --- a/core/src/stored/vol_mgr.h +++ b/core/src/stored/vol_mgr.h @@ -46,6 +46,8 @@ #ifndef BAREOS_STORED_VOL_MGR_H_ #define BAREOS_STORED_VOL_MGR_H_ +#include <atomic> + template <typename T> class dlist; namespace storagedaemon { @@ -60,12 +62,12 @@ void ReadVolWalkEnd(VolumeReservationItem* vol); // Volume reservation class -- see vol_mgr.c and reserve.c class VolumeReservationItem { - bool swapping_{false}; /**< set when swapping to another drive */ - bool in_use_{false}; /**< set when volume reserved or in use */ - bool reading_{false}; /**< set when reading */ - slot_number_t slot_{0}; /**< slot of swapping volume */ - uint32_t JobId_{0}; /**< JobId for read volumes */ - volatile int32_t use_count_{0}; /**< Use count */ + bool swapping_{false}; /**< set when swapping to another drive */ + bool in_use_{false}; /**< set when volume reserved or in use */ + bool reading_{false}; /**< set when reading */ + slot_number_t slot_{0}; /**< slot of swapping volume */ + uint32_t JobId_{0}; /**< JobId for read volumes */ + std::atomic<int32_t> use_count_{0}; /**< Use count */ pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER; /**< Vol muntex */ public: dlink<VolumeReservationItem> link; @@ -76,18 +78,8 @@ class VolumeReservationItem { void DestroyMutex() { pthread_mutex_destroy(&mutex_); } void Lock() { lock_mutex(mutex_); } void Unlock() { unlock_mutex(mutex_); } - void IncUseCount(void) - { - lock_mutex(mutex_); - use_count_++; - unlock_mutex(mutex_); - } - void DecUseCount(void) - { - lock_mutex(mutex_); - use_count_--; - unlock_mutex(mutex_); - } + void IncUseCount(void) { ++use_count_; } + void DecUseCount(void) { --use_count_; } int32_t UseCount() const { return use_count_; } bool IsSwapping() const { return swapping_; } bool is_reading() const { return reading_; } |