Commit | Line | Data |
---|---|---|
e09e518e GM |
1 | #include "lockclass.h" |
2 | ||
3 | ||
4 | ||
5 | struct lockclass * lockclass_Init(int CPU){ | |
6 | struct lockclass *this = (struct lockclass *) g_malloc(sizeof(struct lockclass)); | |
7 | lockclassContext_Init(&this->_fsm, this); | |
8 | this->cpu = CPU; | |
9 | this->local_stack = g_array_new(FALSE, FALSE, sizeof(struct lockstruct *)); | |
10 | return this; | |
11 | } | |
12 | ||
13 | struct lockstruct * lockstruct_Init(guint32 address){ | |
14 | struct lockstruct *this = (struct lockstruct *) g_malloc(sizeof(struct lockstruct)); | |
15 | this->lock_add = address; | |
16 | this->taken_irqs_off=0; | |
17 | this->taken_irqs_on=0; | |
18 | this->hardirq_context=0; | |
19 | return this; | |
20 | } | |
21 | int irq_check(struct lockclass *fsm, void *lock, int hardirqs_off, int hardirq_context){ | |
22 | struct lockstruct *lock_check = (struct lockstruct *)lock; | |
23 | if(hardirq_context) | |
24 | lock_check->hardirq_context=hardirq_context; | |
25 | if(hardirq_context && lock_check->taken_irqs_on) | |
26 | return 1; | |
27 | else if(lock_check->hardirq_context && !hardirqs_off) | |
28 | return 1; | |
29 | ||
30 | return 0; | |
31 | } | |
32 | int empty_stack(struct lockclass *fsm){ | |
33 | return fsm->local_stack->len; | |
34 | } | |
35 | int lock_held(struct lockclass *fsm, struct lockstruct *lock){ | |
36 | //loop through stack & return 1 if found, 0 otherwise | |
37 | int i, len=fsm->local_stack->len; | |
38 | for(i=0; i<len; i++) | |
39 | { | |
40 | struct lockstruct *temp = g_array_index(fsm->local_stack, struct lockstruct *, i); | |
41 | if(temp==lock) | |
42 | return 1; | |
43 | } | |
44 | return 0; | |
45 | } | |
46 | int lock_held_on_behalf(struct lockclass *fsm, guint32 pid){ | |
47 | //loop through stack & return 1 if a lock is being held on behalf of pid | |
48 | int i, len=fsm->local_stack->len; | |
49 | for(i=0; i<len; i++) | |
50 | { | |
51 | struct lockstruct *temp=g_array_index(fsm->local_stack, struct lockstruct *, i); | |
52 | if(temp->pid==pid){ | |
53 | return 1; | |
54 | ||
55 | } | |
56 | } | |
57 | return 0; | |
58 | } | |
59 | void lockclass_test(){ | |
60 | //the smc compiler didn't generate the right code since no action was specified. (only a guard) | |
61 | return; | |
62 | } | |
63 | void lockclass_warning(struct lockclass *fsm, char *msg, struct lockstruct *lock){ | |
64 | printf("WARNING: %s\n", msg); | |
65 | if(lock!=NULL) | |
66 | printf("Lock 0x%x: taken_hard_irqs_on: %d, taken_hard_irqs_off %d, hardirq_context %d\n ", | |
67 | lock->lock_add, lock->taken_irqs_on, lock->taken_irqs_off, lock->hardirq_context); | |
68 | } | |
69 | void lockclass_pushlock(struct lockclass *fsm, struct lockstruct *lock){ | |
70 | g_array_append_val(fsm->local_stack, lock); | |
71 | } | |
72 | ||
73 | void lockclass_poplock(struct lockclass *fsm, struct lockstruct *lock){ | |
74 | int i; | |
75 | struct lockstruct *temp; | |
76 | for(i=fsm->local_stack->len-1; i>=0; i--){ | |
77 | temp=g_array_index(fsm->local_stack, struct lockstruct *, i); | |
78 | if(temp==lock){ | |
79 | g_array_remove_index(fsm->local_stack, i); | |
80 | break; | |
81 | } | |
82 | } | |
83 | } | |
84 |