summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2017-10-30 14:48:56 +0000
committerTor Egge <Tor.Egge@oath.com>2017-10-30 14:48:56 +0000
commit10b63f93aeba3f62b8360e422abc2116b76d7b40 (patch)
tree27b70f45553113d18ca1422e0f220e35cf915004
parentb4b5240356b6fa324a33e893c07829cf6ecdb65e (diff)
Remove FastOS_Mutex and FastOS_Cond.
-rw-r--r--fastos/src/vespa/fastos/CMakeLists.txt2
-rw-r--r--fastos/src/vespa/fastos/cond.h165
-rw-r--r--fastos/src/vespa/fastos/mutex.h64
-rw-r--r--fastos/src/vespa/fastos/unix_cond.cpp49
-rw-r--r--fastos/src/vespa/fastos/unix_cond.h42
-rw-r--r--fastos/src/vespa/fastos/unix_mutex.cpp18
-rw-r--r--fastos/src/vespa/fastos/unix_mutex.h44
7 files changed, 0 insertions, 384 deletions
diff --git a/fastos/src/vespa/fastos/CMakeLists.txt b/fastos/src/vespa/fastos/CMakeLists.txt
index 2a0ff2d370a..f98e5b8d97b 100644
--- a/fastos/src/vespa/fastos/CMakeLists.txt
+++ b/fastos/src/vespa/fastos/CMakeLists.txt
@@ -13,11 +13,9 @@ vespa_add_library(fastos_objects OBJECT
time.cpp
timestamp.cpp
unix_app.cpp
- unix_cond.cpp
unix_dynamiclibrary.cpp
unix_file.cpp
unix_ipc.cpp
- unix_mutex.cpp
unix_process.cpp
unix_socket.cpp
unix_thread.cpp
diff --git a/fastos/src/vespa/fastos/cond.h b/fastos/src/vespa/fastos/cond.h
deleted file mode 100644
index c9405728223..00000000000
--- a/fastos/src/vespa/fastos/cond.h
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-//************************************************************************
-/**
- * @file
- * Class definitions for FastOS_CondInterface and FastOS_BoolCond.
- *
- * @author Div, Oivind H. Danielsen
- */
-
-#pragma once
-
-#include "mutex.h"
-
-
-/**
- * This class implements a synchronization mechanism used by threads to wait
- * until a condition expression involving shared data attains a particular state.
- *
- * Condition variables provide a different type of synchronization
- * than locking mechanisms like mutexes. For instance, a mutex is used
- * to cause other threads to wait while the thread holding the mutex
- * executes code in a critical section. In contrast, a condition
- * variable is typically used by a thread to make itself wait until an
- * expression involving shared data attains a particular state.
- */
-class FastOS_CondInterface : public FastOS_Mutex
-{
-public:
- FastOS_CondInterface(void) : FastOS_Mutex() { }
-
- virtual ~FastOS_CondInterface () {}
-
- /**
- * Wait for the condition to be signalled. If the wait takes
- * longer than [milliseconds] ms, the wait is aborted and false
- * is returned.
- * @param milliseconds Max time to wait.
- * @return Boolean success/failure
- */
- virtual bool TimedWait (int milliseconds) = 0;
-
- /**
- * Wait for the condition to be signalled.
- */
- virtual void Wait (void)=0;
-
- /**
- * Send a signal to one thread waiting on the condition (if any).
- */
- virtual void Signal (void)=0;
-
- /**
- * Send a signal to all threads waiting on the condition.
- */
- virtual void Broadcast (void)=0;
-};
-
-#include <vespa/fastos/unix_cond.h>
-typedef FastOS_UNIX_Cond FASTOS_PREFIX(Cond);
-
-/**
- * This class implements a condition variable with a boolean
- * value.
- */
-class FastOS_BoolCond : public FastOS_Cond
-{
- bool _busy;
-
-public:
- /**
- * Constructor. Initially the boolean variable is
- * set to non-busy.
- */
- FastOS_BoolCond(void) : _busy(false) { }
-
- ~FastOS_BoolCond(void) { }
-
- /**
- * If the variable is busy, wait for it to be non-busy,
- * then set the variable to busy. */
- void SetBusy(void)
- {
- Lock();
-
- while (_busy == true)
- Wait();
-
- _busy = true;
- Unlock();
- }
-
- /**
- * If the variable is busy, wait until it is no longer busy.
- * If it was non-busy to begin with, no wait is performed.
- */
- void WaitBusy(void)
- {
- Lock();
-
- while (_busy == true)
- Wait();
-
- Unlock();
- }
-
- /**
- * If the variable is busy, wait until it is no longer busy or a
- * timeout occurs. If it was non-busy to begin with, no wait is
- * performed.
- * @param ms Time to wait
- * @return True=non-busy, false=timeout
- */
- bool TimedWaitBusy(int ms)
- {
- bool success = true;
-
- Lock();
- if (_busy == true) {
- success = TimedWait(ms);
- }
- Unlock();
-
- return success;
- }
-
- /**
- * Return busy status.
- * @return True=busy, false=non-busy
- */
- bool PollBusy (void)
- {
- bool rc;
- Lock();
- rc = _busy;
- Unlock();
- return rc;
- }
-
- /**
- * Set the variable to non-busy, and signal one thread
- * waiting (if there are any).
- * (if any).
- */
- void ClearBusy(void)
- {
- Lock();
- _busy = false;
- Signal();
- Unlock();
- }
-
- /**
- * Set the variable to non-busy, and broadcast to all
- * threads waiting (if there are any).
- */
- void ClearBusyBroadcast(void)
- {
- Lock();
- _busy = false;
- Broadcast();
- Unlock();
- }
-};
-
-
diff --git a/fastos/src/vespa/fastos/mutex.h b/fastos/src/vespa/fastos/mutex.h
deleted file mode 100644
index 530e8d007bc..00000000000
--- a/fastos/src/vespa/fastos/mutex.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-//************************************************************************
-/**
- * @file
- * Class definition for FastOS_Mutex.
- *
- * @author Div, Oivind H. Danielsen
- */
-
-#pragma once
-
-#include "types.h"
-
-/**
- * This class defines a mutual-exclusion object.
- *
- * Facilitates synchronized access to mutual-exclusion zones in the program.
- * Before entering code sections where only a single thread at the time can
- * operate, use @ref Lock(). If another thread is holding the lock at the
- * time, the calling thread will sleep until the current holder of the mutex
- * is through using it.
- *
- * Use @ref Unlock() to release the mutex lock. This will allow other threads
- * to obtain the lock.
- */
-
-class FastOS_MutexInterface
-{
-public:
- /**
- * Destructor
- */
- virtual ~FastOS_MutexInterface () {}
-
- /**
- * Obtain an exclusive lock on the mutex. The result of a recursive lock
- * is currently undefined. The caller should assume this will result
- * in a deadlock situation.
- * A recursive lock occurs when a thread, currently owning the lock,
- * attempts to lock the mutex a second time.
- *
- * Use @ref Unlock() to unlock the mutex when done.
- */
- virtual void Lock ()=0;
-
- /**
- * Try to obtain an exclusive lock on the mutex. If a lock cannot be
- * obtained right away, the method will return false. There will
- * be no blocking/waiting for the mutex lock to be available. If
- * the mutex was locked in the attempt, true is returned.
- * @return Boolean success/failure
- */
- virtual bool TryLock ()=0;
-
- /**
- * Unlock a locked mutex. The result of unlocking a mutex not already
- * locked by the calling thread is undefined.
- */
- virtual void Unlock ()=0;
-};
-
-#include "unix_mutex.h"
-typedef FastOS_UNIX_Mutex FASTOS_PREFIX(Mutex);
-
diff --git a/fastos/src/vespa/fastos/unix_cond.cpp b/fastos/src/vespa/fastos/unix_cond.cpp
deleted file mode 100644
index 5eb1f5b0218..00000000000
--- a/fastos/src/vespa/fastos/unix_cond.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "cond.h"
-#include <sys/time.h>
-#include <cstdint>
-
-FastOS_UNIX_Cond::FastOS_UNIX_Cond(void)
- : FastOS_CondInterface(),
- _cond()
-{
- pthread_cond_init(&_cond, nullptr);
-}
-
-FastOS_UNIX_Cond::~FastOS_UNIX_Cond(void)
-{
- pthread_cond_destroy(&_cond);
-}
-
-void
-FastOS_UNIX_Cond::Wait(void)
-{
- pthread_cond_wait(&_cond, &_mutex);
-}
-
-bool
-FastOS_UNIX_Cond::TimedWait(int milliseconds)
-{
-
- struct timeval currentTime;
- struct timespec absTime;
- int error;
-
- gettimeofday(&currentTime, nullptr);
-
- int64_t ns = (static_cast<int64_t>(currentTime.tv_sec) *
- static_cast<int64_t>(1000 * 1000 * 1000) +
- static_cast<int64_t>(currentTime.tv_usec) *
- static_cast<int64_t>(1000) +
- static_cast<int64_t>(milliseconds) *
- static_cast<int64_t>(1000 * 1000));
-
- absTime.tv_sec = static_cast<int>
- (ns / static_cast<int64_t>(1000 * 1000 * 1000));
- absTime.tv_nsec = static_cast<int>
- (ns % static_cast<int64_t>(1000 * 1000 * 1000));
-
- error = pthread_cond_timedwait(&_cond, &_mutex, &absTime);
- return error == 0;
-}
diff --git a/fastos/src/vespa/fastos/unix_cond.h b/fastos/src/vespa/fastos/unix_cond.h
deleted file mode 100644
index 7367d812959..00000000000
--- a/fastos/src/vespa/fastos/unix_cond.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-//************************************************************************
-/**
- * Class definition and implementation for FastOS_UNIX_Cond.
- *
- * @author Div, Oivind H. Danielsen
- */
-
-#pragma once
-
-#include <vespa/fastos/cond.h>
-
-
-class FastOS_UNIX_Cond : public FastOS_CondInterface
-{
-private:
- FastOS_UNIX_Cond(const FastOS_UNIX_Cond &);
- FastOS_UNIX_Cond& operator=(const FastOS_UNIX_Cond &);
-
- pthread_cond_t _cond;
-
-public:
- FastOS_UNIX_Cond ();
-
- ~FastOS_UNIX_Cond();
-
- void Wait() override;
-
- bool TimedWait(int milliseconds) override;
-
- void Signal() override
- {
- pthread_cond_signal(&_cond);
- }
-
- void Broadcast() override
- {
- pthread_cond_broadcast(&_cond);
- }
-};
-
-
diff --git a/fastos/src/vespa/fastos/unix_mutex.cpp b/fastos/src/vespa/fastos/unix_mutex.cpp
deleted file mode 100644
index 535a39ce592..00000000000
--- a/fastos/src/vespa/fastos/unix_mutex.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "mutex.h"
-#include <cassert>
-
-FastOS_UNIX_Mutex::FastOS_UNIX_Mutex(void)
- : FastOS_MutexInterface(),
- _mutex()
-{
- int error = pthread_mutex_init(&_mutex, nullptr);
- assert(error == 0);
- (void) error;
-}
-
-FastOS_UNIX_Mutex::~FastOS_UNIX_Mutex(void)
-{
- pthread_mutex_destroy(&_mutex);
-}
diff --git a/fastos/src/vespa/fastos/unix_mutex.h b/fastos/src/vespa/fastos/unix_mutex.h
deleted file mode 100644
index 30150bc1590..00000000000
--- a/fastos/src/vespa/fastos/unix_mutex.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/**
-******************************************************************************
-* @author Oivind H. Danielsen
-* @date Creation date: 2000-02-02
-* @file
-* Class definition and implementation for FastOS_UNIX_Mutex
-*****************************************************************************/
-
-
-
-#pragma once
-
-
-#include "mutex.h"
-#include <pthread.h>
-
-class FastOS_UNIX_Mutex : public FastOS_MutexInterface
-{
-private:
- FastOS_UNIX_Mutex(const FastOS_UNIX_Mutex &other);
- FastOS_UNIX_Mutex & operator = (const FastOS_UNIX_Mutex &other);
-protected:
- pthread_mutex_t _mutex;
-
-public:
- FastOS_UNIX_Mutex();
-
- ~FastOS_UNIX_Mutex();
-
- bool TryLock () override {
- return pthread_mutex_trylock(&_mutex) == 0;
- }
-
- void Lock() override {
- pthread_mutex_lock(&_mutex);
- }
-
- void Unlock() override {
- pthread_mutex_unlock(&_mutex);
- }
-};
-
-