-/* threads_table_init *********************************************************
-
- Initialize the global threads table.
-
-******************************************************************************/
-
-static void threads_table_init(void)
-{
- s4 size;
- s4 i;
-
- size = THREADS_INITIAL_TABLE_SIZE;
-
- threads_table.size = size;
- threads_table.table = MNEW(threads_table_entry_t, size);
-
- /* link the entries in a freelist */
-
- for (i=0; i<size; ++i) {
- threads_table.table[i].nextfree = i+1;
- }
-
- /* terminate the freelist */
-
- threads_table.table[size-1].nextfree = 0; /* index 0 is never free */
-}
-
-
-/* threads_table_add **********************************************************
-
- Add a thread to the global threads table. The index is entered in the
- threadobject. The thinlock value for the thread is pre-computed.
-
- IN:
- thread............the thread to add
-
- RETURN VALUE:
- The table index for the newly added thread. This value has also been
- entered in the threadobject.
-
- PRE-CONDITION:
- The caller must hold the threadlistlock!
-
-******************************************************************************/
-
-static s4 threads_table_add(threadobject *thread)
-{
- s4 index;
- s4 oldsize;
- s4 newsize;
- s4 i;
-
- /* table[0] serves as the head of the freelist */
-
- index = threads_table.table[0].nextfree;
-
- /* if we got a free index, use it */
-
- if (index) {
-got_an_index:
- threads_table.table[0].nextfree = threads_table.table[index].nextfree;
- threads_table.table[index].thread = thread;
- thread->index = index;
- thread->thinlock = lock_pre_compute_thinlock(index);
- return index;
- }
-
- /* we must grow the table */
-
- oldsize = threads_table.size;
- newsize = oldsize * 2;
-
- threads_table.table = MREALLOC(threads_table.table, threads_table_entry_t,
- oldsize, newsize);
- threads_table.size = newsize;
-
- /* link the new entries to a free list */
-
- for (i=oldsize; i<newsize; ++i) {
- threads_table.table[i].nextfree = i+1;
- }
-
- /* terminate the freelist */
-
- threads_table.table[newsize-1].nextfree = 0; /* index 0 is never free */
-
- /* use the first of the new entries */
-
- index = oldsize;
- goto got_an_index;
-}
-
-
-/* threads_table_remove *******************************************************
-
- Remove a thread from the global threads table.
-
- IN:
- thread............the thread to remove
-
- PRE-CONDITION:
- The caller must hold the threadlistlock!
-
-******************************************************************************/
-
-static void threads_table_remove(threadobject *thread)
-{
- s4 index;
-
- index = thread->index;
-
- /* put the index into the freelist */
-
- threads_table.table[index] = threads_table.table[0];
- threads_table.table[0].nextfree = index;
-
- /* delete the index in the threadobject to discover bugs */
-#if !defined(NDEBUG)
- thread->index = 0;
-#endif
-}
-
-/* threads_init_threadobject **************************************************
-
- Initialize implementation fields of a java.lang.VMThread.
-
- IN:
- t............the java.lang.VMThread
-
-******************************************************************************/
-
-void threads_init_threadobject(java_lang_VMThread *t)
-{
- threadobject *thread = (threadobject*) t;
-
- thread->tid = pthread_self();
-
- thread->index = 0;
-
- /* TODO destroy all those things */
- pthread_mutex_init(&(thread->joinmutex), NULL);
- pthread_cond_init(&(thread->joincond), NULL);
-
- pthread_mutex_init(&(thread->waitmutex), NULL);
- pthread_cond_init(&(thread->waitcond), NULL);
-
- thread->interrupted = false;
- thread->signaled = false;
- thread->sleeping = false;
-}
-
-