summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-12-21 14:26:09 -0500
committerPietro Gagliardi <[email protected]>2015-12-21 14:26:09 -0500
commit4b74894536813fbc8f59136a6f77a3d5f9af67eb (patch)
treededfa6110d88e9c439adfff5cd47656e325bfae3
parent01893daaf19c3617b65820a7e1febdfa02beb389 (diff)
Made QueueMain() immune to collisions.
-rw-r--r--main.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/main.go b/main.go
index 5f8f624..de7b1ca 100644
--- a/main.go
+++ b/main.go
@@ -83,8 +83,14 @@ func QueueMain(f func()) {
qmlock.Lock()
defer qmlock.Unlock()
- n := qmcurrent
- qmcurrent++
+ n := uintptr(0)
+ for {
+ n = qmcurrent
+ qmcurrent++
+ if qmmap[n] == nil {
+ break
+ }
+ }
qmmap[n] = f
C.realQueueMain(unsafe.Pointer(n))
}