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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [thread.c] - Blame information for rev 848

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

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2010 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
#include <errno.h>
6
#include <signal.h>
7
 
8
#include "runtime.h"
9
#include "go-assert.h"
10
 
11
/* For targets which don't have the required sync support.  Really
12
   these should be provided by gcc itself.  FIXME.  */
13
 
14
#if !defined (HAVE_SYNC_BOOL_COMPARE_AND_SWAP_4) || !defined (HAVE_SYNC_BOOL_COMPARE_AND_SWAP_8) || !defined (HAVE_SYNC_FETCH_AND_ADD_4) || !defined (HAVE_SYNC_ADD_AND_FETCH_8)
15
 
16
static pthread_mutex_t sync_lock = PTHREAD_MUTEX_INITIALIZER;
17
 
18
#endif
19
 
20
#ifndef HAVE_SYNC_BOOL_COMPARE_AND_SWAP_4
21
 
22
_Bool
23
__sync_bool_compare_and_swap_4 (uint32*, uint32, uint32)
24
  __attribute__ ((visibility ("hidden")));
25
 
26
_Bool
27
__sync_bool_compare_and_swap_4 (uint32* ptr, uint32 old, uint32 new)
28
{
29
  int i;
30
  _Bool ret;
31
 
32
  i = pthread_mutex_lock (&sync_lock);
33
  __go_assert (i == 0);
34
 
35
  if (*ptr != old)
36
    ret = 0;
37
  else
38
    {
39
      *ptr = new;
40
      ret = 1;
41
    }
42
 
43
  i = pthread_mutex_unlock (&sync_lock);
44
  __go_assert (i == 0);
45
 
46
  return ret;
47
}
48
 
49
#endif
50
 
51
#ifndef HAVE_SYNC_BOOL_COMPARE_AND_SWAP_8
52
 
53
_Bool
54
__sync_bool_compare_and_swap_8 (uint64*, uint64, uint64)
55
  __attribute__ ((visibility ("hidden")));
56
 
57
_Bool
58
__sync_bool_compare_and_swap_8 (uint64* ptr, uint64 old, uint64 new)
59
{
60
  int i;
61
  _Bool ret;
62
 
63
  i = pthread_mutex_lock (&sync_lock);
64
  __go_assert (i == 0);
65
 
66
  if (*ptr != old)
67
    ret = 0;
68
  else
69
    {
70
      *ptr = new;
71
      ret = 1;
72
    }
73
 
74
  i = pthread_mutex_unlock (&sync_lock);
75
  __go_assert (i == 0);
76
 
77
  return ret;
78
}
79
 
80
#endif
81
 
82
#ifndef HAVE_SYNC_FETCH_AND_ADD_4
83
 
84
uint32
85
__sync_fetch_and_add_4 (uint32*, uint32)
86
  __attribute__ ((visibility ("hidden")));
87
 
88
uint32
89
__sync_fetch_and_add_4 (uint32* ptr, uint32 add)
90
{
91
  int i;
92
  uint32 ret;
93
 
94
  i = pthread_mutex_lock (&sync_lock);
95
  __go_assert (i == 0);
96
 
97
  ret = *ptr;
98
  *ptr += add;
99
 
100
  i = pthread_mutex_unlock (&sync_lock);
101
  __go_assert (i == 0);
102
 
103
  return ret;
104
}
105
 
106
#endif
107
 
108
#ifndef HAVE_SYNC_ADD_AND_FETCH_8
109
 
110
uint64
111
__sync_add_and_fetch_8 (uint64*, uint64)
112
  __attribute__ ((visibility ("hidden")));
113
 
114
uint64
115
__sync_add_and_fetch_8 (uint64* ptr, uint64 add)
116
{
117
  int i;
118
  uint64 ret;
119
 
120
  i = pthread_mutex_lock (&sync_lock);
121
  __go_assert (i == 0);
122
 
123
  *ptr += add;
124
  ret = *ptr;
125
 
126
  i = pthread_mutex_unlock (&sync_lock);
127
  __go_assert (i == 0);
128
 
129
  return ret;
130
}
131
 
132
#endif
133
 
134
// Called to initialize a new m (including the bootstrap m).
135
void
136
runtime_minit(void)
137
{
138
        byte* stack;
139
        size_t stacksize;
140
        stack_t ss;
141
 
142
        // Initialize signal handling.
143
        runtime_m()->gsignal = runtime_malg(32*1024, &stack, &stacksize);       // OS X wants >=8K, Linux >=2K
144
        ss.ss_sp = stack;
145
        ss.ss_flags = 0;
146
        ss.ss_size = stacksize;
147
        if(sigaltstack(&ss, nil) < 0)
148
                *(int *)0xf1 = 0xf1;
149
}

powered by: WebSVN 2.1.0

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