summaryrefslogtreecommitdiffstats
path: root/libgo/runtime/go-go.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime/go-go.c')
-rw-r--r--libgo/runtime/go-go.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/libgo/runtime/go-go.c b/libgo/runtime/go-go.c
index 3d8e9e62908..139162056b8 100644
--- a/libgo/runtime/go-go.c
+++ b/libgo/runtime/go-go.c
@@ -73,7 +73,7 @@ static sigset_t __go_thread_wait_sigset;
/* Remove the current thread from the list of threads. */
static void
-remove_current_thread (void)
+remove_current_thread (void *dummy __attribute__ ((unused)))
{
struct __go_thread_id *list_entry;
MCache *mcache;
@@ -92,7 +92,7 @@ remove_current_thread (void)
if (list_entry->next != NULL)
list_entry->next->prev = list_entry->prev;
- /* This will look runtime_mheap as needed. */
+ /* This will lock runtime_mheap as needed. */
runtime_MCache_ReleaseAll (mcache);
/* This should never deadlock--there shouldn't be any code that
@@ -139,6 +139,8 @@ start_go_thread (void *thread_arg)
m = newm;
+ pthread_cleanup_push (remove_current_thread, NULL);
+
list_entry = newm->list_entry;
pfn = list_entry->pfn;
@@ -166,7 +168,7 @@ start_go_thread (void *thread_arg)
(*pfn) (arg);
- remove_current_thread ();
+ pthread_cleanup_pop (1);
return NULL;
}
@@ -178,11 +180,14 @@ void Goexit (void) asm ("libgo_runtime.runtime.Goexit");
void
Goexit (void)
{
- remove_current_thread ();
pthread_exit (NULL);
abort ();
}
+/* Count of threads created. */
+
+static volatile int mcount;
+
/* Implement the go statement. */
void
@@ -224,6 +229,9 @@ __go_go (void (*pfn) (void*), void *arg)
newm->list_entry = list_entry;
+ newm->id = __sync_fetch_and_add (&mcount, 1);
+ newm->fastrand = 0x49f6428aUL + newm->id;
+
newm->mcache = runtime_allocmcache ();
/* Add the thread to the list of all threads, marked as tentative
@@ -536,12 +544,17 @@ __go_cachestats (void)
for (p = __go_all_thread_ids; p != NULL; p = p->next)
{
MCache *c;
+ int i;
+ runtime_purgecachedstats(p->m);
c = p->m->mcache;
- mstats.heap_alloc += c->local_alloc;
- c->local_alloc = 0;
- mstats.heap_objects += c->local_objects;
- c->local_objects = 0;
+ for (i = 0; i < NumSizeClasses; ++i)
+ {
+ mstats.by_size[i].nmalloc += c->local_by_size[i].nmalloc;
+ c->local_by_size[i].nmalloc = 0;
+ mstats.by_size[i].nfree += c->local_by_size[i].nfree;
+ c->local_by_size[i].nfree = 0;
+ }
}
}
OpenPOWER on IntegriCloud