Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
cb1565eb
Commit
cb1565eb
authored
Apr 10, 2012
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Android-specific implementation of getNumberOfCPUs
parent
dccfd79d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
system.cpp
modules/core/src/system.cpp
+44
-0
No files found.
modules/core/src/system.cpp
View file @
cb1565eb
...
...
@@ -374,6 +374,46 @@ int getThreadNum(void)
#endif
}
#if ANDROID
static
inline
int
getNumberOfCPUsImpl
()
{
FILE
*
cpuPossible
=
fopen
(
"/sys/devices/system/cpu/possible"
,
"r"
);
if
(
!
cpuPossible
)
return
1
;
char
buf
[
2000
];
//big enough for 1000 CPUs in worst possible configuration
char
*
pbuf
=
fgets
(
buf
,
sizeof
(
buf
),
cpuPossible
);
fclose
(
cpuPossible
);
if
(
!
pbuf
)
return
1
;
//parse string of form "0-1,3,5-7,10,13-15"
int
cpusAvailable
=
0
;
while
(
*
pbuf
)
{
const
char
*
pos
=
pbuf
;
bool
range
=
false
;
while
(
*
pbuf
&&
*
pbuf
!=
','
)
{
if
(
*
pbuf
==
'-'
)
range
=
true
;
++
pbuf
;
}
if
(
*
pbuf
)
*
pbuf
++
=
0
;
if
(
!
range
)
++
cpusAvailable
;
else
{
int
rstart
=
0
,
rend
=
0
;
sscanf
(
pos
,
"%d-%d"
,
&
rstart
,
&
rend
);
cpusAvailable
+=
rend
-
rstart
+
1
;
}
}
return
cpusAvailable
?
cpusAvailable
:
1
;
}
#endif
int
getNumberOfCPUs
(
void
)
{
#if defined WIN32 || defined _WIN32
...
...
@@ -381,6 +421,10 @@ int getNumberOfCPUs(void)
GetSystemInfo
(
&
sysinfo
);
return
(
int
)
sysinfo
.
dwNumberOfProcessors
;
#elif ANDROID
static
int
ncpus
=
getNumberOfCPUsImpl
();
printf
(
"CPUS= %d
\n
"
,
ncpus
);
return
ncpus
;
#elif defined __linux__
return
(
int
)
sysconf
(
_SC_NPROCESSORS_ONLN
);
#elif defined __APPLE__
...
...
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