Subversion Repositories HelenOS-historic

Rev

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

Rev 1062 Rev 1066
Line 51... Line 51...
51
#include <arch/atomic.h>
51
#include <arch/atomic.h>
52
#include <memstr.h>
52
#include <memstr.h>
53
#include <print.h>
53
#include <print.h>
54
#include <mm/slab.h>
54
#include <mm/slab.h>
55
#include <debug.h>
55
#include <debug.h>
-
 
56
#include <main/uinit.h>
56
 
57
 
57
char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */
58
char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */
58
 
59
 
59
SPINLOCK_INITIALIZE(threads_lock);  /**< Lock protecting threads_head list. For locking rules, see declaration thereof. */
60
SPINLOCK_INITIALIZE(threads_lock);  /**< Lock protecting threads_head list. For locking rules, see declaration thereof. */
60
LIST_INITIALIZE(threads_head);      /**< List of all threads. */
61
LIST_INITIALIZE(threads_head);      /**< List of all threads. */
Line 278... Line 279...
278
   
279
   
279
    ipl = interrupts_disable();
280
    ipl = interrupts_disable();
280
    t->saved_context.ipl = interrupts_read();
281
    t->saved_context.ipl = interrupts_read();
281
    interrupts_restore(ipl);
282
    interrupts_restore(ipl);
282
   
283
   
283
    t->name = name;
284
    memcpy(t->name, name, THREAD_NAME_BUFLEN);
-
 
285
   
284
    t->thread_code = func;
286
    t->thread_code = func;
285
    t->thread_arg = arg;
287
    t->thread_arg = arg;
286
    t->ticks = -1;
288
    t->ticks = -1;
287
    t->priority = -1;       /* start in rq[0] */
289
    t->priority = -1;       /* start in rq[0] */
288
    t->cpu = NULL;
290
    t->cpu = NULL;
Line 421... Line 423...
421
    }
423
    }
422
 
424
 
423
    spinlock_unlock(&threads_lock);
425
    spinlock_unlock(&threads_lock);
424
    interrupts_restore(ipl);
426
    interrupts_restore(ipl);
425
}
427
}
-
 
428
 
-
 
429
/** Process syscall to create new thread.
-
 
430
 *
-
 
431
 */
-
 
432
__native sys_thread_create(__address function, void *arg, void *stack, char *name)
-
 
433
{
-
 
434
        thread_t *t;
-
 
435
        char namebuf[THREAD_NAME_BUFLEN];
-
 
436
    uspace_arg_t *uarg;
-
 
437
    __u32 tid;
-
 
438
 
-
 
439
        copy_from_uspace(namebuf, name, THREAD_NAME_BUFLEN);
-
 
440
    uarg = (uspace_arg_t *) malloc(sizeof(uarg), 0);
-
 
441
   
-
 
442
    uarg->uspace_entry = function;
-
 
443
    uarg->uspace_stack = (__address) stack;
-
 
444
 
-
 
445
        if ((t = thread_create(uinit, uarg, TASK, 0, namebuf))) {
-
 
446
        tid = t->tid;
-
 
447
                thread_ready(t);
-
 
448
        return (__native) tid;
-
 
449
        } else {
-
 
450
                free(namebuf);
-
 
451
        }
-
 
452
 
-
 
453
        return (__native) -1;
-
 
454
}
-
 
455
 
-
 
456
/** Process syscall to terminate thread.
-
 
457
 *
-
 
458
 */
-
 
459
__native sys_thread_exit(int status)
-
 
460
{
-
 
461
        thread_exit();
-
 
462
        /* Unreachable */
-
 
463
        return 0;
-
 
464
}