Skip to content

Commit

Permalink
refactoring lockmanager name to avoid conflicts with CLI11
Browse files Browse the repository at this point in the history
Macros `P(x)` and `V(x)` create conflicts with CLI11.
We decided to remove the macro all together and rename the 
function to be more expressive.

Anecdote: 
V stands for 'Verhoog', which can be translated as "increment" from dutch.
P stands for 'Prolaag', a madeup Dutch word of 'probeer verlaag',
which can be translated as "try to decrease".

These words were coined by Edsger W. Dijkstra.
  • Loading branch information
alaaeddineelamri committed Jul 11, 2022
1 parent db78672 commit 450669b
Show file tree
Hide file tree
Showing 52 changed files with 361 additions and 363 deletions.
12 changes: 6 additions & 6 deletions core/src/cats/mysql.cc
Expand Up @@ -146,7 +146,7 @@ bool BareosDbMysql::OpenDatabase(JobControlRecord* jcr)
my_bool reconnect = 1;
# endif

P(mutex);
lock_mutex(mutex);
if (connected_) {
retval = true;
goto bail_out;
Expand Down Expand Up @@ -214,14 +214,14 @@ bool BareosDbMysql::OpenDatabase(JobControlRecord* jcr)
retval = true;

bail_out:
V(mutex);
unlock_mutex(mutex);
return retval;
}

void BareosDbMysql::CloseDatabase(JobControlRecord* jcr)
{
if (connected_) { EndTransaction(jcr); }
P(mutex);
lock_mutex(mutex);
ref_count_--;
Dmsg3(100, "closedb ref=%d connected=%d db=%p\n", ref_count_, connected_,
db_handle_);
Expand Down Expand Up @@ -253,7 +253,7 @@ void BareosDbMysql::CloseDatabase(JobControlRecord* jcr)
db_list = NULL;
}
}
V(mutex);
unlock_mutex(mutex);
}

bool BareosDbMysql::ValidateConnection(void)
Expand Down Expand Up @@ -673,7 +673,7 @@ BareosDb* db_init_database(JobControlRecord* jcr,
Jmsg(jcr, M_FATAL, 0, _("A user name for MySQL must be supplied.\n"));
return NULL;
}
P(mutex); /* lock DB queue */
lock_mutex(mutex); /* lock DB queue */

// Look to see if DB already open
if (db_list && !mult_db_connections && !need_private) {
Expand All @@ -694,7 +694,7 @@ BareosDb* db_init_database(JobControlRecord* jcr,
need_private);

bail_out:
V(mutex);
unlock_mutex(mutex);
return mdb;
}

Expand Down
12 changes: 6 additions & 6 deletions core/src/cats/postgresql.cc
Expand Up @@ -185,7 +185,7 @@ bool BareosDbPostgresql::OpenDatabase(JobControlRecord* jcr)
int errstat;
char buf[10], *port;

P(mutex);
lock_mutex(mutex);
if (connected_) {
retval = true;
goto bail_out;
Expand Down Expand Up @@ -254,14 +254,14 @@ bool BareosDbPostgresql::OpenDatabase(JobControlRecord* jcr)
retval = true;

bail_out:
V(mutex);
unlock_mutex(mutex);
return retval;
}

void BareosDbPostgresql::CloseDatabase(JobControlRecord* jcr)
{
if (connected_) { EndTransaction(jcr); }
P(mutex);
lock_mutex(mutex);
ref_count_--;
if (ref_count_ == 0) {
if (connected_) { SqlFreeResult(); }
Expand Down Expand Up @@ -289,7 +289,7 @@ void BareosDbPostgresql::CloseDatabase(JobControlRecord* jcr)
db_list = NULL;
}
}
V(mutex);
unlock_mutex(mutex);
}

bool BareosDbPostgresql::ValidateConnection(void)
Expand Down Expand Up @@ -939,7 +939,7 @@ BareosDb* db_init_database(JobControlRecord* jcr,
Jmsg(jcr, M_FATAL, 0, _("A user name for PostgreSQL must be supplied.\n"));
return NULL;
}
P(mutex); /* lock DB queue */
lock_mutex(mutex); /* lock DB queue */

// Look to see if DB already open
if (db_list && !mult_db_connections && !need_private) {
Expand All @@ -960,7 +960,7 @@ BareosDb* db_init_database(JobControlRecord* jcr,
try_reconnect, exit_on_fatal, need_private);

bail_out:
V(mutex);
unlock_mutex(mutex);
return mdb;
}

Expand Down
12 changes: 6 additions & 6 deletions core/src/cats/sqlite.cc
Expand Up @@ -146,7 +146,7 @@ bool BareosDbSqlite::OpenDatabase(JobControlRecord* jcr)
int errstat;
int retry = 0;

P(mutex);
lock_mutex(mutex);
if (connected_) {
retval = true;
goto bail_out;
Expand Down Expand Up @@ -207,14 +207,14 @@ bool BareosDbSqlite::OpenDatabase(JobControlRecord* jcr)
retval = true;

bail_out:
V(mutex);
unlock_mutex(mutex);
return retval;
}

void BareosDbSqlite::CloseDatabase(JobControlRecord* jcr)
{
if (connected_) { EndTransaction(jcr); }
P(mutex);
lock_mutex(mutex);
ref_count_--;
if (ref_count_ == 0) {
if (connected_) { SqlFreeResult(); }
Expand All @@ -237,7 +237,7 @@ void BareosDbSqlite::CloseDatabase(JobControlRecord* jcr)
db_list = NULL;
}
}
V(mutex);
unlock_mutex(mutex);
}

bool BareosDbSqlite::ValidateConnection(void)
Expand Down Expand Up @@ -660,7 +660,7 @@ BareosDb* db_init_database(JobControlRecord* jcr,
{
BareosDbSqlite* mdb = NULL;

P(mutex); /* lock DB queue */
lock_mutex(mutex); /* lock DB queue */

// Look to see if DB already open
if (db_list && !mult_db_connections && !need_private) {
Expand All @@ -681,7 +681,7 @@ BareosDb* db_init_database(JobControlRecord* jcr,
need_private);

bail_out:
V(mutex);
unlock_mutex(mutex);
return mdb;
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/bsr.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2002-2010 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -250,9 +250,9 @@ static void MakeUniqueRestoreFilename(UaContext* ua, PoolMem& fname)
Mmsg(fname, "%s", ua->argv[i]);
jcr->impl->unlink_bsr = false;
} else {
P(mutex);
lock_mutex(mutex);
uniq++;
V(mutex);
unlock_mutex(mutex);
Mmsg(fname, "%s/%s.restore.%u.bsr", working_directory, my_name, uniq);
jcr->impl->unlink_bsr = true;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/dir_plugins.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -794,7 +794,7 @@ static bRC bareosGetInstanceCount(PluginContext* ctx, int* ret)

if (!IsCtxGood(ctx, jcr, bctx)) { goto bail_out; }

P(mutex);
lock_mutex(mutex);

cnt = 0;
foreach_jcr (njcr) {
Expand All @@ -806,7 +806,7 @@ static bRC bareosGetInstanceCount(PluginContext* ctx, int* ret)
}
endeach_jcr(njcr);

V(mutex);
unlock_mutex(mutex);

*ret = cnt;
retval = bRC_OK;
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/job.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -1455,7 +1455,7 @@ void CreateUniqueJobName(JobControlRecord* jcr, const char* base_name)
/* Guarantee unique start time -- maximum one per second, and
* thus unique Job Name
*/
P(mutex); /* lock creation of jobs */
lock_mutex(mutex); /* lock creation of jobs */
seq++;
if (seq > 59) { /* wrap as if it is seconds */
seq = 0;
Expand All @@ -1466,7 +1466,7 @@ void CreateUniqueJobName(JobControlRecord* jcr, const char* base_name)
}
lseq = seq;
last_start_time = now;
V(mutex); /* allow creation of jobs */
unlock_mutex(mutex); /* allow creation of jobs */
jcr->start_time = now;

/*
Expand Down

0 comments on commit 450669b

Please sign in to comment.