Subversion Repositories HelenOS

Rev

Rev 3623 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3623 Rev 4377
Line 100... Line 100...
100
 
100
 
101
SPINLOCK_INITIALIZE(tidlock);
101
SPINLOCK_INITIALIZE(tidlock);
102
thread_id_t last_tid = 0;
102
thread_id_t last_tid = 0;
103
 
103
 
104
static slab_cache_t *thread_slab;
104
static slab_cache_t *thread_slab;
105
#ifdef ARCH_HAS_FPU
105
#ifdef CONFIG_FPU
106
slab_cache_t *fpu_context_slab;
106
slab_cache_t *fpu_context_slab;
107
#endif
107
#endif
108
 
108
 
109
/** Thread wrapper.
109
/** Thread wrapper.
110
 *
110
 *
Line 159... Line 159...
159
    link_initialize(&t->th_link);
159
    link_initialize(&t->th_link);
160
 
160
 
161
    /* call the architecture-specific part of the constructor */
161
    /* call the architecture-specific part of the constructor */
162
    thr_constructor_arch(t);
162
    thr_constructor_arch(t);
163
   
163
   
164
#ifdef ARCH_HAS_FPU
164
#ifdef CONFIG_FPU
165
#ifdef CONFIG_FPU_LAZY
165
#ifdef CONFIG_FPU_LAZY
166
    t->saved_fpu_context = NULL;
166
    t->saved_fpu_context = NULL;
167
#else
167
#else
168
    t->saved_fpu_context = slab_alloc(fpu_context_slab, kmflags);
168
    t->saved_fpu_context = slab_alloc(fpu_context_slab, kmflags);
169
    if (!t->saved_fpu_context)
169
    if (!t->saved_fpu_context)
170
        return -1;
170
        return -1;
171
#endif
171
#endif
172
#endif  
172
#endif
173
 
173
 
174
    t->kstack = (uint8_t *) frame_alloc(STACK_FRAMES, FRAME_KA | kmflags);
174
    t->kstack = (uint8_t *) frame_alloc(STACK_FRAMES, FRAME_KA | kmflags);
175
    if (!t->kstack) {
175
    if (!t->kstack) {
176
#ifdef ARCH_HAS_FPU
176
#ifdef CONFIG_FPU
177
        if (t->saved_fpu_context)
177
        if (t->saved_fpu_context)
178
            slab_free(fpu_context_slab, t->saved_fpu_context);
178
            slab_free(fpu_context_slab, t->saved_fpu_context);
179
#endif
179
#endif
180
        return -1;
180
        return -1;
181
    }
181
    }
Line 194... Line 194...
194
 
194
 
195
    /* call the architecture-specific part of the destructor */
195
    /* call the architecture-specific part of the destructor */
196
    thr_destructor_arch(t);
196
    thr_destructor_arch(t);
197
 
197
 
198
    frame_free(KA2PA(t->kstack));
198
    frame_free(KA2PA(t->kstack));
199
#ifdef ARCH_HAS_FPU
199
#ifdef CONFIG_FPU
200
    if (t->saved_fpu_context)
200
    if (t->saved_fpu_context)
201
        slab_free(fpu_context_slab, t->saved_fpu_context);
201
        slab_free(fpu_context_slab, t->saved_fpu_context);
202
#endif
202
#endif
203
    return 1; /* One page freed */
203
    return 1; /* One page freed */
204
}
204
}
Line 209... Line 209...
209
 *
209
 *
210
 */
210
 */
211
void thread_init(void)
211
void thread_init(void)
212
{
212
{
213
    THREAD = NULL;
213
    THREAD = NULL;
214
    atomic_set(&nrdy,0);
214
    atomic_set(&nrdy, 0);
215
    thread_slab = slab_cache_create("thread_slab", sizeof(thread_t), 0,
215
    thread_slab = slab_cache_create("thread_slab", sizeof(thread_t), 0,
216
        thr_constructor, thr_destructor, 0);
216
        thr_constructor, thr_destructor, 0);
217
 
217
 
218
#ifdef ARCH_HAS_FPU
218
#ifdef CONFIG_FPU
219
    fpu_context_slab = slab_cache_create("fpu_slab", sizeof(fpu_context_t),
219
    fpu_context_slab = slab_cache_create("fpu_slab", sizeof(fpu_context_t),
220
        FPU_CONTEXT_ALIGN, NULL, NULL, 0);
220
        FPU_CONTEXT_ALIGN, NULL, NULL, 0);
221
#endif
221
#endif
222
 
222
 
223
    avltree_create(&threads_tree);
223
    avltree_create(&threads_tree);
Line 314... Line 314...
314
    ipl = interrupts_disable();
314
    ipl = interrupts_disable();
315
    t->saved_context.ipl = interrupts_read();
315
    t->saved_context.ipl = interrupts_read();
316
    interrupts_restore(ipl);
316
    interrupts_restore(ipl);
317
   
317
   
318
    memcpy(t->name, name, THREAD_NAME_BUFLEN);
318
    memcpy(t->name, name, THREAD_NAME_BUFLEN);
319
    t->name[THREAD_NAME_BUFLEN - 1] = '\0';
319
    t->name[THREAD_NAME_BUFLEN - 1] = 0;
320
   
320
   
321
    t->thread_code = func;
321
    t->thread_code = func;
322
    t->thread_arg = arg;
322
    t->thread_arg = arg;
323
    t->ticks = -1;
323
    t->ticks = -1;
324
    t->cycles = 0;
324
    t->cycles = 0;
Line 721... Line 721...
721
 
721
 
722
    rc = copy_from_uspace(namebuf, uspace_name, name_len);
722
    rc = copy_from_uspace(namebuf, uspace_name, name_len);
723
    if (rc != 0)
723
    if (rc != 0)
724
        return (unative_t) rc;
724
        return (unative_t) rc;
725
 
725
 
726
    namebuf[name_len] = '\0';
726
    namebuf[name_len] = 0;
727
 
727
 
728
    /*
728
    /*
729
     * In case of failure, kernel_uarg will be deallocated in this function.
729
     * In case of failure, kernel_uarg will be deallocated in this function.
730
     * In case of success, kernel_uarg will be freed in uinit().
730
     * In case of success, kernel_uarg will be freed in uinit().
731
     */
731
     */