-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtask.cpp
More file actions
105 lines (85 loc) · 1.89 KB
/
task.cpp
File metadata and controls
105 lines (85 loc) · 1.89 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <vxWorks.h>
#include <taskLib.h>
#include <intLib.h>
#include <sysLib.h>
#include <stdexcept>
#include "./vwpp.h"
using namespace vwpp::v3_0;
// This is the entry point for all tasks created with the Task
// class. It is a static function, so it has no object instance. By
// convention, the object context for the new task is passed as the
// first argument.
void Task::initTask(Task* tt)
{
try {
tt->taskEntry();
}
catch (...) {
::taskSuspend(0);
}
tt->id = ERROR;
}
Task::Task() : id(ERROR)
{
}
Task::~Task() NOTHROW_IMPL
{
if (ERROR != id)
::taskDelete(id);
}
// Delays the current task. The delay is given in milliseconds. If,
// after scaling the delay into timer ticks, the result is zero, the
// task will delay for 1 tick.
void Task::delay(int const dly) const
{
::taskDelay(ms_to_tick(dly));
}
void Task::run(char const* const name, unsigned char const pri, int const ss)
{
if (ERROR == id) {
if (ERROR == (id = ::taskSpawn(const_cast<char*>(name), pri,VX_FP_TASK,
ss, reinterpret_cast<FUNCPTR>(initTask),
reinterpret_cast<int>(this), 0, 0, 0, 0,
0, 0, 0, 0, 0)))
throw std::runtime_error("couldn't start new task");
} else
throw std::logic_error("task is already started");
}
int Task::priority() const
{
int tmp;
if (LIKELY(OK == ::taskPriorityGet(id, &tmp)))
return tmp;
throw std::runtime_error("couldn't get task priority");
}
bool Task::isReady() const
{
return TRUE == ::taskIsReady(id);
}
bool Task::isSuspended() const
{
return TRUE == ::taskIsSuspended(id);
}
bool Task::isValid() const
{
return OK == ::taskIdVerify(id);
}
char const* Task::name() const
{
return ::taskName(id);
}
void Task::suspend() const
{
::taskSuspend(id);
}
void Task::resume() const
{
::taskResume(id);
}
#ifndef NDEBUG
STATUS vwppTestTasks()
{
SchedLock lock();
return OK;
}
#endif