Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k-sdk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈伟灿
k-sdk
Commits
bbb74483
Commit
bbb74483
authored
Oct 21, 2020
by
陈伟灿
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'yjq' into 'master'
20201021 See merge request chenweican/k-sdk!50
parents
5fe6622a
e589be90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
166 additions
and
0 deletions
+166
-0
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_ncp_queue.c
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_ncp_queue.c
+147
-0
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_ncp_queue.h
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_ncp_queue.h
+19
-0
No files found.
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_ncp_queue.c
0 → 100644
View file @
bbb74483
#include "kk_ncp_queue.h"
#include <pthread.h>
static
ncp_queue_s
g_ncp_queue
;
static
ncp_queue_s
*
_ncp_queue_get_ctx
(
void
)
{
return
&
g_ncp_queue
;
}
static
void
_ncp_queue_lock
(
void
)
{
int
err_num
;
ncp_queue_s
*
ctx
=
_ncp_queue_get_ctx
();
if
(
0
!=
(
err_num
=
pthread_mutex_lock
((
pthread_mutex_t
*
)
ctx
->
mutex
)))
{
printf
(
"lock mutex failed: - '%s' (%d)"
,
strerror
(
err_num
),
err_num
);
}
}
static
void
_ncp_queue_unlock
(
void
)
{
int
err_num
;
ncp_queue_s
*
ctx
=
_ncp_queue_get_ctx
();
if
(
0
!=
(
err_num
=
pthread_mutex_unlock
((
pthread_mutex_t
*
)
ctx
->
mutex
)))
{
printf
(
"unlock mutex failed - '%s' (%d)"
,
strerror
(
err_num
),
err_num
);
}
}
int
ncp_queue_init
(
int
max_size
)
{
int
err_num
;
ncp_queue_s
*
ctx
=
_ncp_queue_get_ctx
();
memset
(
ctx
,
0
,
sizeof
(
ncp_queue_s
));
ctx
->
mutex
=
(
pthread_mutex_t
*
)
malloc
(
sizeof
(
pthread_mutex_t
));
if
(
ctx
->
mutex
==
NULL
)
{
return
-
1
;
}
if
(
0
!=
(
err_num
=
pthread_mutex_init
(
ctx
->
mutex
,
NULL
)))
{
printf
(
"create mutex failed"
);
free
(
ctx
->
mutex
);
return
-
2
;
}
ctx
->
max_size
=
max_size
;
INIT_LIST_HEAD
(
&
ctx
->
list
);
return
0
;
}
void
ncp_queue_deinit
(
void
)
{
}
int
ncp_queue_enqueue
(
void
*
data
)
{
ncp_queue_s
*
ctx
=
_ncp_queue_get_ctx
();
ncp_queue_msg_s
*
node
=
NULL
;
if
(
data
==
NULL
)
{
return
-
1
;
}
_ncp_queue_lock
();
printf
(
"list size: %d, max size: %d
\n
"
,
ctx
->
size
,
ctx
->
max_size
);
if
(
ctx
->
size
>=
ctx
->
max_size
)
{
printf
(
"ncp queue list full"
);
_ncp_queue_unlock
();
return
-
2
;
}
node
=
malloc
(
sizeof
(
ncp_queue_msg_s
));
if
(
node
==
NULL
)
{
_ncp_queue_unlock
();
return
-
3
;
}
memset
(
node
,
0
,
sizeof
(
ncp_queue_msg_s
));
node
->
data
=
data
;
INIT_LIST_HEAD
(
&
node
->
list
);
ctx
->
size
++
;
list_add_tail
(
&
node
->
list
,
&
ctx
->
list
);
_ncp_queue_unlock
();
return
0
;
}
int
ncp_queue_dequeue
(
void
**
data
)
{
ncp_queue_s
*
ctx
=
_ncp_queue_get_ctx
();
ncp_queue_msg_s
*
node
=
NULL
;
if
(
data
==
NULL
)
{
return
-
1
;
}
_ncp_queue_lock
();
if
(
list_empty
(
&
ctx
->
list
))
{
_ncp_queue_unlock
();
return
-
2
;
}
node
=
list_first_entry
(
&
ctx
->
list
,
ncp_queue_msg_s
,
list
);
list_del
(
&
node
->
list
);
ctx
->
size
--
;
*
data
=
node
->
data
;
free
(
node
);
_ncp_queue_unlock
();
return
0
;
}
platform/zigbee/app/builder/Z3GatewayHost/ZB/kk_ncp_queue.h
0 → 100644
View file @
bbb74483
#include "klist.h"
typedef
struct
{
void
*
data
;
struct
list_head
list
;
}
ncp_queue_msg_s
;
typedef
struct
{
void
*
mutex
;
int
max_size
;
int
size
;
struct
list_head
list
;
}
ncp_queue_s
;
int
ncp_queue_init
(
int
max_size
);
int
ncp_queue_dequeue
(
void
**
data
);
int
ncp_queue_enqueue
(
void
*
data
);
Write
Preview
Markdown
is supported
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