Changeset a35a3d8 in mainline for uspace/lib/c/generic/context.c


Ignore:
Timestamp:
2018-03-12T17:13:46Z (7 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b127e4af
Parents:
f3d47c97
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-12 17:13:46)
git-committer:
GitHub <noreply@…> (2018-03-12 17:13:46)
Message:

Turn context_save/context_restore into standard setjmp/longjmp. (#24)

Turn context_save()/context_restore() into semi-standard __setjmp()/__longjmp().

The original context_* functions are similar to setjmp()/longjmp(), except that the return value is more restricted for the former, and with inverted meaning. This commit adopts the standard return value semantics and acknowledges that these functions are "standard setjmp()/longjmp() with additional implementation-specific properties" by changing the name. The only divergence from the standard is that __longjmp() causes __setjmp() to return its value unchanged, even if it is zero. This is just to avoid extra assembly, and longjmp() checks this in C.

Note that the original use of context_save()/context_restore() to implement context switching in fibril implementation has already been delegated to context_create()/context_swap(), which provide more natural control flow.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/context.c

    rf3d47c97 ra35a3d8  
    2828
    2929#include <context.h>
     30#include <setjmp.h>
    3031#include <libarch/tls.h>
    3132#include <libarch/fibril.h>
     
    4243void context_swap(context_t *self, context_t *other)
    4344{
    44         if (context_save(self))
    45                 context_restore(other);
     45        if (!__setjmp(self))
     46                __longjmp(other, 1);
    4647}
    4748
    4849void context_create(context_t *context, const context_create_t *arg)
    4950{
    50         context_save(context);
     51        __setjmp(context);
    5152        context_set(context, FADDR(arg->fn), arg->stack_base,
    5253            arg->stack_size, arg->tls);
Note: See TracChangeset for help on using the changeset viewer.