File: limiter.cc

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (32 lines) | stat: -rw-r--r-- 1,162 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "process.ih"

void Process::limiter(Process *process)
{
    size_t &timeLimit = process->d_timeLimit;

    if (timeLimit == 0)                 // no timelimit: thread immediately
        return;                         //               ends

    unique_lock<mutex> lock(process->d_mutex);   // get the lock

    volatile ChildAction &action = process->d_action;

    action = TIME_LIMIT;

            // when the child process ends, signalHandler is called, which
            // sets d_action to CHILD_ENDED, and notifies this function:
            // the loop ends with CHILD_ENDED. Otherwise, the time limit is
            // reached and the wait_for ends with d_action == TIME_LIMIT
    while (action != CHILD_ENDED)
    {
                                        // When the time limit is reached
                                        // the loop breaks, and d_action is
                                        // TIME_LIMIT.
        if (process->d_condition.wait_for(
                lock, chrono::seconds(timeLimit)) == cv_status::timeout)
            break;
    }

    if (action == TIME_LIMIT)
        process->discontinue(process->d_child);
}