Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Esteban Blanc
proview
Commits
63c120eb
Commit
63c120eb
authored
Sep 27, 2018
by
Christoffer Ackelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added documentation to co_array.
parent
852ae8d7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
101 deletions
+84
-101
src/exe/rt_neth/src/rt_neth.c
src/exe/rt_neth/src/rt_neth.c
+5
-6
src/lib/co/src/co_array.c
src/lib/co/src/co_array.c
+28
-67
src/lib/co/src/co_array.h
src/lib/co/src/co_array.h
+36
-11
src/lib/rt/src/rt_gdh.c
src/lib/rt/src/rt_gdh.c
+15
-17
No files found.
src/exe/rt_neth/src/rt_neth.c
View file @
63c120eb
...
...
@@ -1225,7 +1225,6 @@ static void classList(qcom_sGet* get)
int
i
;
pwr_tOid
oid
;
int
listcnt
;
array_tCtx
arr
;
pwr_tAttrRef
aref
;
gdb_ScopeLock
...
...
@@ -1239,14 +1238,14 @@ static void classList(qcom_sGet* get)
cdh_NodeIdToString
(
NULL
,
np
->
nid
,
0
,
0
));
}
array_
Init
(
&
arr
,
sizeof
(
pwr_tAttrRef
),
20
);
array_
tCtx
arr
=
array_New
(
sizeof
(
pwr_tAttrRef
),
20
);
listcnt
=
0
;
if
(
mp
->
attrobjects
)
{
for
(
i
=
0
;
i
<
mp
->
cidcnt
;
i
++
)
{
for
(
sts
=
gdh_GetClassListAttrRef
(
mp
->
cid
[
i
],
&
aref
);
ODD
(
sts
);
sts
=
gdh_GetNextAttrRef
(
mp
->
cid
[
i
],
&
aref
,
&
aref
))
{
array_
Add
(
arr
,
&
aref
);
array_
Push
(
arr
,
&
aref
);
listcnt
++
;
}
}
...
...
@@ -1255,7 +1254,7 @@ static void classList(qcom_sGet* get)
for
(
sts
=
gdh_GetClassList
(
mp
->
cid
[
i
],
&
oid
);
ODD
(
sts
);
sts
=
gdh_GetNextObject
(
oid
,
&
oid
))
{
aref
=
cdh_ObjidToAref
(
oid
);
array_
Add
(
arr
,
&
aref
);
array_
Push
(
arr
,
&
aref
);
listcnt
++
;
}
}
...
...
@@ -1279,10 +1278,10 @@ static void classList(qcom_sGet* get)
rmp
->
listcnt
=
0
;
}
else
{
rmp
->
listcnt
=
listcnt
;
memcpy
(
rmp
->
classlist
,
arr
->
a
,
listcnt
*
sizeof
(
pwr_tAttrRef
));
memcpy
(
rmp
->
classlist
,
arr
->
dat
a
,
listcnt
*
sizeof
(
pwr_tAttrRef
));
}
array_
Clos
e
(
arr
);
array_
Delet
e
(
arr
);
net_Reply
(
&
sts
,
get
,
&
put
,
0
);
}
src/lib/co/src/co_array.c
View file @
63c120eb
...
...
@@ -38,90 +38,51 @@
#include "pwr.h"
#include "co_array.h"
#include "co_math.h"
int
array_Init
(
array_tCtx
*
ctx
,
int
elemsize
,
int
alloc_incr
)
array_tCtx
array_New
(
int
elemsize
,
int
alloc_incr
)
{
*
ctx
=
calloc
(
1
,
sizeof
(
array_sCtx
));
if
(
!
*
ctx
)
return
0
;
(
*
ctx
)
->
elemsize
=
elemsize
;
(
*
ctx
)
->
alloc_incr
=
alloc_incr
;
(
*
ctx
)
->
a
=
calloc
(
1
,
elemsize
*
alloc_incr
)
;
if
(
!
(
*
ctx
)
->
a
)
return
0
;
(
*
ctx
)
->
allocated
=
alloc_incr
;
return
1
;
array_tCtx
arr
=
calloc
(
1
,
sizeof
(
array_sCtx
));
if
(
!
arr
)
return
NULL
;
arr
->
data
=
calloc
(
1
,
elemsize
*
alloc_incr
)
;
if
(
!
arr
->
data
)
return
NULL
;
arr
->
elemsize
=
elemsize
;
arr
->
alloc_incr
=
alloc_incr
;
arr
->
capacity
=
alloc_incr
;
return
arr
;
}
void
array_
Close
(
array_tCtx
ctx
)
void
array_
Delete
(
array_tCtx
arr
)
{
free
((
char
*
)
ctx
->
a
);
free
((
char
*
)
ctx
);
free
((
char
*
)
arr
->
dat
a
);
free
((
char
*
)
arr
);
}
int
array_
Add
(
array_tCtx
ctx
,
void
*
elem
)
int
array_
Push
(
array_tCtx
arr
,
void
*
elem
)
{
if
(
ctx
->
allocated
<=
ctx
->
a_size
)
{
void
*
a_tmp
;
ctx
->
allocated
+=
ctx
->
alloc_incr
;
a_tmp
=
calloc
(
ctx
->
allocated
,
ctx
->
elemsize
);
if
(
!
a_tmp
)
return
0
;
memcpy
(
a_tmp
,
ctx
->
a
,
ctx
->
a_size
*
ctx
->
elemsize
);
free
((
char
*
)
ctx
->
a
);
ctx
->
a
=
a_tmp
;
}
memcpy
((
char
*
)
ctx
->
a
+
ctx
->
a_size
*
ctx
->
elemsize
,
elem
,
ctx
->
elemsize
);
ctx
->
a_size
++
;
return
1
;
return
array_Concat
(
arr
,
elem
,
1
);
}
int
array_
MAdd
(
array_tCtx
ctx
,
void
*
elem
,
int
elements
)
int
array_
Concat
(
array_tCtx
arr
,
void
*
elems
,
int
number
)
{
if
(
ctx
->
allocated
<=
ctx
->
a_size
+
elements
-
1
)
{
void
*
a_tmp
;
ctx
->
allocated
+=
ctx
->
alloc_incr
;
if
(
ctx
->
allocated
<
ctx
->
a_size
+
elements
)
ctx
->
allocated
=
ctx
->
a_size
+
elements
;
a_tmp
=
calloc
(
ctx
->
allocated
,
ctx
->
elemsize
);
if
(
arr
->
capacity
<=
arr
->
size
+
number
-
1
)
{
void
*
a_tmp
=
realloc
(
arr
->
data
,
arr
->
elemsize
*
MAX
(
arr
->
capacity
+
arr
->
alloc_incr
,
arr
->
size
+
number
));
if
(
!
a_tmp
)
return
0
;
memcpy
(
a_tmp
,
ctx
->
a
,
ctx
->
a_size
*
ctx
->
elemsize
);
free
((
char
*
)
ctx
->
a
);
ctx
->
a
=
a_tmp
;
arr
->
data
=
a_tmp
;
arr
->
capacity
=
number
;
}
memcpy
((
char
*
)
ctx
->
a
+
ctx
->
a_size
*
ctx
->
elemsize
,
elem
,
ctx
->
elemsize
*
elements
);
ctx
->
a_size
+=
elements
;
memcpy
((
char
*
)
arr
->
data
+
arr
->
size
*
arr
->
elemsize
,
elems
,
arr
->
elemsize
*
number
);
arr
->
size
+=
number
;
return
1
;
}
int
array_Get
(
array_tCtx
ctx
,
int
idx
,
void
**
elem
)
void
*
array_Copy
(
array_tCtx
arr
)
{
if
(
idx
>=
ctx
->
a_size
)
return
0
;
memcpy
(
elem
,
(
char
*
)
ctx
->
a
+
idx
*
ctx
->
elemsize
,
ctx
->
elemsize
);
return
1
;
}
int
array_Size
(
array_tCtx
ctx
)
{
return
ctx
->
a_size
;
}
void
*
array_Array
(
array_tCtx
ctx
)
{
return
ctx
->
a
;
}
void
*
array_CopyArray
(
array_tCtx
ctx
)
{
void
*
buf
;
buf
=
malloc
(
ctx
->
elemsize
*
ctx
->
a_size
);
memcpy
(
buf
,
ctx
->
a
,
ctx
->
a_size
*
ctx
->
elemsize
);
void
*
buf
=
malloc
(
arr
->
elemsize
*
arr
->
size
);
memcpy
(
buf
,
arr
->
data
,
arr
->
size
*
arr
->
elemsize
);
return
buf
;
}
src/lib/co/src/co_array.h
View file @
63c120eb
...
...
@@ -45,22 +45,47 @@ extern "C" {
#include <stddef.h>
#endif
/*! \file co_array.h
\brief Dynamic-size array, like std::vector from C++ or ArrayList from Java.
*/
typedef
struct
{
void
*
a
;
void
*
dat
a
;
int
elemsize
;
int
allocated
;
int
capacity
;
int
alloc_incr
;
int
a_
size
;
int
size
;
}
array_sCtx
,
*
array_tCtx
;
int
array_Init
(
array_tCtx
*
ctx
,
int
elemsize
,
int
alloc_incr
);
void
array_Close
(
array_tCtx
ctx
);
int
array_Add
(
array_tCtx
ctx
,
void
*
elem
);
int
array_MAdd
(
array_tCtx
ctx
,
void
*
elem
,
int
elements
);
int
array_Get
(
array_tCtx
ctx
,
int
idx
,
void
**
elem
);
int
array_Size
(
array_tCtx
ctx
);
void
*
array_Array
(
array_tCtx
ctx
);
void
*
array_CopyArray
(
array_tCtx
ctx
);
/*! \fn array_tCtx array_New(int elemsize, int alloc_incr)
\brief Allocates a new dynamic array containing elements of size \a elemsize
\param elemsize The sizeof() an element.
\param alloc_incr How much the dynamic array should grow when it is full.
\return Returns a new dynamic array.
*/
array_tCtx
array_New
(
int
elemsize
,
int
alloc_incr
);
/*! \fn void array_Delete(array_tCtx arr)
\brief Frees the memory held by \a arr
*/
void
array_Delete
(
array_tCtx
arr
);
/*! \fn int array_Push(array_tCtx arr, void* elem)
\brief Appends \a elem to the end of the array.
*/
int
array_Push
(
array_tCtx
arr
,
void
*
elem
);
/*! \fn int array_Push(array_tCtx arr, void* elem)
\brief Concatenates \a number of elements from the fixed-size array
\a elems to the end of the dynamic array \a arr.
*/
int
array_Concat
(
array_tCtx
arr
,
void
*
elems
,
int
number
);
/*! \fn void* array_Copy(array_tCtx arr)
\brief Creates and returns a copy of \a arr.
Warning! The returned array must be free() explicitly.
*/
void
*
array_Copy
(
array_tCtx
arr
);
#ifdef __cplusplus
}
...
...
src/lib/rt/src/rt_gdh.c
View file @
63c120eb
...
...
@@ -5153,21 +5153,20 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
pwr_tStatus
sts
;
qcom_sNode
mynode
,
node
;
pwr_tNid
nid
;
array_tCtx
arr
;
pwr_tAttrRef
*
clist
;
int
ccnt
;
int
i
;
pwr_tObjid
oid
;
pwr_tAttrRef
aref
;
array_
Init
(
&
arr
,
sizeof
(
pwr_tAttrRef
),
20
);
array_
tCtx
arr
=
array_New
(
sizeof
(
pwr_tAttrRef
),
20
);
/* Add local objects */
if
(
attrobjects
)
{
for
(
i
=
0
;
i
<
cidcnt
;
i
++
)
{
for
(
sts
=
gdh_GetClassListAttrRef
(
cid
[
i
],
&
aref
);
ODD
(
sts
);
sts
=
gdh_GetNextAttrRef
(
cid
[
i
],
&
aref
,
&
aref
))
{
array_
Add
(
arr
,
&
aref
);
array_
Push
(
arr
,
&
aref
);
}
}
}
else
{
...
...
@@ -5175,7 +5174,7 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
for
(
sts
=
gdh_GetClassList
(
cid
[
i
],
&
oid
);
ODD
(
sts
);
sts
=
gdh_GetNextObject
(
oid
,
&
oid
))
{
aref
=
cdh_ObjidToAref
(
oid
);
array_
Add
(
arr
,
&
aref
);
array_
Push
(
arr
,
&
aref
);
}
}
}
...
...
@@ -5189,18 +5188,18 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
if
(
EVEN
(
sts
))
continue
;
array_
MAdd
(
arr
,
clist
,
ccnt
);
array_
Concat
(
arr
,
clist
,
ccnt
);
}
if
(
arr
ay_Size
(
arr
)
)
*
classlist
=
array_Copy
Array
(
arr
);
if
(
arr
->
size
)
*
classlist
=
array_Copy
(
arr
);
else
{
*
classlist
=
0
;
sts
=
GDH__NOSUCHOBJ
;
}
*
listcnt
=
arr
ay_Size
(
arr
)
;
*
listcnt
=
arr
->
size
;
array_
Clos
e
(
arr
);
array_
Delet
e
(
arr
);
return
GDH__SUCCESS
;
}
...
...
@@ -5208,19 +5207,18 @@ pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
pwr_tAttrRef
*
classlist
[],
int
*
listcnt
)
{
pwr_tStatus
sts
;
array_tCtx
arr
;
int
i
;
pwr_tObjid
oid
;
pwr_tAttrRef
aref
;
array_
Init
(
&
arr
,
sizeof
(
pwr_tAttrRef
),
20
);
array_
tCtx
arr
=
array_New
(
sizeof
(
pwr_tAttrRef
),
20
);
/* Add local objects */
if
(
attrobjects
)
{
for
(
i
=
0
;
i
<
cidcnt
;
i
++
)
{
for
(
sts
=
gdh_GetClassListAttrRef
(
cid
[
i
],
&
aref
);
ODD
(
sts
);
sts
=
gdh_GetNextAttrRef
(
cid
[
i
],
&
aref
,
&
aref
))
{
array_
Add
(
arr
,
&
aref
);
array_
Push
(
arr
,
&
aref
);
}
}
}
else
{
...
...
@@ -5228,20 +5226,20 @@ pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
for
(
sts
=
gdh_GetClassList
(
cid
[
i
],
&
oid
);
ODD
(
sts
);
sts
=
gdh_GetNextObject
(
oid
,
&
oid
))
{
aref
=
cdh_ObjidToAref
(
oid
);
array_
Add
(
arr
,
&
aref
);
array_
Push
(
arr
,
&
aref
);
}
}
}
if
(
arr
ay_Size
(
arr
)
)
*
classlist
=
array_Copy
Array
(
arr
);
if
(
arr
->
size
)
*
classlist
=
array_Copy
(
arr
);
else
{
*
classlist
=
0
;
sts
=
GDH__NOSUCHOBJ
;
}
*
listcnt
=
arr
ay_Size
(
arr
)
;
*
listcnt
=
arr
->
size
;
array_
Clos
e
(
arr
);
array_
Delet
e
(
arr
);
return
GDH__SUCCESS
;
}
...
...
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