// File: mh0fm4[P]SCDC/src/components/dataprov/dataprov_jobrun.cc
// Function: sched_run_routine(void*)
static void *sched_run_routine(void *arg)
{
  SCDC_TRACE(__func__ << ": arg: '" << arg << "'");

  scdc_dataprov_jobrun *dataprov_jobrun = static_cast<scdc_dataprov_jobrun *>(arg);

  pthread_mutex_lock(&dataprov_jobrun->sched_lock);
  while (dataprov_jobrun->sched_run)
  {
    struct timespec abstime;
    abstimeout(&abstime, 0.1, -1);

    pthread_cond_timedwait(&dataprov_jobrun->sched_cond, &dataprov_jobrun->sched_lock, &abstime);

/*    SCDC_TRACE(__func__ << ": " << time(NULL) << " TICK-TACK");*/

    if (!dataprov_jobrun->runjobs) continue;

    while (dataprov_jobrun->sched_jobs_wait.size() > 0)
    {
      /* check scheduling method */
      dataprov_jobrun->sched->update(dataprov_jobrun->sched_method);

      string jobid;
      scdc_dataprov_jobrun_job_t job;
      scdc_dataprov_jobrun_res_t jobres;
      scdcint_t m;

      if (!dataprov_jobrun->sched->job_get_runable(jobid, job, jobres, m)) break;

      sched_job_arg_t *sched_job_arg = new sched_job_arg_t;
      sched_job_arg->dataprov_jobrun = dataprov_jobrun;
      sched_job_arg->jobid = jobid;
      sched_job_arg->jobcmds = job.jobcmds;
      sched_job_arg->jobres = jobres;
      sched_job_arg->m = m;

      dataprov_jobrun->sched->job_started(m, jobid, sched_job_arg->jobres);

      pthread_t thread;
      pthread_create(&thread, NULL, sched_job_routine, sched_job_arg);

      dataprov_jobrun->sched_jobs_run.insert(scdc_dataprov_jobrun::sched_jobs_run_t::value_type(jobid, thread));

      job.waiting = false;
      dataprov_jobrun->set_job(jobid, job);

      pthread_cond_signal(&dataprov_jobrun->sched_cond_finished);
    }
  }
  pthread_mutex_unlock(&dataprov_jobrun->sched_lock);

  SCDC_TRACE(__func__ << ": return");

  pthread_exit(NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
jmp 0x7e421
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0xc9f0
movq -0x10(%rbp), %rax
testb $0x1, 0x188(%rax)
je 0x7e767
leaq -0x20(%rbp), %rdi
movsd 0x2a5ea(%rip), %xmm0    # 0xa8a40
movsd 0x26f52(%rip), %xmm1    # 0xa53b0
callq 0x2af10
movq -0x10(%rbp), %rdi
addq $0x1b8, %rdi            # imm = 0x1B8
movq -0x10(%rbp), %rsi
addq $0x190, %rsi            # imm = 0x190
leaq -0x20(%rbp), %rdx
callq 0xca30
movq -0x10(%rbp), %rax
testb $0x1, 0xc8(%rax)
jne 0x7e491
jmp 0x7e439
jmp 0x7e493
movq -0x10(%rbp), %rdi
addq $0x228, %rdi            # imm = 0x228
callq 0x83790
cmpq $0x0, %rax
jbe 0x7e762
movq -0x10(%rbp), %rsi
movq 0x180(%rsi), %rdi
addq $0xf0, %rsi
callq 0x86370
leaq -0x40(%rbp), %rdi
callq 0xc960
leaq -0xa8(%rbp), %rdi
callq 0x84280
jmp 0x7e4db
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x81e20
movq -0x138(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x180(%rax), %rdi
leaq -0x40(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
leaq -0xd8(%rbp), %r8
callq 0x864f0
movb %al, -0x129(%rbp)
jmp 0x7e51f
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x7e568
jmp 0x7e52b
movl $0x7, -0xdc(%rbp)
jmp 0x7e6ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x7e757
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x7e73f
movl $0x68, %edi
callq 0xc690
movq %rax, -0x140(%rbp)
jmp 0x7e57b
movq -0x140(%rbp), %rdi
callq 0x86560
movq -0x140(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rcx
movq -0xe8(%rbp), %rax
movq %rcx, (%rax)
movq -0xe8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x40(%rbp), %rsi
callq 0xc070
jmp 0x7e5b9
leaq -0x68(%rbp), %rsi
movq -0xe8(%rbp), %rdi
addq $0x28, %rdi
callq 0xc070
jmp 0x7e5cf
movq -0xe8(%rbp), %rdi
addq $0x48, %rdi
leaq -0xd0(%rbp), %rsi
callq 0x865a0
jmp 0x7e5e8
movq -0xd8(%rbp), %rcx
movq -0xe8(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x180(%rax), %rdi
movq -0xd8(%rbp), %rsi
movq -0xe8(%rbp), %rcx
addq $0x48, %rcx
leaq -0x40(%rbp), %rdx
callq 0x867f0
jmp 0x7e622
movq -0xe8(%rbp), %rcx
leaq 0x35e0(%rip), %rdx      # 0x81c10
xorl %eax, %eax
movl %eax, %esi
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0xcc20
movq -0x150(%rbp), %rdx
movq -0x10(%rbp), %rax
addq $0x240, %rax            # imm = 0x240
movq %rax, -0x148(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x86880
jmp 0x7e671
movq -0x148(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x86840
movb %dl, -0x159(%rbp)
movq %rax, -0x158(%rbp)
jmp 0x7e693
movb -0x159(%rbp), %al
movq -0x158(%rbp), %rcx
movq %rcx, -0x128(%rbp)
movb %al, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x84cc0
movb $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x7d6e0
jmp 0x7e6d3
movq -0x10(%rbp), %rdi
addq $0x1e8, %rdi            # imm = 0x1E8
callq 0xc030
movl $0x0, -0xdc(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x81ff0
leaq -0xa8(%rbp), %rdi
callq 0x842c0
leaq -0x40(%rbp), %rdi
callq 0xc3e0
movl -0xdc(%rbp), %eax
testl %eax, %eax
je 0x7e71c
jmp 0x7e71a
jmp 0x7e762
jmp 0x7e493
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x84cc0
leaq -0xd0(%rbp), %rdi
callq 0x81ff0
leaq -0xa8(%rbp), %rdi
callq 0x842c0
leaq -0x40(%rbp), %rdi
callq 0xc3e0
jmp 0x7e782
jmp 0x7e439
movq -0x10(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
callq 0xc4c0
jmp 0x7e779
xorl %eax, %eax
movl %eax, %edi
callq 0xcbb0
movq -0xb0(%rbp), %rdi
callq 0xcba0
nop