Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset da1bafb in mainline for kernel/generic/src/ipc/ipcrsc.c


Ignore:
Timestamp:
2010-05-24T18:57:31Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
0095368
Parents:
666f492
Message:

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/ipcrsc.c

    r666f492 rda1bafb  
    4545 * - hangup phone (the caller has hung up)
    4646 * - hangup phone (the answerbox is exiting)
    47  * 
     47 *
    4848 * Locking strategy
    4949 *
     
    8585 *
    8686 * Phone hangup
    87  * 
     87 *
    8888 * *** The caller hangs up (sys_ipc_hangup) ***
    8989 * - The phone is disconnected (no more messages can be sent over this phone),
     
    9999 *
    100100 * Call forwarding
    101  * 
     101 *
    102102 * The call can be forwarded, so that the answer to call is passed directly
    103103 * to the original sender. However, this poses special problems regarding
     
    114114 *
    115115 * Cleanup strategy
    116  * 
     116 *
    117117 * 1) Disconnect all our phones ('ipc_phone_hangup').
    118118 *
     
    123123 *
    124124 * 4) Wait for all async answers to arrive and dispose of them.
    125  * 
     125 *
    126126 */
    127127
     
    137137 * @todo Some speedup (hash table?)
    138138 *
    139  * @param callid        Userspace hash of the call. Currently it is the call
    140  *                      structure kernel address.
    141  *
    142  * @return              NULL on not found, otherwise pointer to the call
    143  *                      structure.
     139 * @param callid Userspace hash of the call. Currently it is the call
     140 *               structure kernel address.
     141 *
     142 * @return NULL on not found, otherwise pointer to the call
     143 *         structure.
     144 *
    144145 */
    145146call_t *get_call(unative_t callid)
    146147{
    147148        link_t *lst;
    148         call_t *call, *result = NULL;
    149 
    150         spinlock_lock(&TASK->answerbox.lock);
     149        call_t *result = NULL;
     150       
     151        irq_spinlock_lock(&TASK->answerbox.lock, true);
    151152        for (lst = TASK->answerbox.dispatched_calls.next;
    152153            lst != &TASK->answerbox.dispatched_calls; lst = lst->next) {
    153                 call = list_get_instance(lst, call_t, link);
     154                call_t *call = list_get_instance(lst, call_t, link);
    154155                if ((unative_t) call == callid) {
    155156                        result = call;
     
    157158                }
    158159        }
    159         spinlock_unlock(&TASK->answerbox.lock);
     160       
     161        irq_spinlock_unlock(&TASK->answerbox.lock, true);
    160162        return result;
    161163}
     
    163165/** Allocate new phone slot in the specified task.
    164166 *
    165  * @param t             Task for which to allocate a new phone.
    166  *
    167  * @return              New phone handle or -1 if the phone handle limit is
    168  *                      exceeded.
    169  */
    170 int phone_alloc(task_t *t)
    171 {
    172         int i;
    173 
    174         spinlock_lock(&t->lock);
     167 * @param task Task for which to allocate a new phone.
     168 *
     169 * @return New phone handle or -1 if the phone handle limit is
     170 *         exceeded.
     171 *
     172 */
     173int phone_alloc(task_t *task)
     174{
     175        irq_spinlock_lock(&task->lock, true);
     176       
     177        size_t i;
    175178        for (i = 0; i < IPC_MAX_PHONES; i++) {
    176                 if (t->phones[i].state == IPC_PHONE_HUNGUP &&
    177                     atomic_get(&t->phones[i].active_calls) == 0)
    178                         t->phones[i].state = IPC_PHONE_FREE;
    179 
    180                 if (t->phones[i].state == IPC_PHONE_FREE) {
    181                         t->phones[i].state = IPC_PHONE_CONNECTING;
     179                if ((task->phones[i].state == IPC_PHONE_HUNGUP) &&
     180                    (atomic_get(&task->phones[i].active_calls) == 0))
     181                        task->phones[i].state = IPC_PHONE_FREE;
     182               
     183                if (task->phones[i].state == IPC_PHONE_FREE) {
     184                        task->phones[i].state = IPC_PHONE_CONNECTING;
    182185                        break;
    183186                }
    184187        }
    185         spinlock_unlock(&t->lock);
    186 
     188       
     189        irq_spinlock_unlock(&task->lock, true);
     190       
    187191        if (i == IPC_MAX_PHONES)
    188192                return -1;
    189 
     193       
    190194        return i;
    191195}
     
    193197/** Mark a phone structure free.
    194198 *
    195  * @param phone         Phone structure to be marked free.
     199 * @param phone Phone structure to be marked free.
     200 *
    196201 */
    197202static void phone_deallocp(phone_t *phone)
     
    199204        ASSERT(phone->state == IPC_PHONE_CONNECTING);
    200205       
    201         /* atomic operation */
     206        /* Atomic operation */
    202207        phone->state = IPC_PHONE_FREE;
    203208}
     
    207212 * All already sent messages will be correctly processed.
    208213 *
    209  * @param phoneid       Phone handle of the phone to be freed.
     214 * @param phoneid Phone handle of the phone to be freed.
     215 *
    210216 */
    211217void phone_dealloc(int phoneid)
     
    216222/** Connect phone to a given answerbox.
    217223 *
    218  * @param phoneid       Phone handle to be connected.
    219  * @param box           Answerbox to which to connect the phone handle.
     224 * @param phoneid Phone handle to be connected.
     225 * @param box     Answerbox to which to connect the phone handle.
    220226 *
    221227 * The procedure _enforces_ that the user first marks the phone
    222228 * busy (e.g. via phone_alloc) and then connects the phone, otherwise
    223229 * race condition may appear.
     230 *
    224231 */
    225232void phone_connect(int phoneid, answerbox_t *box)
Note: See TracChangeset for help on using the changeset viewer.