Subversion Repositories HelenOS

Rev

Rev 1854 | Rev 1888 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1854 Rev 1882
Line 84... Line 84...
84
 */
84
 */
85
void before_thread_runs(void)
85
void before_thread_runs(void)
86
{
86
{
87
    before_thread_runs_arch();
87
    before_thread_runs_arch();
88
#ifdef CONFIG_FPU_LAZY
88
#ifdef CONFIG_FPU_LAZY
89
    if(THREAD==CPU->fpu_owner)
89
    if(THREAD == CPU->fpu_owner)
90
        fpu_enable();
90
        fpu_enable();
91
    else
91
    else
92
        fpu_disable();
92
        fpu_disable();
93
#else
93
#else
94
    fpu_enable();
94
    fpu_enable();
95
    if (THREAD->fpu_context_exists)
95
    if (THREAD->fpu_context_exists)
96
        fpu_context_restore(THREAD->saved_fpu_context);
96
        fpu_context_restore(THREAD->saved_fpu_context);
97
    else {
97
    else {
98
        fpu_init();
98
        fpu_init();
99
        THREAD->fpu_context_exists=1;
99
        THREAD->fpu_context_exists = 1;
100
    }
100
    }
101
#endif
101
#endif
102
}
102
}
103
 
103
 
104
/** Take actions after THREAD had run.
104
/** Take actions after THREAD had run.
Line 125... Line 125...
125
    /* Save old context */
125
    /* Save old context */
126
    if (CPU->fpu_owner != NULL) {  
126
    if (CPU->fpu_owner != NULL) {  
127
        spinlock_lock(&CPU->fpu_owner->lock);
127
        spinlock_lock(&CPU->fpu_owner->lock);
128
        fpu_context_save(CPU->fpu_owner->saved_fpu_context);
128
        fpu_context_save(CPU->fpu_owner->saved_fpu_context);
129
        /* don't prevent migration */
129
        /* don't prevent migration */
130
        CPU->fpu_owner->fpu_context_engaged=0;
130
        CPU->fpu_owner->fpu_context_engaged = 0;
131
        spinlock_unlock(&CPU->fpu_owner->lock);
131
        spinlock_unlock(&CPU->fpu_owner->lock);
132
        CPU->fpu_owner = NULL;
132
        CPU->fpu_owner = NULL;
133
    }
133
    }
134
 
134
 
135
    spinlock_lock(&THREAD->lock);
135
    spinlock_lock(&THREAD->lock);
Line 144... Line 144...
144
            THREAD->saved_fpu_context = slab_alloc(fpu_context_slab, 0);
144
            THREAD->saved_fpu_context = slab_alloc(fpu_context_slab, 0);
145
            /* We may have switched CPUs during slab_alloc */
145
            /* We may have switched CPUs during slab_alloc */
146
            goto restart;
146
            goto restart;
147
        }
147
        }
148
        fpu_init();
148
        fpu_init();
149
        THREAD->fpu_context_exists=1;
149
        THREAD->fpu_context_exists = 1;
150
    }
150
    }
151
    CPU->fpu_owner=THREAD;
151
    CPU->fpu_owner = THREAD;
152
    THREAD->fpu_context_engaged = 1;
152
    THREAD->fpu_context_engaged = 1;
153
    spinlock_unlock(&THREAD->lock);
153
    spinlock_unlock(&THREAD->lock);
154
 
154
 
155
    spinlock_unlock(&CPU->lock);
155
    spinlock_unlock(&CPU->lock);
156
}
156
}