23 |
|
|
24 |
#include "cons.h" |
#include "cons.h" |
25 |
|
|
26 |
/* Open the virtual console ID or the ACTIVE_ID plus DELTA one in CONS |
/* Open the virtual console ID or the virtual console DELTA steps away |
27 |
and return it in R_VCONS, which will be locked. */ |
from VCONS in the linked list and return it in R_VCONS, which will |
28 |
|
be locked. */ |
29 |
error_t |
error_t |
30 |
cons_switch (cons_t cons, int active_id, int id, int delta, vcons_t *r_vcons) |
cons_switch (vcons_t vcons, int id, int delta, vcons_t *r_vcons) |
31 |
{ |
{ |
32 |
error_t err = 0; |
error_t err = 0; |
33 |
|
cons_t cons = vcons->cons; |
34 |
vcons_list_t vcons_entry = NULL; |
vcons_list_t vcons_entry = NULL; |
35 |
|
|
36 |
if (!id && !delta) |
if (!id && !delta) |
37 |
return 0; |
return 0; |
38 |
|
|
39 |
mutex_lock (&cons->lock); |
mutex_lock (&cons->lock); |
40 |
vcons_entry = cons->vcons_list; |
if (id) |
41 |
while (vcons_entry && vcons_entry->id != (id ?: active_id)) |
{ |
42 |
vcons_entry = vcons_entry->next; |
vcons_entry = cons->vcons_list; |
43 |
|
while (vcons_entry && vcons_entry->id != id) |
44 |
if (!id && vcons_entry) |
vcons_entry = vcons_entry->next; |
45 |
{ |
} |
46 |
if (delta > 0) |
else if (delta > 0) |
47 |
{ |
{ |
48 |
while (delta-- > 0) |
vcons_entry = vcons->vcons_entry; |
49 |
{ |
while (delta-- > 0) |
50 |
vcons_entry = vcons_entry->next; |
{ |
51 |
if (!vcons_entry) |
vcons_entry = vcons_entry->next; |
52 |
vcons_entry = cons->vcons_list; |
if (!vcons_entry) |
53 |
} |
vcons_entry = cons->vcons_list; |
54 |
} |
} |
55 |
else |
} |
56 |
{ |
else |
57 |
assert (delta < 0); |
{ |
58 |
while (delta++ < 0) |
assert (delta < 0); |
59 |
{ |
while (delta++ < 0) |
60 |
vcons_entry = vcons_entry->prev; |
{ |
61 |
if (!vcons_entry) |
vcons_entry = vcons_entry->prev; |
62 |
vcons_entry = cons->vcons_last; |
if (!vcons_entry) |
63 |
} |
vcons_entry = cons->vcons_last; |
64 |
} |
} |
65 |
} |
} |
66 |
|
|
67 |
if (!vcons_entry) |
if (!vcons_entry) |
68 |
{ |
{ |
69 |
mutex_unlock (&cons->lock); |
mutex_unlock (&cons->lock); |
81 |
if (!err) |
if (!err) |
82 |
vcons_entry->vcons = *r_vcons; |
vcons_entry->vcons = *r_vcons; |
83 |
} |
} |
84 |
|
|
85 |
mutex_unlock (&cons->lock); |
mutex_unlock (&cons->lock); |
86 |
return err; |
return err; |
87 |
} |
} |