aboutsummaryrefslogtreecommitdiffstats
path: root/fastos/src/tests/job.h
blob: 4546cfe1daa72d88beee24290c0f5673fda1642f (plain) (blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <mutex>
#include <condition_variable>

enum JobCode
{
   PRINT_MESSAGE_AND_WAIT3MSEC,
   INCREASE_NUMBER,
   WAIT_FOR_BREAK_FLAG,
   WAIT_FOR_THREAD_TO_FINISH,
   TEST_ID,
   SILENTNOP,
   NOP
};

class Job
{
private:
   Job(const Job &);
   Job &operator=(const Job&);

public:
   JobCode code;
   char *message;
   std::mutex *mutex;
   std::condition_variable *condition;
   FastOS_ThreadInterface *otherThread, *ownThread;
   std::atomic<int> result;
   FastOS_ThreadId _threadId;

   Job()
     : code(NOP),
       message(nullptr),
       mutex(nullptr),
       condition(nullptr),
       otherThread(nullptr),
       ownThread(nullptr),
       result(-1),
       _threadId()
   {
   }

   ~Job()
   {
      if(message != nullptr)
         free(message);
   }
};