COSA
An Object-Oriented Platform for Arduino Programming
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Resource.hh
Go to the documentation of this file.
1
21
#ifndef COSA_RESOURCE_HH
22
#define COSA_RESOURCE_HH
23
24
#include "
Cosa/Types.h
"
25
29
class
Resource
{
30
public
:
34
Resource
() :
35
m_busy(false)
36
{}
37
42
void
acquire
()
43
{
44
uint8_t key =
lock
(m_busy);
45
on_acquire
();
46
unlock
(key);
47
}
48
54
bool
try_acquire
()
55
{
56
synchronized
{
57
if
(m_busy)
return
(
false
);
58
m_busy =
true
;
59
on_acquire
();
60
}
61
}
62
67
void
release
()
68
{
69
synchronized
{
70
on_release
();
71
m_busy =
false
;
72
}
73
}
74
75
protected
:
80
virtual
void
on_acquire
() = 0;
81
86
virtual
void
on_release
() = 0;
87
88
private
:
89
volatile
bool
m_busy;
90
};
91
#endif
92
Resource::Resource
Resource()
Definition:
Resource.hh:34
Types.h
Resource::release
void release()
Definition:
Resource.hh:67
Resource::acquire
void acquire()
Definition:
Resource.hh:42
Resource::on_release
virtual void on_release()=0
lock
uint8_t lock()
Definition:
Types.h:319
Resource::try_acquire
bool try_acquire()
Definition:
Resource.hh:54
Resource
Definition:
Resource.hh:29
unlock
void unlock(uint8_t key)
Definition:
Types.h:331
Resource::on_acquire
virtual void on_acquire()=0
cores
cosa
Cosa
Resource.hh
Generated on Thu Aug 31 2017 17:02:02 for COSA by
1.8.11