summaryrefslogtreecommitdiff
path: root/pfinet/asm/system.h
blob: bb51a6fba1560d8317e919c79e797950fafe4442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef _HACK_ASM_SYSTEM_H_
#define _HACK_ASM_SYSTEM_H_

#include <cthreads.h>
#include <sys/types.h>

/* This lock is held when "interrupts" are disabled. */
extern struct mutex global_interrupt_lock;

/* Save the "processor state" in the longword FLAGS. */
/* We define 1 to mean that global_interrupt_lock is held. */

#define save_flags(x) _real_save_flags (&x)
extern inline void 
_real_save_flags (u_long *flagsword)
{
  int locked;
  
  locked = !mutex_try_lock (&global_interrupt_lock);
  if (!locked)
    mutex_unlock (&global_interrupt_lock);
  *flagsword = locked;
}

/* Restore state saved in FLAGS. */
extern inline void
restore_flags (u_long flags)
{
  if (flags)
    mutex_try_lock (&global_interrupt_lock);
  else
    mutex_unlock (&global_interrupt_lock);
}

/* Prevent "interrupts" from happening. */
extern inline void 
cli ()
{
  mutex_try_lock (&global_interrupt_lock);
}

/* Permit "interrupts". */ 
extern inline void
sti ()
{
  mutex_unlock (&global_interrupt_lock);
}

/* In threads set aside to be interrupt threads, they call this
   before doing any real work, thus putting us into "interrupt"
   mode. */
extern inline void
begin_interrupt ()
{
  mutex_lock (&global_interrupt_lock);
  /* Should we suspend the current "user thread"? */
}

/* And then this, at the end of the real work. */
extern inline void
end_interrupt ()
{
  mutex_unlock (&global_interrupt_lock);
  /* Likewise a resumption? */
}



#endif