Skip to content

Commit

Permalink
jcr: removed redundant or wrong calls to pthread_setspecific
Browse files Browse the repository at this point in the history
- refactored SetJcrInTsd
- removed redundant or not needful calls to SetJcrInTsd
  • Loading branch information
franku committed Dec 18, 2018
1 parent 3e3364a commit 9ec77b1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions core/src/dird/dird.cc
Expand Up @@ -380,7 +380,7 @@ int main (int argc, char *argv[])
GetFirstPortHostOrder(me->DIRaddrs));
}

SetJcrInTsd(INVALID_JCR);
/* SetJcrInTsd(INVALID_JCR); */
SetThreadConcurrency(me->MaxConcurrentJobs * 2 +
4 /* UA */ + 5 /* sched+watchdog+jobsvr+misc */);
LmgrInitThread(); /* initialize the lockmanager stack */
Expand Down Expand Up @@ -449,7 +449,7 @@ int main (int argc, char *argv[])
while ((jcr = wait_for_next_job(runjob))) {
RunJob(jcr); /* run job */
FreeJcr(jcr); /* release jcr */
SetJcrInTsd(INVALID_JCR);
/* SetJcrInTsd(INVALID_JCR); */
if (runjob) { /* command line, run a single job? */
break; /* yes, Terminate */
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/jobq.cc
Expand Up @@ -169,7 +169,7 @@ extern "C" void *sched_wait(void *arg)
JobControlRecord *jcr = ((wait_pkt *)arg)->jcr;
jobq_t *jq = ((wait_pkt *)arg)->jq;

SetJcrInTsd(INVALID_JCR);
/* SetJcrInTsd(INVALID_JCR); */
Dmsg0(2300, "Enter sched_wait.\n");
free(arg);
time_t wtime = jcr->sched_time - time(NULL);
Expand Down Expand Up @@ -387,7 +387,7 @@ extern "C" void *jobq_server(void *arg)
bool timedout = false;
bool work = true;

SetJcrInTsd(INVALID_JCR);
/* SetJcrInTsd(INVALID_JCR); */
Dmsg0(2300, "Start jobq_server\n");
P(jq->mutex);

Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/socket_server.cc
Expand Up @@ -122,7 +122,7 @@ static void *HandleConnectionRequest(ConfigurationParser *config, void *arg)

extern "C" void *connect_thread(void *arg)
{
SetJcrInTsd(INVALID_JCR);
/* SetJcrInTsd(INVALID_JCR); */

/*
* Permit MaxConnections connections.
Expand Down
1 change: 0 additions & 1 deletion core/src/lib/bsock.cc
Expand Up @@ -371,7 +371,6 @@ bool BareosSocket::TwoWayAuthenticate(JobControlRecord *jcr,
bool initiated_by_remote)
{
bool auth_success = false;

if (jcr && JobCanceled(jcr)) {
Dmsg0(debuglevel, "Failed, because job is canceled.\n");
} else if (password.encoding != p_encoding_md5) {
Expand Down
8 changes: 5 additions & 3 deletions core/src/lib/jcr.cc
Expand Up @@ -667,9 +667,11 @@ void RemoveJcrFromTsd(JobControlRecord *jcr)
*/
void SetJcrInTsd(JobControlRecord *jcr)
{
int status;

status = pthread_setspecific(jcr_key, (void *)jcr);
if (!jcr_key) {
Jmsg0(jcr, M_WARNING, 0, _("pthread_setspecific called with invalid key = 0\n"));
return;
}
int status = pthread_setspecific(jcr_key, (void *)jcr);
if (status != 0) {
BErrNo be;
Jmsg1(jcr, M_ABORT, 0, _("pthread_setspecific failed: ERR=%s\n"), be.bstrerror(status));
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/watchdog.cc
Expand Up @@ -251,7 +251,7 @@ extern "C" void *watchdog_thread(void *arg)
struct timezone tz;
utime_t next_time;

SetJcrInTsd(INVALID_JCR);
/* SetJcrInTsd(INVALID_JCR); */
Dmsg0(800, "NicB-reworked watchdog thread entered\n");

while (!quit) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/stored/stored.cc
Expand Up @@ -283,7 +283,7 @@ int main (int argc, char *argv[])
ReadCryptoCache(me->working_directory, "bareos-sd",
GetFirstPortHostOrder(me->SDaddrs));

SetJcrInTsd(INVALID_JCR);
/* SetJcrInTsd(INVALID_JCR); */

/*
* Make sure on Solaris we can run concurrent, watch dog + servers + misc
Expand Down

0 comments on commit 9ec77b1

Please sign in to comment.