| 1 | = Internal tricks = |
| 2 | During real and deep developing time, we faced some obstacles seeming hard to |
| 3 | overcome, but we did. That is because a few tricks helped us. |
| 4 | |
| 5 | An early faced obstacle was the process queue tail pointer updating in `pcb.c` |
| 6 | module, avoiding to use a global-visible variable, but passing a parameter. To |
| 7 | do this, each involved function receives a pointer to that queue pointer (i.e. a |
| 8 | double pointer). |
| 9 | |
| 10 | We use the same hack on a different situation, writing `st.c` source, where we |
| 11 | enjoined double advantages. Maintaining a tree after insertion/removal |
| 12 | operations, means updating a couple of pointers, and so knowing their location. |
| 13 | Because of the fact that tree is |
| 14 | [wiki:DataStructures#a3.Semaphorebinarytree single-linked], going back the tree |
| 15 | becomes impossible, and so, each of such operations must be performed starting |
| 16 | one level higher in the hierarchy. Here another problem comes up: starting from |
| 17 | a node, which of its child is the wanted one? As pointed up above, we found just |
| 18 | one solution for both problem: using a pointer to the father's field |
| 19 | (`s_leftC`/`s_rightC`), which point to the target node. |
| 20 | |
| 21 | But, as you can see, there is another question: which is the ancestor of the |
| 22 | root element? If it does not exist, the solution just explained gets wrong and |
| 23 | need a small modification: the insertion of a dummy node, pointed to by |
| 24 | `semdRoot`, as root node, which makes the whole semaphore descriptors tree the |
| 25 | dummy's left-progeny. |
| 26 | |
| 27 | This change suggests another hack, in order to find a suitable place to store |
| 28 | the free list. It contains descriptors of each inactive semaphore: we linked it |
| 29 | as a list, using `s_rightC` field, avoiding memory space wastes. |
| 30 | |
| 31 | {{{ |
| 32 | |
| 33 | Semaphore Tree structure: |
| 34 | ______ |
| 35 | | | |
| 36 | | HEAD | |
| 37 | |______| |
| 38 | .' '. |
| 39 | __.' '.__ |
| 40 | |__| |__| |
| 41 | __.''.__ '.__ |
| 42 | |__| |__| |__| |
| 43 | |
| 44 | | | | | |
| 45 | `--------' `----' |
| 46 | AST Free List |
| 47 | |
| 48 | Further details can be found directly in source code :) |
| 49 | |
| 50 | }}} |