init_python_interpreter(&python_args);
#endif /* HAVE_PYTHON */
+ set_jcr_in_tsd(INVALID_JCR);
set_thread_concurrency(director->MaxConcurrentJobs * 2 +
4 /* UA */ + 4 /* sched+watchdog+jobsvr+misc */);
while ( (jcr = wait_for_next_job(runjob)) ) {
run_job(jcr); /* run job */
free_jcr(jcr); /* release jcr */
+ set_jcr_in_tsd(INVALID_JCR);
if (runjob) { /* command line, run a single job? */
break; /* yes, terminate */
}
JCR *jcr = ((wait_pkt *)arg)->jcr;
jobq_t *jq = ((wait_pkt *)arg)->jq;
+ set_jcr_in_tsd(jcr);
Dmsg0(2300, "Enter sched_wait.\n");
free(arg);
time_t wtime = jcr->sched_time - time(NULL);
}
item->jcr = jcr;
+ /* While waiting in a queue this job is not attached to a thread */
+ set_jcr_in_tsd(INVALID_JCR);
if (job_canceled(jcr)) {
/* Add job to ready queue so that it is canceled quickly */
jq->ready_jobs->prepend(item);
bool timedout = false;
bool work = true;
+ set_jcr_in_tsd(INVALID_JCR);
Dmsg0(2300, "Start jobq_server\n");
if ((stat = pthread_mutex_lock(&jq->mutex)) != 0) {
berrno be;
}
}
jq->running_jobs->append(je);
+
+ /* Attach jcr to this thread while we run the job */
set_jcr_in_tsd(jcr);
Dmsg1(2300, "Took jobid=%d from ready and appended to run\n", jcr->JobId);
jcr->use_count());
jq->engine(je->jcr);
+ /* Job finished detach from thread */
+ set_jcr_in_tsd(INVALID_JCR);
+
Dmsg2(2300, "Back from user engine jobid=%d use=%d.\n", jcr->JobId,
jcr->use_count());
void *connect_thread(void *arg)
{
pthread_detach(pthread_self());
+ set_jcr_in_tsd(INVALID_JCR);
/* Permit 20 console connections */
bnet_thread_server((dlist*)arg, 20, &ua_workq, handle_UA_client_request);
ua = new_ua_context(jcr);
ua->UA_sock = user;
- set_jcr_in_tsd(jcr);
+ set_jcr_in_tsd(INVALID_JCR);
user->recv(); /* Get first message */
if (!authenticate_user_agent(ua)) {
*/
void remove_jcr_from_tsd(JCR *jcr)
{
- JCR *tjcr = get_gcr_from_tsd();
+ JCR *tjcr = get_jcr_from_tsd();
if (tjcr == jcr) {
set_jcr_in_tsd(INVALID_JCR);
}
struct timezone tz;
utime_t next_time;
+ set_jcr_in_tsd(INVALID_JCR);
Dmsg0(800, "NicB-reworked watchdog thread entered\n");
while (!quit) {
*/
#include "bacula.h"
+#include "jcr.h"
/* Forward referenced functions */
extern "C" void *workq_server(void *arg);
if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) {
return NULL;
}
+ set_jcr_in_tsd(INVALID_JCR);
for (;;) {
struct timeval tv;
General:
25Nov08
+kes More changes to ensure that during thread switches the jcr
+ is removed from the TSD.
kes Ensure that consoles attach jcr to thread, and that only the
thread attached is removed from the TSD.
24Nov08