summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2017-10-30 12:31:24 +0000
committerTor Egge <Tor.Egge@oath.com>2017-10-30 12:31:24 +0000
commit1db555a020b946eb9d380ef0a74960265267ec48 (patch)
tree555d460006eff035340fe6673b39a76950b0e2c0
parentdc8cf61d81f44784620d0c5881b7e833e619fb1f (diff)
Use std::mutex instead of FastOS_Mutex to protect socket event objects.
-rw-r--r--fastos/src/vespa/fastos/socketevent.cpp18
-rw-r--r--fastos/src/vespa/fastos/socketevent.h4
2 files changed, 8 insertions, 14 deletions
diff --git a/fastos/src/vespa/fastos/socketevent.cpp b/fastos/src/vespa/fastos/socketevent.cpp
index a80cb015782..5e542390a53 100644
--- a/fastos/src/vespa/fastos/socketevent.cpp
+++ b/fastos/src/vespa/fastos/socketevent.cpp
@@ -7,7 +7,7 @@
FastOS_SocketEventObjects *FastOS_SocketEventObjects::_objects = nullptr;
-FastOS_Mutex FastOS_SocketEventObjects::_listMutex;
+std::mutex FastOS_SocketEventObjects::_listMutex;
int FastOS_SocketEventObjects::_objectCount = 0;
bool FastOS_SocketEventObjects::_initialized = false;
@@ -55,12 +55,12 @@ bool FastOS_SocketEvent::HandleWakeUp ()
FastOS_SocketEventObjects *FastOS_SocketEventObjects::ObtainObject (FastOS_SocketEvent *event)
{
FastOS_SocketEventObjects *node;
- _listMutex.Lock();
+ std::unique_lock<std::mutex> guard(_listMutex);
if(_objects == nullptr)
{
_objectCount++;
- _listMutex.Unlock();
+ guard.unlock();
node = new FastOS_SocketEventObjects(event);
node->_next = nullptr;
@@ -70,8 +70,6 @@ FastOS_SocketEventObjects *FastOS_SocketEventObjects::ObtainObject (FastOS_Socke
node = _objects;
_objects = node->_next;
node->_next = nullptr;
-
- _listMutex.Unlock();
}
return node;
@@ -81,7 +79,7 @@ void FastOS_SocketEventObjects::ReleaseObject (FastOS_SocketEventObjects *node)
{
if (node != nullptr)
node->ReleasedCleanup();
- _listMutex.Lock();
+ std::lock_guard<std::mutex> guard(_listMutex);
if (_initialized) {
node->_next = _objects;
@@ -90,8 +88,6 @@ void FastOS_SocketEventObjects::ReleaseObject (FastOS_SocketEventObjects *node)
delete node;
_objectCount--;
}
-
- _listMutex.Unlock();
}
@@ -213,15 +209,14 @@ FastOS_SocketEvent::epollFini()
void
FastOS_SocketEventObjects::InitializeClass(void)
{
- _listMutex.Lock();
+ std::lock_guard<std::mutex> guard(_listMutex);
_initialized = true;
- _listMutex.Unlock();
}
void FastOS_SocketEventObjects::ClassCleanup(void)
{
- _listMutex.Lock();
+ std::lock_guard<std::mutex> guard(_listMutex);
_initialized = false;
for (;;)
{
@@ -236,7 +231,6 @@ void FastOS_SocketEventObjects::ClassCleanup(void)
_objectCount--;
}
}
- _listMutex.Unlock();
}
diff --git a/fastos/src/vespa/fastos/socketevent.h b/fastos/src/vespa/fastos/socketevent.h
index 5e457908ace..267f948caf9 100644
--- a/fastos/src/vespa/fastos/socketevent.h
+++ b/fastos/src/vespa/fastos/socketevent.h
@@ -3,11 +3,11 @@
#pragma once
#include "types.h"
-#include "mutex.h"
#include <poll.h>
#include <sys/epoll.h>
#include <vector>
+#include <mutex>
class FastOS_IOEvent
{
@@ -25,7 +25,7 @@ private:
FastOS_SocketEventObjects(const FastOS_SocketEventObjects&);
FastOS_SocketEventObjects& operator=(const FastOS_SocketEventObjects&);
- static FastOS_Mutex _listMutex;
+ static std::mutex _listMutex;
static int _objectCount;
static bool _initialized;