aboutsummaryrefslogtreecommitdiffstats
path: root/fastos
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-03-07 21:36:00 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-03-07 21:36:00 +0000
commitb467cf4ff116dafe041860e26927305ac09f86c2 (patch)
treedabffed1c695eca820d21328af36197e5b8f14a4 /fastos
parent52e711ff6775a4b37aa6b13c9078ffb4906c7605 (diff)
Also gc FasOS_DynamicLibrary and RingBuffer.
Diffstat (limited to 'fastos')
-rw-r--r--fastos/src/vespa/fastos/CMakeLists.txt1
-rw-r--r--fastos/src/vespa/fastos/dynamiclibrary.h111
-rw-r--r--fastos/src/vespa/fastos/ringbuffer.h116
-rw-r--r--fastos/src/vespa/fastos/unix_dynamiclibrary.cpp128
-rw-r--r--fastos/src/vespa/fastos/unix_dynamiclibrary.h40
5 files changed, 0 insertions, 396 deletions
diff --git a/fastos/src/vespa/fastos/CMakeLists.txt b/fastos/src/vespa/fastos/CMakeLists.txt
index 623d931e999..605b1e40a38 100644
--- a/fastos/src/vespa/fastos/CMakeLists.txt
+++ b/fastos/src/vespa/fastos/CMakeLists.txt
@@ -8,7 +8,6 @@ vespa_add_library(fastos_objects OBJECT
linux_file.cpp
thread.cpp
unix_app.cpp
- unix_dynamiclibrary.cpp
unix_file.cpp
unix_thread.cpp
)
diff --git a/fastos/src/vespa/fastos/dynamiclibrary.h b/fastos/src/vespa/fastos/dynamiclibrary.h
deleted file mode 100644
index 6762ad4ac76..00000000000
--- a/fastos/src/vespa/fastos/dynamiclibrary.h
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/****************************************************************-*-C++-*-
- * @file
- * Class definitions for FastOS_DynamicLibrary.
- *
- * @author Eyvind Bernhardsen
- *
- * Creation date : 2003-07-02
- *************************************************************************/
-
-
-
-#pragma once
-
-
-#include <vespa/fastos/types.h>
-#include <string>
-
-/**
- * This class contains functionality to load, get symbols from and
- * unload dynamic libraries.
- */
-
-class FastOS_DynamicLibraryInterface
-{
-public:
- /**
- * Destructor. The destructor will close the library if it is open.
- */
- virtual ~FastOS_DynamicLibraryInterface() {}
-
- /**
- * Open (load) the library.
- * @param libname the name of the library to open
- * @return Boolean success/failure
- */
- virtual bool Open(const char *libname = nullptr) = 0;
-
- /**
- * Close (unload) the library.
- * @return Boolean success/failure
- */
- virtual bool Close() = 0;
-
- /**
- * Find the address of a symbol in the library.
- * @param symbol Name of symbol to find
- * @return Address of the symbol, or nullptr if an error has occurred
- */
- virtual void * GetSymbol(const char *symbol) const = 0;
-
- /**
- * Check if the library is open.
- * @return true if it is, false if it ain't
- */
- virtual bool IsOpen() const = 0;
-
- /**
- * Return an error message describing the last error. This is
- * currently platform-dependent, unfortunately; FastOS does not
- * normalize the error messages.
- * @return The error string if an error has occurred since the last
- * invocation, or an empty one if no error has occurred.
- */
- std::string GetLastErrorString();
-};
-
-
-# include "unix_dynamiclibrary.h"
-typedef FastOS_UNIX_DynamicLibrary FASTOS_PREFIX(DynamicLibrary);
-
-/*********************************************************************
- * Dynamic library helper macros:
- *
- * FASTOS_LOADABLE_EXPORT prefix that marks a symbol to be exported
- * FASTOS_LOADABLE_IMPORT prefix that marks a symbol to be imported
- * from a dll
- * FASTOS_LOADABLE_FACTORY macro that creates and exports a function
- * called factory. The macro takes a class
- * name as its only parameter, and the
- * factory function returns a pointer to an
- * instance of that class.
- *
- * Example usage:
- * loadableclass.h:
- * class FastOS_LoadableClass
- * {
- * public:
- * void DoSomething();
- * }
- *
- * in loadableclass.cpp:
- * FASTOS_LOADABLE_FACTORY(LoadableClass)
- *********************************************************************/
-
-
-# define FASTOS_LOADABLE_EXPORT
-
-# define FASTOS_LOADABLE_IMPORT
-
-#define FASTOS_LOADABLE_FACTORY(loadable_class) \
-extern "C" { \
- FASTOS_LOADABLE_EXPORT loadable_class *factory() { \
- return new loadable_class; \
- } \
-}
-
-// New macros to support the new gcc visibility features.
-
-#define VESPA_DLL_EXPORT __attribute__ ((visibility("default")))
-#define VESPA_DLL_LOCAL __attribute__ ((visibility("hidden")))
diff --git a/fastos/src/vespa/fastos/ringbuffer.h b/fastos/src/vespa/fastos/ringbuffer.h
deleted file mode 100644
index e442faa1921..00000000000
--- a/fastos/src/vespa/fastos/ringbuffer.h
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-struct FastOS_RingBufferData
-{
- union
- {
- unsigned int _messageSize;
- uint8_t _buffer[1];
- };
-};
-
-
-class FastOS_RingBuffer
-{
-private:
- FastOS_RingBuffer (const FastOS_RingBuffer&);
- FastOS_RingBuffer& operator=(const FastOS_RingBuffer&);
-
- bool _closed;
- FastOS_RingBufferData *_data;
- int _bufferSize;
- int _dataIndex, _dataSize;
-
- int GetWriteIndex (int offset)
- {
- return (_dataIndex + _dataSize + offset) % _bufferSize;
- }
-
- int GetReadIndex (int offset)
- {
- return (_dataIndex + offset) % _bufferSize;
- }
-
- std::mutex _mutex;
-
-public:
- void Reset ()
- {
- _dataIndex = 0;
- _dataSize = 0;
- _closed = false;
- }
-
- FastOS_RingBuffer (int bufferSize)
- : _closed(false),
- _data(0),
- _bufferSize(bufferSize),
- _dataIndex(0),
- _dataSize(0),
- _mutex()
- {
- _data = static_cast<FastOS_RingBufferData *>
- (malloc(sizeof(FastOS_RingBufferData) + bufferSize));
- Reset();
- }
-
- ~FastOS_RingBuffer ()
- {
- free(_data);
- }
-
- uint8_t *GetWritePtr (int offset=0)
- {
- return &_data->_buffer[GetWriteIndex(offset)];
- }
-
- uint8_t *GetReadPtr (int offset=0)
- {
- return &_data->_buffer[GetReadIndex(offset)];
- }
-
- void Consume (int bytes)
- {
- _dataSize -= bytes;
- _dataIndex = (_dataIndex + bytes) % _bufferSize;
- }
-
- void Produce (int bytes)
- {
- _dataSize += bytes;
- }
-
- int GetWriteSpace ()
- {
- int spaceLeft = _bufferSize - _dataSize;
- int continuousBufferLeft = _bufferSize - GetWriteIndex(0);
-
- if(continuousBufferLeft > spaceLeft)
- continuousBufferLeft = spaceLeft;
-
- return continuousBufferLeft;
- }
-
- int GetReadSpace ()
- {
- int dataLeft = _dataSize;
- int continuousBufferLeft = _bufferSize - _dataIndex;
- if(continuousBufferLeft > dataLeft)
- continuousBufferLeft = dataLeft;
- return continuousBufferLeft;
- }
-
- void Close ()
- {
- _closed = true;
- }
-
- bool GetCloseFlag ()
- {
- return _closed;
- }
-
- std::unique_lock<std::mutex> getGuard() { return std::unique_lock<std::mutex>(_mutex); }
-};
-
diff --git a/fastos/src/vespa/fastos/unix_dynamiclibrary.cpp b/fastos/src/vespa/fastos/unix_dynamiclibrary.cpp
deleted file mode 100644
index 68e00010211..00000000000
--- a/fastos/src/vespa/fastos/unix_dynamiclibrary.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/fastos/dynamiclibrary.h>
-#include <vespa/fastos/file.h>
-
-#include <dlfcn.h>
-
-namespace {
-const std::string FASTOS_DYNLIB_PREFIX("lib");
-#ifdef __APPLE__
-const std::string FASTOS_DYNLIB_SUFFIX(".dylib");
-#else
-const std::string FASTOS_DYNLIB_SUFFIX(".so");
-const std::string FASTOS_DYNLIB_SUFPREFIX(".so.");
-#endif
-
-bool hasValidSuffix(const std::string & s)
-{
- if (s.rfind(FASTOS_DYNLIB_SUFFIX) == (s.size() - FASTOS_DYNLIB_SUFFIX.size())) {
- return true;
- }
-#ifndef __APPLE__
- if (s.rfind(FASTOS_DYNLIB_SUFPREFIX) != std::string::npos) {
- return true;
- }
-#endif
- return false;
-}
-
-}
-
-void
-FastOS_UNIX_DynamicLibrary::SetLibName(const char *libname)
-{
- if (libname != nullptr) {
- _libname = libname;
- if ( ! hasValidSuffix(_libname)) {
- _libname.append(FASTOS_DYNLIB_SUFFIX);
- }
- } else {
- _libname = "";
- }
-}
-
-bool
-FastOS_UNIX_DynamicLibrary::NormalizeLibName(void)
-{
- bool returnCode = false;
- std::string::size_type pathPos = _libname.rfind(FastOS_File::GetPathSeparator()[0]);
- std::string tmp = (pathPos != std::string::npos)
- ? _libname.substr(pathPos+1)
- : _libname;
- if (tmp.find(FASTOS_DYNLIB_PREFIX) != 0) {
- tmp = FASTOS_DYNLIB_PREFIX + tmp;
- if (pathPos != std::string::npos) {
- tmp = _libname.substr(0, pathPos);
- }
- SetLibName(tmp.c_str());
- returnCode = true;
- }
-
- return returnCode;
-}
-
-bool
-FastOS_UNIX_DynamicLibrary::Close()
-{
- bool retcode = true;
-
- if (IsOpen()) {
- retcode = (dlclose(_handle) == 0);
- if (retcode)
- _handle = nullptr;
- }
-
- return retcode;
-}
-
-FastOS_UNIX_DynamicLibrary::FastOS_UNIX_DynamicLibrary(const char *libname) :
- _handle(nullptr),
- _libname("")
-{
- SetLibName(libname);
-}
-
-FastOS_UNIX_DynamicLibrary::~FastOS_UNIX_DynamicLibrary()
-{
- Close();
-}
-
-bool
-FastOS_UNIX_DynamicLibrary::Open(const char *libname)
-{
- if (! Close())
- return false;
- if (libname != nullptr) {
- SetLibName(libname);
- }
-
- _handle = dlopen(_libname.c_str(), RTLD_NOW);
-
- if (_handle == nullptr) {
- // Prepend "lib" if neccessary...
- if (NormalizeLibName()) {
- // ...try to open again if a change was made.
- _handle = dlopen(_libname.c_str(), RTLD_NOW);
- }
- }
-
- return (_handle != nullptr);
-}
-
-void *
-FastOS_UNIX_DynamicLibrary::GetSymbol(const char *symbol) const
-{
- return dlsym(_handle, symbol);
-}
-
-std::string
-FastOS_UNIX_DynamicLibrary::GetLastErrorString() const
-{
- const char *errorString = dlerror();
- std::string e;
- if (errorString != nullptr) {
- e = errorString;
- }
-
- return e;
-}
diff --git a/fastos/src/vespa/fastos/unix_dynamiclibrary.h b/fastos/src/vespa/fastos/unix_dynamiclibrary.h
deleted file mode 100644
index 4d52a68f093..00000000000
--- a/fastos/src/vespa/fastos/unix_dynamiclibrary.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/**
-*************************************************************-*C++-*-
-* @author Eyvind Bernhardsen
-* @date Creation date: 2003-07-02
-* @file
-* Class definitions for FastOS_Unix_DynamicLibrary
-*********************************************************************/
-
-
-
-#pragma once
-
-
-#include <vespa/fastos/types.h>
-
-class FastOS_UNIX_DynamicLibrary : public FastOS_DynamicLibraryInterface
-{
-private:
- FastOS_UNIX_DynamicLibrary(const FastOS_UNIX_DynamicLibrary&);
- FastOS_UNIX_DynamicLibrary& operator=(const FastOS_UNIX_DynamicLibrary&);
-
- void *_handle;
- std::string _libname;
-
-public:
- FastOS_UNIX_DynamicLibrary(const char *libname = nullptr);
- ~FastOS_UNIX_DynamicLibrary();
-
- void SetLibName(const char *libname);
- bool NormalizeLibName(void);
- bool Close() override;
- bool Open(const char *libname = nullptr) override;
- void * GetSymbol(const char *symbol) const override;
- std::string GetLastErrorString() const;
- const char * GetLibName() const { return _libname.c_str(); }
- bool IsOpen() const override { return (_handle != nullptr); }
-};
-
-