use auto_ptr or unique_ptr

This commit is contained in:
Michael Davidsaver
2020-10-26 15:09:13 -07:00
parent d83e3b5de1
commit db2f7d8b92
5 changed files with 40 additions and 7 deletions

View File

@@ -153,13 +153,13 @@ ca_client_context::ca_client_context ( bool enablePreemptiveCallback ) :
this->localPort = htons ( tmpAddr.ia.sin_port );
}
std::auto_ptr < CallbackGuard > pCBGuard;
ca::auto_ptr < CallbackGuard > pCBGuard;
if ( ! enablePreemptiveCallback ) {
pCBGuard.reset ( new CallbackGuard ( this->cbMutex ) );
}
// multiple steps ensure exception safety
this->pCallbackGuard = pCBGuard;
this->pCallbackGuard = PTRMOVE(pCBGuard);
}
ca_client_context::~ca_client_context ()

View File

@@ -38,6 +38,17 @@
#include "cadef.h"
#include "syncGroup.h"
namespace ca {
#if __cplusplus>=201103L
template<typename T>
using auto_ptr = std::unique_ptr<T>;
#define PTRMOVE(AUTO) std::move(AUTO)
#else
using std::auto_ptr;
#define PTRMOVE(AUTO) (AUTO)
#endif
}
struct oldChannelNotify : private cacChannelNotify {
public:
oldChannelNotify (
@@ -393,8 +404,8 @@ private:
epicsEvent ioDone;
epicsEvent callbackThreadActivityComplete;
epicsThreadId createdByThread;
std::auto_ptr < CallbackGuard > pCallbackGuard;
std::auto_ptr < cacContext > pServiceContext;
ca::auto_ptr < CallbackGuard > pCallbackGuard;
ca::auto_ptr < cacContext > pServiceContext;
caExceptionHandler * ca_exception_func;
void * ca_exception_arg;
caPrintfFunc * pVPrintfFunc;

View File

@@ -40,6 +40,17 @@
#include "repeaterSubscribeTimer.h"
#include "SearchDest.h"
namespace ca {
#if __cplusplus>=201103L
template<typename T>
using auto_ptr = std::unique_ptr<T>;
#define PTRMOVE(AUTO) std::move(AUTO)
#else
using std::auto_ptr;
#define PTRMOVE(AUTO) (AUTO)
#endif
}
extern "C" void cacRecvThreadUDP ( void *pParam );
LIBCA_API void epicsStdCall caStartRepeaterIfNotInstalled (
@@ -161,7 +172,7 @@ private:
epicsMutex & cacMutex;
const unsigned nTimers;
struct SearchArray {
typedef std::auto_ptr <searchTimer> value_type;
typedef ca::auto_ptr <searchTimer> value_type;
value_type *arr;
SearchArray(size_t n) : arr(new value_type[n]) {}
~SearchArray() { delete[] arr; }

View File

@@ -48,6 +48,17 @@
#include "db_convert.h"
#include "resourceLib.h"
namespace ca {
#if __cplusplus>=201103L
template<typename T>
using auto_ptr = std::unique_ptr<T>;
#define PTRMOVE(AUTO) std::move(AUTO)
#else
using std::auto_ptr;
#define PTRMOVE(AUTO) (AUTO)
#endif
}
extern "C" int putNotifyPut ( processNotify *ppn, notifyPutType notifyPutType );
extern "C" void putNotifyCompletion ( processNotify *ppn );
@@ -194,7 +205,7 @@ private:
epicsMutex & mutex;
epicsMutex & cbMutex;
cacContextNotify & notify;
std::auto_ptr < cacContext > pNetContext;
ca::auto_ptr < cacContext > pNetContext;
char * pStateNotifyCache;
bool isolated;

View File

@@ -71,7 +71,7 @@ dbContext::dbContext ( epicsMutex & cbMutexIn,
epicsMutex & mutexIn, cacContextNotify & notifyIn ) :
readNotifyCache ( mutexIn ), ctx ( 0 ),
stateNotifyCacheSize ( 0 ), mutex ( mutexIn ), cbMutex ( cbMutexIn ),
notify ( notifyIn ), pNetContext ( 0 ), pStateNotifyCache ( 0 ),
notify ( notifyIn ), pStateNotifyCache ( 0 ),
isolated(dbServiceIsolate)
{
}