VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
Loading...
Searching...
No Matches
vex_task.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* */
3/* Copyright (c) Robomatter 2016, All rights reserved. */
4/* */
5/* Module: vex_task.h */
6/* Author: James Pearman */
7/* Created: 22 Nov 2016 */
8/* */
9/* Revisions: */
10/* V1.00 TBD - Initial release */
11/* */
12/*----------------------------------------------------------------------------*/
13
14#ifndef VEX_TASK_CLASS_H
15#define VEX_TASK_CLASS_H
16
17// In case we have ROBOTC definitions
18#ifdef task
19#undef task
20#endif
21
22/*-----------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace vex {
31 class task {
32 private:
33 static int _labelId;
34 int (* _callback)(void);
35
36 protected:
37 static int32_t _index( int (* callback)(void) );
38 static void _stopAll();
39
40 public:
41 task();
46 task( int (* callback)(void) );
52 task( int (* callback)(void), uint16_t priority );
53 ~task();
54
55 static const int32_t taskPrioritylow = 1;
56 static const int32_t taskPriorityNormal = 7;
57 static const int32_t taskPriorityHigh = 15;
58
63 static void stop( const task &t );
64
69 static void suspend( const task &t );
70
75 static void resume( const task &t );
76
82 static int16_t priority( const task &t ) ;
83
89 static void setPriority( const task &t, uint16_t priority ) ;
90
91 // these act on this task
95 void stop();
96
100 void suspend();
101
105 void resume();
106
111 int16_t priority();
112
117 void setPriority( uint16_t priority );
118
123 int16_t index( void );
124
129 static void sleep( uint32_t time );
130
134 static void yield();
135
139 static void dump();
140
145 static void stop( int (* callback)(void) );
146 };
147};
148
149namespace vex {
153 class semaphore {
154 private:
155 static bool _initialized;
156 uint32_t _sem;
157
158 protected:
159
160 public:
161 semaphore();
162 ~semaphore();
163
167 void lock();
168
173 void lock( uint32_t time );
174
178 void unlock();
179
184 bool owner();
185 };
186};
187
188#endif // VEX_TASK_CLASS_H
189
Use this class to synchronize access to resources.
Definition vex_task.h:153
void lock()
Attempts to lock the semaphore. If the semaphore is previously locked, it will block until the semaph...
void unlock()
Unlocks a locked semaphore.
void lock(uint32_t time)
Attempts to lock the semaphore. If the semaphore is previously locked, it will block until the timeou...
bool owner()
Checks to see if the semaphore was locked and is owned by the current task.
Use this class to create and control tasks.
Definition vex_task.h:31
void suspend()
Suspends the task until the task is told to resume.
static void sleep(uint32_t time)
Sets the task to sleep for the specified amount of time (in milliseconds).
task(int(*callback)(void))
Constructs a task with a function callback.
void setPriority(uint16_t priority)
Sets the priority of the task.
static int16_t priority(const task &t)
Gets the priority of a task.
static void yield()
return control to the scheduler and allow other tasks to run.
task(int(*callback)(void), uint16_t priority)
Constructs a task with a function callback and a priority.
static void stop(const task &t)
Stops the specified task.
void resume()
Resumes the previously suspended task.
static void stop(int(*callback)(void))
Stops the task of the passed in function.
static void resume(const task &t)
Resumes a specified task that has been suspended.
int16_t index(void)
Gets the task's index.
static void dump()
, internal use
int16_t priority()
Gets the priority of the task.
static void suspend(const task &t)
Suspends the specified task for later use.
void stop()
Stops the task.
static void setPriority(const task &t, uint16_t priority)
Sets the priority of the specified task.
Bumper switch device class
Definition vex_brain.h:24