while (cont) {
if (!moderate_inst) {
@@ -96,9 +77,15 @@ void *do_loop(void *data)
int main(int arg_count, char *argv[])
{
int ret, i;
- int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ int num_cpus;
cpu_set_t cpuset;
+ num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+ if (num_cpus < 0) {
+ printf("ERROR: sysconf error\n");
+ return -1;
+ }
+
printf("Num CPUs: %d\n", num_cpus);
if (arg_count > 1) {
if (!strcmp("moderate", argv[1])) {
@@ -120,7 +107,7 @@ int main(int arg_count, char *argv[])
}
pthread_t *p_thread_ptr = (pthread_t *) malloc(
- num_cpus * sizeof(pthread_attr_t));
+ num_cpus * sizeof(pthread_t));
if (!p_thread_ptr) {
printf("ERROR: out of memory\n");
@@ -141,7 +128,7 @@ int main(int arg_count, char *argv[])
#endif
#else
- ret = pthread_attr_setschedpolicy(&p[i], SCHED_NORMAL);
+ ret = pthread_attr_setschedpolicy(&p[i], SCHED_OTHER);
#endif
/* for each new object */
CPU_SET(i, &cpuset);
@@ -156,7 +143,7 @@ int main(int arg_count, char *argv[])
return ret;
}
#endif
- CPU_CLR(i, &cpuset);
+ CPU_CLR(i, &cpuset);
}
@@ -165,29 +152,23 @@ int main(int arg_count, char *argv[])
ret = pthread_create(&p_thread_ptr[i], &p[i],
do_loop, (void *)i);
if (ret < 0)
- printf("Error setting affinity for cpu%d\n", i);
+ printf("Error creating thread for cpu%d\n", i);
#ifdef ANDROID
CPU_ZERO(&cpuset);
CPU_SET(i, &cpuset);
- ret = sched_setaffinity(thr_id[i], sizeof(cpuset), &cpuset);
+ ret = pthread_setaffinity_np(p_thread_ptr[i], sizeof(cpuset), &cpuset);
if (ret) {
- printf("Error setting affinity on pthread th_id\n");
+ printf("Error setting affinity on pthread\n");
printf("Error: %s\n", strerror(ret));
return ret;
}
#endif
}
-#ifdef ANDROID
- pthread_mutex_lock(&mutex);
- conditionMet = 1;
- pthread_cond_broadcast(&cond);
- pthread_mutex_unlock(&mutex);
-#endif
-
while (1)
sleep(1);
+
return 0;
}