OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [go-defer.c] - Blame information for rev 761

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
/* go-defer.c -- manage the defer stack.
2
 
3
   Copyright 2009 The Go Authors. All rights reserved.
4
   Use of this source code is governed by a BSD-style
5
   license that can be found in the LICENSE file.  */
6
 
7
#include <stddef.h>
8
 
9
#include "runtime.h"
10
#include "go-alloc.h"
11
#include "go-panic.h"
12
#include "go-defer.h"
13
 
14
/* This function is called each time we need to defer a call.  */
15
 
16
void
17
__go_defer (_Bool *frame, void (*pfn) (void *), void *arg)
18
{
19
  G *g;
20
  struct __go_defer_stack *n;
21
 
22
  g = runtime_g ();
23
  n = (struct __go_defer_stack *) __go_alloc (sizeof (struct __go_defer_stack));
24
  n->__next = g->defer;
25
  n->__frame = frame;
26
  n->__panic = g->panic;
27
  n->__pfn = pfn;
28
  n->__arg = arg;
29
  n->__retaddr = NULL;
30
  g->defer = n;
31
}
32
 
33
/* This function is called when we want to undefer the stack.  */
34
 
35
void
36
__go_undefer (_Bool *frame)
37
{
38
  G *g;
39
 
40
  g = runtime_g ();
41
  while (g->defer != NULL && g->defer->__frame == frame)
42
    {
43
      struct __go_defer_stack *d;
44
      void (*pfn) (void *);
45
 
46
      d = g->defer;
47
      pfn = d->__pfn;
48
      d->__pfn = NULL;
49
 
50
      if (pfn != NULL)
51
        (*pfn) (d->__arg);
52
 
53
      g->defer = d->__next;
54
      __go_free (d);
55
 
56
      /* Since we are executing a defer function here, we know we are
57
         returning from the calling function.  If the calling
58
         function, or one of its callees, paniced, then the defer
59
         functions would be executed by __go_panic.  */
60
      *frame = 1;
61
    }
62
}
63
 
64
/* This function is called to record the address to which the deferred
65
   function returns.  This may in turn be checked by __go_can_recover.
66
   The frontend relies on this function returning false.  */
67
 
68
_Bool
69
__go_set_defer_retaddr (void *retaddr)
70
{
71
  G *g;
72
 
73
  g = runtime_g ();
74
  if (g->defer != NULL)
75
    g->defer->__retaddr = retaddr;
76
  return 0;
77
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.