Comprehensive update, add some GC fixes, update examples to new MacOS

header file layout.
This commit is contained in:
gmp
2020-06-24 13:03:53 -04:00
parent acc8cab583
commit 8b3a956bbe
26 changed files with 9729 additions and 354 deletions
+27 -27
View File
@@ -26,21 +26,21 @@ func incr() func(bool) (int, float64) {
if b == 0 {
return i, 0.0
} else {
return i, (b/float64(i)) * 100
return i, (b / float64(i)) * 100
}
}
}
type tracker struct {
add, drop func(*ns.Id)
check func()
i func(bool) (int, float64)
check func()
i func(bool) (int, float64)
}
type record struct {
ptr unsafe.Pointer
ptr unsafe.Pointer
goPtr *ns.Id
when time.Time
when time.Time
}
func newTracker() (func(*ns.Id), func(*ns.Id), func()) {
@@ -54,35 +54,35 @@ func newTracker() (func(*ns.Id), func(*ns.Id), func()) {
select {
case x := <-addch:
mux.Lock()
data = append(data,record{
x.Ptr(),
x,
time.Now(),
})
data = append(data, record{
x.Ptr(),
x,
time.Now(),
})
mux.Unlock()
case x := <-dropch:
mux.Lock()
data = append(data,record{
nil,
x,
time.Now(),
})
data = append(data, record{
nil,
x,
time.Now(),
})
mux.Unlock()
}
}
}()
add := func(x *ns.Id) {
addch<- x
addch <- x
}
drop := func(x *ns.Id) {
dropch<- x
dropch <- x
}
check := func() {
live := map[unsafe.Pointer]*ns.Id{}
bad := false
mux.Lock()
for _,r := range data {
for _, r := range data {
if r.ptr != nil {
if live[r.ptr] != nil {
fmt.Printf("COLLISION: %p & %p -> %p\n", r.goPtr, live[r.ptr], r.ptr)
@@ -90,10 +90,10 @@ func newTracker() (func(*ns.Id), func(*ns.Id), func()) {
}
live[r.ptr] = r.goPtr
} else {
delete(live,r.ptr)
delete(live, r.ptr)
}
}
fmt.Printf("Checked %d records -- ",len(data))
fmt.Printf("Checked %d records -- ", len(data))
if bad {
fmt.Printf("failed\n")
} else {
@@ -101,25 +101,25 @@ func newTracker() (func(*ns.Id), func(*ns.Id), func()) {
}
mux.Unlock()
}
return add,drop,check
return add, drop, check
}
func mkstrings(t tracker) {
for {
//fmt.Printf("main thread: %t\n",ns.NSThreadIsMainThread())
x,b := t.i(false)
str := fmt.Sprintf("string %d",x)
x, b := t.i(false)
str := fmt.Sprintf("string %d", x)
s := ns.NSStringWithGoString(str)
//t.add(&s.Id)
for j := 0; j < 10; j++ {
sout := s.String()
if str != sout {
_,b = t.i(true)
_, b = t.i(true)
fmt.Printf("%3.2f%% -- %d: '%s' '%s'\n", b, x, str, sout)
}
time.Sleep(time.Second/1000)
time.Sleep(time.Second / 1000)
}
if x % 1000 == 0 {
if x%1000 == 0 {
fmt.Printf("%3.2f%% -- %s\n", b, time.Now().Format("03:04:05.000"))
}
//t.drop(&s.Id)
@@ -145,7 +145,7 @@ func main() {
go func() {
for {
runtime.GC()
time.Sleep(time.Second/100)
time.Sleep(time.Second / 100)
}
}()
+1 -1
View File
@@ -1,5 +1,5 @@
inputfiles:
- /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h
- /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h
classes:
- NSString
- NSThread