Skip to content

Commit

Permalink
use make_unique if possible
Browse files Browse the repository at this point in the history
change code style after review comments
  • Loading branch information
ClausKlein committed Jun 2, 2021
1 parent 07fa228 commit 2c7d1c0
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 55 deletions.
21 changes: 16 additions & 5 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
---
# This configuration requires clang-format version 12.0 or newer.
# This configuration requires clang-format version v12.0 or newer.
BasedOnStyle: Mozilla
AlignOperands: false
#
AlignConsecutiveDeclarations: Consecutive
AlignEscapedNewlines: Left
AlignOperands: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
# AlwaysBreakAfterDefinitionReturnType: TopLevel
# AlwaysBreakAfterReturnType: TopLevelDefinitions
BinPackArguments: false
BinPackParameters: false
# parameters will either all be on the same line or will have one line each.
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Never
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
Expand All @@ -29,10 +36,14 @@ BraceWrapping:
SplitEmptyRecord: true
SplitEmptyNamespace: true
# based on BreakBeforeBraces: GNU
ColumnLimit: 79
#XXX IndentAccessModifiers: true
ColumnLimit: 123 # MAYBE up to 160
#
# XXX v13.0 only IndentAccessModifiers: true
#
IndentPPDirectives: AfterHash
SortUsingDeclarations: false
SpaceAfterTemplateKeyword: true
SpaceAfterLogicalNot: true
SpaceBeforeParens: Always
SpaceInEmptyBlock: false
...
5 changes: 1 addition & 4 deletions TAO/tests/Bug_3251_Regression/DllOrb.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ class bug_3251_Export DllOrb : public ACE_Task_Base
DllOrb (void);
virtual ~DllOrb (void);

CORBA::ORB_ptr orb () const
{
return CORBA::ORB::_duplicate (mv_orb_.in ());
}
CORBA::ORB_ptr orb () const { return CORBA::ORB::_duplicate (mv_orb_.in ()); }

virtual int init (int argc, ACE_TCHAR* argv[]);

Expand Down
16 changes: 8 additions & 8 deletions TAO/tests/Bug_3542_Regression/DllOrb.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
#include "ace/Task.h"
#include "tao/ORB.h"

#include "tao/PortableServer/PortableServer.h"
#include "bug_3542_export.h"
#include "tao/PortableServer/PortableServer.h"

#include <memory>

class bug_3542_Export DllOrb: public ACE_Task_Base
class bug_3542_Export DllOrb : public ACE_Task_Base
{
public:
DllOrb (void);
virtual ~DllOrb (void);

CORBA::ORB_ptr orb () const { return CORBA::ORB::_duplicate(mv_orb_.in()); }
CORBA::ORB_ptr orb () const { return CORBA::ORB::_duplicate (mv_orb_.in ()); }

virtual int init (int argc, ACE_TCHAR *argv[]);
virtual int init (int argc, ACE_TCHAR* argv[]);

virtual int fini ();

virtual int svc ();

private:
std::unique_ptr < ACE_Thread_Barrier > ma_barrier_;
CORBA::ORB_var mv_orb_;
PortableServer::POA_var mv_rootPOA_;
PortableServer::POAManager_var mv_poaManager_;
std::unique_ptr<ACE_Thread_Barrier> ma_barrier_;
CORBA::ORB_var mv_orb_;
PortableServer::POA_var mv_rootPOA_;
PortableServer::POAManager_var mv_poaManager_;
};

ACE_FACTORY_DECLARE (bug_3542, DllOrb)
Expand Down
6 changes: 4 additions & 2 deletions TAO/tests/Oneway_Send_Timeouts/ORB_Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ class ORB_Task : public ACE_Task_Base
ORB_Task (CORBA::ORB_ptr orb)
: orb_ (CORBA::ORB::_duplicate (orb))
{
if (CORBA::is_nil (orb_.in ()) == 1) {
if (CORBA::is_nil (orb_.in ()) == 1)
{
ACE_ERROR ((LM_ERROR, "ORB_Task> Ctr> Orb is NULL\n"));
}
};

virtual int svc ()
{
if (CORBA::is_nil (orb_.in ()) == 0) {
if (CORBA::is_nil (orb_.in ()) == 0)
{
orb_->run ();
}

Expand Down
24 changes: 17 additions & 7 deletions TAO/tests/Oneway_Send_Timeouts/Server_Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,30 @@ class Server_Task : public ACE_Task_Base
bool initializer = false;
{
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_, -1);
if (server_.get () == 0) {
if (server_.get () == 0)
{
ACE_ARGV my_args (args_.c_str ());

// Initialize Server ORB in new thread
// server_ = std::make_unique<Server>(my_args.argc(), my_args.argv());

#ifdef ACE_HAS_CPP14
server_ = std::make_unique<Server> (my_args.argc (), my_args.argv ());
#else
server_.reset (new Server(my_args.argc (), my_args.argv ());
ACE_ASSERT (server_.get () != 0);
#endif

ACE_ASSERT (server_);
initializer = true;
}
}

if (initializer) {
if (initializer)
{
server_->run (false);
this->force_shutdown (); // servant thread is responsible for shutdown
}
else {
else
{
server_->run (true);
}

Expand All @@ -45,7 +53,8 @@ class Server_Task : public ACE_Task_Base

bool ready ()
{
if (server_.get () != 0) {
if (server_.get () != 0)
{
return server_->init_;
}

Expand All @@ -54,7 +63,8 @@ class Server_Task : public ACE_Task_Base

void force_shutdown ()
{
if (server_.get () != 0) {
if (server_.get () != 0)
{
server_->shutdown ();
}
}
Expand Down
70 changes: 41 additions & 29 deletions TAO/tests/Oneway_Send_Timeouts/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,33 @@ class MyMain
bool shutdown_;
};

void
MyMain::print_usage ()
void MyMain::print_usage ()
{}

bool
MyMain::init_server (const ACE_TCHAR* args)
bool MyMain::init_server (const ACE_TCHAR* args)
{
std::string my_args (ACE_TEXT_ALWAYS_CHAR (args));
// main thread and extra thread for backdoor operations
int thread_pool = 2;

// TODO: server_ = std::make_unique<Server> (my_args);
#ifdef ACE_HAS_CPP14
server_ = std::make_unique<Server> (my_args);
#else
server_.reset (new Server (my_args);
ACE_ASSERT (server_task_.get () != 0);
#endif

server_task_->activate (THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED,
thread_pool);
ACE_ASSERT (server_task_);

server_task_->activate (THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED, thread_pool);

int duration = 4; // wait 3 seconds for initialization
ACE_Time_Value current = ACE_High_Res_Timer::gettimeofday_hr ();
ACE_Time_Value timeout = current + ACE_Time_Value (duration);

while (current < timeout) {
if (server_task_->ready ()) {
while (current < timeout)
{
if (server_task_->ready ())
{
break;
}
ACE_Time_Value sleep_time;
Expand All @@ -60,7 +63,8 @@ MyMain::init_server (const ACE_TCHAR* args)
current += sleep_time;
}

if (!server_task_->ready ()) {
if (! server_task_->ready ())
{
server_task_->force_shutdown ();
server_task_->wait ();
server_task_.reset ();
Expand All @@ -70,18 +74,20 @@ MyMain::init_server (const ACE_TCHAR* args)
return true;
}

bool
MyMain::init_client (const ACE_TCHAR* args)
bool MyMain::init_client (const ACE_TCHAR* args)
{
std::string my_args (ACE_TEXT_ALWAYS_CHAR (args));
int thread_pool = 1;

// TODO: client_task_ = std::make_unique<Client_Task> (my_args);
#ifdef ACE_HAS_CPP14
client_task_ = std::make_unique<Client_Task> (my_args);
#else
client_task_.reset (new Client_Task (my_args);
ACE_ASSERT (client_task_.get () != 0);
#endif

ACE_ASSERT (client_task_);

client_task_->activate (THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED,
thread_pool);
client_task_->activate (THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED, thread_pool);

return true;
}
Expand All @@ -91,35 +97,41 @@ MyMain::MyMain (int argc, ACE_TCHAR* argv[])
, shutdown_ (false)
{
argc--;
for (int p = 1; p <= argc; p++) {
if (ACE_OS::strcmp (argv[p], ACE_TEXT ("-?")) == 0) {
for (int p = 1; p <= argc; p++)
{
if (ACE_OS::strcmp (argv[p], ACE_TEXT ("-?")) == 0)
{
print_usage ();
return;
}

if (ACE_OS::strcasecmp (argv[p], ACE_TEXT ("-s")) == 0) {
if (ACE_OS::strcasecmp (argv[p], ACE_TEXT ("-s")) == 0)
{
const ACE_TCHAR* s_args = (((p + 1) <= argc) ? argv[p + 1] : 0);
s_init_ = this->init_server (s_args);
p++;
}
else if (ACE_OS::strcasecmp (argv[p], ACE_TEXT ("-c")) == 0) {
else if (ACE_OS::strcasecmp (argv[p], ACE_TEXT ("-c")) == 0)
{
const ACE_TCHAR* s_args = (((p + 1) <= argc) ? argv[p + 1] : 0);
if (s_init_) {
if (s_init_)
{
this->init_client (s_args);
}
p++;
}
}
}

void
MyMain::run ()
void MyMain::run ()
{
if (server_task_.get () != 0) {
if (server_task_.get () != 0)
{
server_task_->wait ();
}

if (client_task_.get () != 0) {
if (client_task_.get () != 0)
{
client_task_->wait ();
}

Expand All @@ -128,13 +140,13 @@ MyMain::run ()

MyMain::~MyMain ()
{
if (!shutdown_) {
if (! shutdown_)
{
this->run ();
}
}

int
ACE_TMAIN (int argc, ACE_TCHAR* argv[])
int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
MyMain my_main (argc, argv);

Expand Down

0 comments on commit 2c7d1c0

Please sign in to comment.