SchedAPI.h 2.21 KB
Newer Older
1
/* -----------------------------------------------------------------------------
sof's avatar
sof committed
2
 * $Id: SchedAPI.h,v 1.14 2002/02/15 07:37:55 sof Exp $
3 4 5 6 7 8 9 10 11 12 13
 *
 * (c) The GHC Team 1998
 *
 * External API for the scheduler.  For most uses, the functions in
 * RtsAPI.h should be enough.
 *
 * ---------------------------------------------------------------------------*/

#ifndef SCHEDAPI_H
#define SCHEDAPI_H

14 15 16 17 18
#if defined(GRAN)
// Dummy def for NO_PRI if not in GranSim
#define NO_PRI  0
#endif

sof's avatar
sof committed
19
extern SchedulerStatus waitThread(StgTSO *main_thread, /*out*/StgClosure **ret);
20 21

/* 
sof's avatar
sof committed
22
 * Creating threads
23
 */
24
#if defined(GRAN)
sof's avatar
sof committed
25
extern StgTSO *createThread(nat stack_size, StgInt pri);
26
#else
sof's avatar
sof committed
27
extern StgTSO *createThread(nat stack_size);
28
#endif
29
#if defined(PAR) || defined(SMP)
sof's avatar
sof committed
30
extern void taskStart(void);
31
#endif
sof's avatar
sof committed
32 33
extern void scheduleThread(StgTSO *tso);
extern void scheduleExtThread(StgTSO *tso);
34 35 36 37 38 39 40 41 42 43 44 45 46

static inline void pushClosure   (StgTSO *tso, StgClosure *c) {
  tso->sp--;
  tso->sp[0] = (W_) c;
}

static inline void pushRealWorld (StgTSO *tso) {
  tso->sp--;
  tso->sp[0] = (W_) REALWORLD_TAG;
}
static inline StgTSO *
createGenThread(nat stack_size,  StgClosure *closure) {
  StgTSO *t;
47 48 49
#if defined(GRAN)
  t = createThread(stack_size, NO_PRI);
#else
50
  t = createThread(stack_size);
51
#endif
52 53 54 55 56 57 58
  pushClosure(t,closure);
  return t;
}

static inline StgTSO *
createIOThread(nat stack_size,  StgClosure *closure) {
  StgTSO *t;
59 60 61
#if defined(GRAN)
  t = createThread(stack_size, NO_PRI);
#else
62
  t = createThread(stack_size);
63
#endif
64 65 66 67 68
  pushRealWorld(t);
  pushClosure(t,closure);
  return t;
}

sof's avatar
sof committed
69 70 71 72 73 74 75 76
/*
 * Same as above, but also evaluate the result of the IO action
 * to whnf while we're at it.
 */

static inline StgTSO *
createStrictIOThread(nat stack_size,  StgClosure *closure) {
  StgTSO *t;
77 78 79
#if defined(GRAN)
  t = createThread(stack_size, NO_PRI);
#else
sof's avatar
sof committed
80
  t = createThread(stack_size);
81
#endif
sof's avatar
sof committed
82
  pushClosure(t,closure);
83
  pushClosure(t,(StgClosure*)&stg_forceIO_closure);
sof's avatar
sof committed
84 85 86 87
  return t;
}


88 89 90
/* 
 * Killing threads
 */
91 92 93 94 95 96 97
extern void deleteThread(StgTSO *tso);
extern void deleteAllThreads ( void );
extern int  howManyThreadsAvail ( void );
/*
 * Run until there are no more threads.
 */
extern void finishAllThreads ( void );
98 99 100 101

/*
 * Reverting CAFs
 */
102
extern void RevertCAFs ( void );
103 104

#endif