Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
d680bba1
Commit
d680bba1
authored
Nov 11, 2013
by
Jeroen Vreeken
Browse files
Merge branch 'trace' into websocket
parents
60f27edd
7561dbc4
Changes
1
Hide whitespace changes
Inline
Side-by-side
common/trace/trace.c
View file @
d680bba1
...
...
@@ -31,6 +31,7 @@
#include
<unistd.h>
#include
<inttypes.h>
#include
<sys/ioctl.h>
#include
<pthread.h>
static
bool
timespec_older
(
struct
timespec
*
t1
,
struct
timespec
*
t2
)
...
...
@@ -120,19 +121,24 @@ static struct trace_pkt **packet_pool;
static
int
packet_pool_size
=
0
;
static
int
packet_pool_cur
=
0
;
static
pthread_mutex_t
trace_pkt_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
struct
trace_pkt
*
trace_packet_new
(
void
)
{
struct
trace_pkt
*
pkt
;
struct
trace_pkt
*
pkt
=
NULL
;
pthread_mutex_lock
(
&
trace_pkt_mutex
);
if
(
packet_pool_cur
)
{
pkt
=
packet_pool
[
packet_pool_cur
-
1
];
packet_pool_cur
--
;
return
pkt
;
}
pthread_mutex_unlock
(
&
trace_pkt_mutex
);
pkt
=
calloc
(
1
,
sizeof
(
struct
trace_pkt
));
pkt
->
data
=
malloc
(
PACKET_BUFLEN
);
pkt
->
buflen
=
PACKET_BUFLEN
;
if
(
!
pkt
)
{
pkt
=
calloc
(
1
,
sizeof
(
struct
trace_pkt
));
pkt
->
data
=
malloc
(
PACKET_BUFLEN
);
pkt
->
buflen
=
PACKET_BUFLEN
;
}
return
pkt
;
}
...
...
@@ -156,6 +162,8 @@ void trace_packet_put(struct trace_pkt *pkt)
return
;
}
pthread_mutex_lock
(
&
trace_pkt_mutex
);
if
(
packet_pool_cur
>=
packet_pool_size
)
{
packet_pool_size
+=
PACKET_POOL_CHUNK
;
packet_pool
=
realloc
(
packet_pool
,
...
...
@@ -164,6 +172,8 @@ void trace_packet_put(struct trace_pkt *pkt)
packet_pool
[
packet_pool_cur
]
=
pkt
;
pkt
->
len
=
0
;
packet_pool_cur
++
;
pthread_mutex_unlock
(
&
trace_pkt_mutex
);
}
int
trace_packet_list_add
(
struct
trace_pkt
*
pkt
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment