Subversion Repositories HelenOS

Rev

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

Rev 2481 Rev 2482
Line 30... Line 30...
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#ifndef LIBC_PSTHREAD_H_
35
#ifndef LIBC_FIBRIL_H_
36
#define LIBC_PSTHREAD_H_
36
#define LIBC_FIBRIL_H_
37
 
37
 
38
#include <libarch/psthread.h>
38
#include <libarch/fibril.h>
39
#include <libadt/list.h>
39
#include <libadt/list.h>
40
#include <libarch/thread.h>
40
#include <libarch/thread.h>
41
 
41
 
42
#ifndef context_set
42
#ifndef context_set
43
#define context_set(c, _pc, stack, size, ptls)          \
43
#define context_set(c, _pc, stack, size, ptls)          \
44
    (c)->pc = (sysarg_t) (_pc);             \
44
    (c)->pc = (sysarg_t) (_pc);             \
45
    (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;     \
45
    (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;     \
46
        (c)->tls = (sysarg_t) (ptls);
46
        (c)->tls = (sysarg_t) (ptls);
47
#endif /* context_set */
47
#endif /* context_set */
48
 
48
 
49
#define PSTHREAD_SERIALIZED   1
49
#define FIBRIL_SERIALIZED   1
50
 
50
 
51
typedef enum {
51
typedef enum {
52
    PS_SLEEP,
52
    FIBRIL_SLEEP,
53
    PS_PREEMPT,
53
    FIBRIL_PREEMPT,
54
    PS_TO_MANAGER,
54
    FIBRIL_TO_MANAGER,
55
    PS_FROM_MANAGER,
55
    FIBRIL_FROM_MANAGER,
56
    PS_FROM_DEAD
56
    FIBRIL_FROM_DEAD
57
} pschange_type;
57
} fibril_switch_type_t;
58
 
58
 
59
typedef sysarg_t pstid_t;
59
typedef sysarg_t fid_t;
60
 
60
 
61
struct psthread_data {
61
struct fibril {
62
    link_t link;
62
    link_t link;
63
    context_t ctx;
63
    context_t ctx;
64
    void *stack;
64
    void *stack;
65
    void *arg;
65
    void *arg;
66
    int (*func)(void *);
66
    int (*func)(void *);
67
    tcb_t *tcb;
67
    tcb_t *tcb;
68
 
68
 
69
    struct psthread_data *clean_after_me;
69
    struct fibril *clean_after_me;
70
    struct psthread_data *joiner;
70
    struct fibril *joiner;
71
    int joinee_retval;
71
    int joinee_retval;
72
    int retval;
72
    int retval;
73
    int flags;
73
    int flags;
74
};
74
};
75
typedef struct psthread_data psthread_data_t;
75
typedef struct fibril fibril_t;
76
 
76
 
77
extern int context_save(context_t *c);
77
extern int context_save(context_t *c);
78
extern void context_restore(context_t *c) __attribute__ ((noreturn));
78
extern void context_restore(context_t *c) __attribute__ ((noreturn));
79
 
79
 
80
pstid_t psthread_create(int (*func)(void *), void *arg);
80
extern fid_t fibril_create(int (*func)(void *), void *arg);
81
int psthread_join(pstid_t psthrid);
81
extern int fibril_join(fid_t fid);
82
psthread_data_t * psthread_setup(void);
82
extern fibril_t *fibril_setup(void);
83
void psthread_teardown(psthread_data_t *pt);
83
extern void fibril_teardown(fibril_t *f);
84
int psthread_schedule_next_adv(pschange_type ctype);
84
extern int fibril_schedule_next_adv(fibril_switch_type_t stype);
85
void psthread_add_ready(pstid_t ptid);
85
extern void fibril_add_ready(fid_t fid);
86
void psthread_add_manager(pstid_t psthrid);
86
extern void fibril_add_manager(fid_t fid);
87
void psthread_remove_manager(void);
87
extern void fibril_remove_manager(void);
88
pstid_t psthread_get_id(void);
88
extern fid_t fibril_get_id(void);
89
void psthread_inc_sercount(void);
89
extern void fibril_inc_sercount(void);
90
void psthread_dec_sercount(void);
90
extern void fibril_dec_sercount(void);
91
 
91
 
92
static inline int psthread_schedule_next(void) {
92
static inline int fibril_schedule_next(void) {
93
    return psthread_schedule_next_adv(PS_PREEMPT);
93
    return fibril_schedule_next_adv(FIBRIL_PREEMPT);
94
}
94
}
95
 
95
 
96
#endif
96
#endif
97
 
97
 
98
/** @}
98
/** @}