gcc/libgo/go/runtime/os_solaris.go
Ian Lance Taylor c0401cf78c runtime: copy internal locking code from Go 1.7 runtime
Remove the old locking code written in C.
    
    Add a shell script mkrsysinfo.sh to generate the runtime_sysinfo.go
    file, so that we can get Go copies of the system time structures and
    other types.
    
    Tweak the compiler so that when compiling the runtime package the
    address operator does not cause local variables to escape.  When the gc
    compiler compiles the runtime, an escaping local variable is treated as
    an error.  We should implement that, instead of this change, when escape
    analysis is turned on.
    
    Tweak the compiler so that the generated C header does not include names
    that start with an underscore followed by a non-upper-case letter,
    except for the special cases of _defer and _panic.  Otherwise we
    translate C types to Go in runtime_sysinfo.go and then generate those Go
    types back as C types in runtime.inc, which is useless and painful for
    the C code.
    
    Change entersyscall and friends to take a dummy argument, as the gc
    versions do, to simplify calls from the shared code.
    
    Reviewed-on: https://go-review.googlesource.com/30079

From-SVN: r240657
2016-09-30 13:45:08 +00:00

86 lines
1.7 KiB
Go

// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime
import "unsafe"
type mOS struct {
waitsema uintptr // semaphore for parking on locks
}
//extern malloc
func libc_malloc(uintptr) unsafe.Pointer
//go:noescape
//extern sem_init
func sem_init(sem *semt, pshared int32, value uint32) int32
//go:noescape
//extern sem_wait
func sem_wait(sem *semt) int32
//go:noescape
//extern sem_post
func sem_post(sem *semt) int32
//go:noescape
//extern sem_reltimedwait_np
func sem_reltimedwait_np(sem *semt, timeout *timespec) int32
//go:nosplit
func semacreate(mp *m) {
if mp.mos.waitsema != 0 {
return
}
var sem *semt
// Call libc's malloc rather than malloc. This will
// allocate space on the C heap. We can't call malloc
// here because it could cause a deadlock.
sem = (*semt)(libc_malloc(unsafe.Sizeof(*sem)))
if sem_init(sem, 0, 0) != 0 {
throw("sem_init")
}
mp.mos.waitsema = uintptr(unsafe.Pointer(sem))
}
//go:nosplit
func semasleep(ns int64) int32 {
_m_ := getg().m
if ns >= 0 {
var ts timespec
ts.set_sec(ns / 1000000000)
ts.set_nsec(int32(ns % 1000000000))
if sem_reltimedwait_np((*semt)(unsafe.Pointer(_m_.mos.waitsema)), &ts) != 0 {
err := errno()
if err == _ETIMEDOUT || err == _EAGAIN || err == _EINTR {
return -1
}
throw("sem_reltimedwait_np")
}
return 0
}
for {
r1 := sem_wait((*semt)(unsafe.Pointer(_m_.mos.waitsema)))
if r1 == 0 {
break
}
if errno() == _EINTR {
continue
}
throw("sem_wait")
}
return 0
}
//go:nosplit
func semawakeup(mp *m) {
if sem_post((*semt)(unsafe.Pointer(mp.mos.waitsema))) != 0 {
throw("sem_post")
}
}