aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/fastos
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src/vespa/fastos')
-rw-r--r--vespalib/src/vespa/fastos/CMakeLists.txt2
-rw-r--r--vespalib/src/vespa/fastos/file.cpp2
-rw-r--r--vespalib/src/vespa/fastos/file.h2
-rw-r--r--vespalib/src/vespa/fastos/file_rw_ops.cpp2
-rw-r--r--vespalib/src/vespa/fastos/file_rw_ops.h2
-rw-r--r--vespalib/src/vespa/fastos/linux_file.cpp24
-rw-r--r--vespalib/src/vespa/fastos/linux_file.h10
-rw-r--r--vespalib/src/vespa/fastos/unix_file.cpp2
-rw-r--r--vespalib/src/vespa/fastos/unix_file.h2
9 files changed, 26 insertions, 22 deletions
diff --git a/vespalib/src/vespa/fastos/CMakeLists.txt b/vespalib/src/vespa/fastos/CMakeLists.txt
index 2b7a2c3b905..02af5be5dc9 100644
--- a/vespalib/src/vespa/fastos/CMakeLists.txt
+++ b/vespalib/src/vespa/fastos/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
vespa_add_library(vespalib_fastos OBJECT
SOURCES
file.cpp
diff --git a/vespalib/src/vespa/fastos/file.cpp b/vespalib/src/vespa/fastos/file.cpp
index 0c05c1ad894..5942c9ffffc 100644
--- a/vespalib/src/vespa/fastos/file.cpp
+++ b/vespalib/src/vespa/fastos/file.cpp
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
//************************************************************************
/**
* Implementation of FastOS_FileInterface methods.
diff --git a/vespalib/src/vespa/fastos/file.h b/vespalib/src/vespa/fastos/file.h
index cd7a22a02b2..48612df4bd9 100644
--- a/vespalib/src/vespa/fastos/file.h
+++ b/vespalib/src/vespa/fastos/file.h
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
//************************************************************************
/**
* @file
diff --git a/vespalib/src/vespa/fastos/file_rw_ops.cpp b/vespalib/src/vespa/fastos/file_rw_ops.cpp
index 79fe95b21f2..7f41926deca 100644
--- a/vespalib/src/vespa/fastos/file_rw_ops.cpp
+++ b/vespalib/src/vespa/fastos/file_rw_ops.cpp
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "file_rw_ops.h"
#include <unistd.h>
diff --git a/vespalib/src/vespa/fastos/file_rw_ops.h b/vespalib/src/vespa/fastos/file_rw_ops.h
index 4f7aa6f082f..34b7da9b71e 100644
--- a/vespalib/src/vespa/fastos/file_rw_ops.h
+++ b/vespalib/src/vespa/fastos/file_rw_ops.h
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
diff --git a/vespalib/src/vespa/fastos/linux_file.cpp b/vespalib/src/vespa/fastos/linux_file.cpp
index 3344250838c..0f32aa953a8 100644
--- a/vespalib/src/vespa/fastos/linux_file.cpp
+++ b/vespalib/src/vespa/fastos/linux_file.cpp
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
******************************************************************************
* @author Oivind H. Danielsen
@@ -202,7 +202,7 @@ FastOS_Linux_File::Write2(const void *buffer, size_t length)
if (writtenNow > 0) {
written += writtenNow;
} else {
- return (written > 0) ? written : writtenNow;;
+ return (written > 0) ? written : writtenNow;
}
}
return written;
@@ -239,8 +239,8 @@ FastOS_Linux_File::internalWrite2(const void *buffer, size_t length)
}
if (writeRes > 0) {
_filePointer += writeRes;
- if (_filePointer > _cachedSize) {
- _cachedSize = _filePointer;
+ if (_filePointer > _cachedSize.load(std::memory_order_relaxed)) {
+ _cachedSize.store(_filePointer, std::memory_order_relaxed);
}
}
} else {
@@ -277,7 +277,7 @@ FastOS_Linux_File::SetSize(int64_t newSize)
bool rc = FastOS_UNIX_File::SetSize(newSize);
if (rc) {
- _cachedSize = newSize;
+ _cachedSize.store(newSize, std::memory_order_relaxed);
}
return rc;
}
@@ -334,19 +334,21 @@ FastOS_Linux_File::DirectIOPadding (int64_t offset, size_t length, size_t &padBe
if (padAfter == _directIOFileAlign) {
padAfter = 0;
}
- if (int64_t(offset+length+padAfter) > _cachedSize) {
+ int64_t fileSize = _cachedSize.load(std::memory_order_relaxed);
+ if (int64_t(offset+length+padAfter) > fileSize) {
// _cachedSize is not really trustworthy, so if we suspect it is not correct, we correct it.
// The main reason is that it will not reflect the file being extended by another filedescriptor.
- _cachedSize = getSize();
+ fileSize = getSize();
+ _cachedSize.store(fileSize, std::memory_order_relaxed);
}
if ((padAfter != 0) &&
- (static_cast<int64_t>(offset + length + padAfter) > _cachedSize) &&
- (static_cast<int64_t>(offset + length) <= _cachedSize))
+ (static_cast<int64_t>(offset + length + padAfter) > fileSize) &&
+ (static_cast<int64_t>(offset + length) <= fileSize))
{
- padAfter = _cachedSize - (offset + length);
+ padAfter = fileSize - (offset + length);
}
- if (static_cast<uint64_t>(offset + length + padAfter) <= static_cast<uint64_t>(_cachedSize)) {
+ if (static_cast<uint64_t>(offset + length + padAfter) <= static_cast<uint64_t>(fileSize)) {
return true;
}
}
diff --git a/vespalib/src/vespa/fastos/linux_file.h b/vespalib/src/vespa/fastos/linux_file.h
index 51bf2a170c7..af6e6af51af 100644
--- a/vespalib/src/vespa/fastos/linux_file.h
+++ b/vespalib/src/vespa/fastos/linux_file.h
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
******************************************************************************
* @author Oivind H. Danielsen
@@ -10,21 +10,23 @@
#pragma once
#include "unix_file.h"
+#include <atomic>
/**
* This is the Linux implementation of @ref FastOS_File. Most
* methods are inherited from @ref FastOS_UNIX_File.
*/
-class FastOS_Linux_File : public FastOS_UNIX_File
+class FastOS_Linux_File final : public FastOS_UNIX_File
{
public:
using FastOS_UNIX_File::ReadBuf;
protected:
- int64_t _cachedSize;
+ std::atomic<int64_t> _cachedSize;
int64_t _filePointer; // Only maintained/used in directio mode
public:
- FastOS_Linux_File (const char *filename = nullptr);
+ FastOS_Linux_File() : FastOS_Linux_File(nullptr) {}
+ explicit FastOS_Linux_File(const char *filename);
~FastOS_Linux_File () override;
bool GetDirectIORestrictions(size_t &memoryAlignment, size_t &transferGranularity, size_t &transferMaximum) override;
bool DirectIOPadding(int64_t offset, size_t length, size_t &padBefore, size_t &padAfter) override;
diff --git a/vespalib/src/vespa/fastos/unix_file.cpp b/vespalib/src/vespa/fastos/unix_file.cpp
index b9fe46e920d..7d1f9650c32 100644
--- a/vespalib/src/vespa/fastos/unix_file.cpp
+++ b/vespalib/src/vespa/fastos/unix_file.cpp
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
******************************************************************************
* @author Oivind H. Danielsen
diff --git a/vespalib/src/vespa/fastos/unix_file.h b/vespalib/src/vespa/fastos/unix_file.h
index 81e5de901a3..8b8d976c003 100644
--- a/vespalib/src/vespa/fastos/unix_file.h
+++ b/vespalib/src/vespa/fastos/unix_file.h
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
******************************************************************************
* @author Oivind H. Danielsen