Changes: Christian Thalinger
Edwin Steiner
- $Id: threads.c 4921 2006-05-15 14:24:36Z twisti $
+ $Id: threads.c 4938 2006-05-22 09:06:44Z twisti $
*/
return;
} while (errno == EINTR);
- fprintf(stderr,"error: sem_init returned unexpected error %d: %s\n",
- errno, strerror(errno));
- abort();
+ vm_abort("sem_init failed: %s", strerror(errno));
}
return;
} while (errno == EINTR);
- fprintf(stderr,"error: sem_wait returned unexpected error %d: %s\n",
- errno, strerror(errno));
- abort();
+ vm_abort("sem_wait failed: %s", strerror(errno));
}
if (r == 0)
return;
- fprintf(stderr,"error: sem_post returned unexpected error %d: %s\n",
- errno, strerror(errno));
- abort();
+ vm_abort("sem_post failed: %s", strerror(errno));
}
mainthreadobj = (threadobject *) builtin_new(class_java_lang_VMThread);
- if (!mainthreadobj)
+ if (mainthreadobj == NULL)
return false;
FREE(tempthread, threadobject);
mainthread = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
- if (!mainthread)
+ if (mainthread == NULL)
throw_exception_exit();
mainthreadobj->o.thread = mainthread;
class_java_lang_Thread,
true);
- if (!method)
+ if (method == NULL)
return false;
(void) vm_call_method(method, (java_objectheader *) mainthread,
class_java_lang_ThreadGroup,
true);
- if (!method)
+ if (method == NULL)
return false;
(void) vm_call_method(method, (java_objectheader *) threadgroup,
threads_set_thread_priority(pthread_self(), 5);
- pthread_attr_init(&threadattr);
+ /* initialize the thread attribute object */
+
+ if (pthread_attr_init(&threadattr)) {
+ log_println("pthread_attr_init failed: %s", strerror(errno));
+ return false;
+ }
+
pthread_attr_setdetachstate(&threadattr, PTHREAD_CREATE_DETACHED);
/* everything's ok */
void threads_start_thread(java_lang_Thread *t, functionptr function)
{
- sem_t sem;
- sem_t sem_first;
- startupinfo startup;
- threadobject *thread;
+ sem_t sem;
+ sem_t sem_first;
+ pthread_attr_t attr;
+ startupinfo startup;
+ threadobject *thread;
thread = (threadobject *) t->vmThread;
threads_sem_init(&sem, 0, 0);
threads_sem_init(&sem_first, 0, 0);
+ /* initialize thread attribute object */
+
+ if (pthread_attr_init(&attr))
+ vm_abort("pthread_attr_init failed: %s", strerror(errno));
+
+ /* initialize thread stacksize */
+
+ if (pthread_attr_setstacksize(&attr, opt_stacksize))
+ vm_abort("pthread_attr_setstacksize failed: %s", strerror(errno));
+
/* create the thread */
- if (pthread_create(&thread->tid, &threadattr, threads_startup_thread,
- &startup)) {
- log_text("pthread_create failed");
- assert(0);
- }
+ if (pthread_create(&thread->tid, &attr, threads_startup_thread, &startup))
+ vm_abort("pthread_create failed: %s", strerror(errno));
/* signal that pthread_create has returned, so thread->tid is valid */
/* get current time */
- if (gettimeofday(&tvnow, NULL) != 0) {
- fprintf(stderr,"error: gettimeofday returned unexpected error %d: %s\n",
- errno, strerror(errno));
- abort();
- }
+ if (gettimeofday(&tvnow, NULL) != 0)
+ vm_abort("gettimeofday failed: %s\n", strerror(errno));
/* convert it to a timespec */