Main Page
Namespaces
Classes
Files
File List
File Members
src
xarm
core
common
queue_memcpy.cc
Go to the documentation of this file.
1
/*
2
# Software License Agreement (MIT License)
3
#
4
# Copyright (c) 2020, UFACTORY, Inc.
5
# All rights reserved.
6
#
7
# Author: Vinman <vinman.wen@ufactory.cc> <vinman.cub@gmail.com>
8
*/
9
#include <string.h>
10
#include "
xarm/core/common/queue_memcpy.h
"
11
12
QueueMemcpy::QueueMemcpy
(
long
n,
long
n_size) {
13
total_
= n;
14
annode_size_
= n_size;
15
buf_
=
new
char
[
total_
*
annode_size_
];
16
flush
();
17
}
18
19
QueueMemcpy::~QueueMemcpy
(
void
) {
delete
[]
buf_
; }
20
21
char
QueueMemcpy::flush
(
void
) {
22
cnt_
= 0;
23
head_
= 0;
24
tail_
= 0;
25
memset(
buf_
, 0,
annode_size_
*
total_
);
26
27
return
0;
28
}
29
30
long
QueueMemcpy::size
(
void
) {
return
cnt_
; }
31
32
int
QueueMemcpy::is_full
(
void
) {
33
if
(
total_
<=
cnt_
)
34
return
1;
35
else
36
return
0;
37
}
38
39
long
QueueMemcpy::node_size
(
void
) {
return
annode_size_
; }
40
41
char
QueueMemcpy::pop
(
void
*data) {
42
std::lock_guard<std::mutex> locker(
mutex_
);
43
if
(0 >=
cnt_
) {
44
return
-1;
45
}
46
if
(
total_
<=
tail_
)
tail_
= 0;
47
48
memcpy(data, &
buf_
[
tail_
*
annode_size_
], annode_size_);
49
tail_
++;
50
cnt_
--;
51
return
0;
52
}
53
54
char
QueueMemcpy::get
(
void
*data) {
55
std::lock_guard<std::mutex> locker(
mutex_
);
56
if
(0 >=
cnt_
) {
57
return
-1;
58
}
59
if
(
total_
<=
tail_
)
tail_
= 0;
60
61
memcpy(data, &
buf_
[
tail_
*
annode_size_
], annode_size_);
62
63
return
0;
64
}
65
66
char
QueueMemcpy::push
(
void
*data) {
67
std::lock_guard<std::mutex> locker(
mutex_
);
68
if
(
total_
<=
cnt_
) {
69
return
-1;
70
}
71
if
(
total_
<=
head_
)
head_
= 0;
72
73
memcpy(&
buf_
[
head_
*
annode_size_
], data, annode_size_);
74
head_
++;
75
cnt_
++;
76
return
0;
77
}
QueueMemcpy::head_
long head_
Definition:
queue_memcpy.h:30
QueueMemcpy::QueueMemcpy
QueueMemcpy(long n, long n_size)
Definition:
queue_memcpy.cc:12
QueueMemcpy::pop
char pop(void *data)
Definition:
queue_memcpy.cc:41
QueueMemcpy::tail_
long tail_
Definition:
queue_memcpy.h:31
queue_memcpy.h
QueueMemcpy::~QueueMemcpy
~QueueMemcpy(void)
Definition:
queue_memcpy.cc:19
QueueMemcpy::mutex_
std::mutex mutex_
Definition:
queue_memcpy.h:34
QueueMemcpy::get
char get(void *data)
Definition:
queue_memcpy.cc:54
QueueMemcpy::buf_
char * buf_
Definition:
queue_memcpy.h:32
QueueMemcpy::cnt_
long cnt_
Definition:
queue_memcpy.h:29
QueueMemcpy::total_
long total_
Definition:
queue_memcpy.h:26
QueueMemcpy::size
long size(void)
Definition:
queue_memcpy.cc:30
QueueMemcpy::annode_size_
long annode_size_
Definition:
queue_memcpy.h:27
QueueMemcpy::push
char push(void *data)
Definition:
queue_memcpy.cc:66
QueueMemcpy::node_size
long node_size(void)
Definition:
queue_memcpy.cc:39
QueueMemcpy::is_full
int is_full(void)
Definition:
queue_memcpy.cc:32
QueueMemcpy::flush
char flush(void)
Definition:
queue_memcpy.cc:21
xarm_api
Author(s):
autogenerated on Sat May 8 2021 02:51:23