- 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 */
-
- return true;
-}
-
-
-/* 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 */