mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
cleaned up some formatting etc.
This commit is contained in:
parent
56e314d724
commit
0b9a37a489
1 changed files with 24 additions and 10 deletions
|
|
@ -13,40 +13,47 @@ namespace openmc {
|
|||
// Class declarations
|
||||
//==============================================================================
|
||||
|
||||
// The SharedArray is an array that is capable of being appended to in an
|
||||
// thread safe manner by use of atomics.
|
||||
template <typename T>
|
||||
class SharedArray {
|
||||
|
||||
private:
|
||||
//==========================================================================
|
||||
// Data members
|
||||
std::unique_ptr<T[]> data_;
|
||||
int64_t size_ {0};
|
||||
int64_t capacity_ {0};
|
||||
|
||||
std::unique_ptr<T[]> data_; //!< A pointer to hold the data
|
||||
int64_t size_ {0}; //!< The current size of the shared array.
|
||||
int64_t capacity_ {0}; //!< The maximum capacity of the shared array.
|
||||
|
||||
public:
|
||||
//==========================================================================
|
||||
// Constructors
|
||||
|
||||
|
||||
// Creates an empty shared array
|
||||
SharedArray() = default;
|
||||
|
||||
|
||||
// Creates a shared array of desired capacity with zero size.
|
||||
SharedArray(int64_t capacity) : capacity_(capacity)
|
||||
{
|
||||
data_ = std::make_unique<T[]>(capacity);
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
// Methods and Accessors
|
||||
|
||||
|
||||
// Array accessor
|
||||
T& operator[](int64_t i) {return data_[i];}
|
||||
|
||||
// Allocates space for the shared array to hold the indicated capacity
|
||||
void reserve(int64_t capacity)
|
||||
{
|
||||
data_ = std::make_unique<T[]>(capacity);
|
||||
capacity_ = capacity;
|
||||
}
|
||||
|
||||
//! Increases the size of the SharedArray by one and returns an index to the
|
||||
//! last element of the array.
|
||||
// Increases the size of the SharedArray by one and returns an index to the
|
||||
// last element of the array.
|
||||
int64_t thread_safe_append()
|
||||
{
|
||||
// Atomically capture the index we want to write to
|
||||
|
|
@ -64,6 +71,8 @@ public:
|
|||
return idx;
|
||||
}
|
||||
|
||||
// Free's any space that was allocated to the shared array and resets
|
||||
// size and capacity to zero.
|
||||
void clear()
|
||||
{
|
||||
data_.reset();
|
||||
|
|
@ -71,12 +80,17 @@ public:
|
|||
capacity_ = 0;
|
||||
}
|
||||
|
||||
// Size getter
|
||||
int64_t size() {return size_;}
|
||||
|
||||
|
||||
// Sets the size of the shared array. This is useful in cases where
|
||||
// we want to write to the shared array in a non-thread safe manner.
|
||||
int64_t resize(int64_t size) {size_ = size;}
|
||||
|
||||
// Capacity getter
|
||||
int64_t capacity() {return capacity_;}
|
||||
|
||||
// Returns a pointer to the data allocation
|
||||
T* data() {return data_.get();}
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue