Date: Sun, 30 Sep 2012 13:32:49 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r241071 - stable/9/sys/kern Message-ID: <201209301332.q8UDWn7R038510@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Sun Sep 30 13:32:48 2012 New Revision: 241071 URL: http://svn.freebsd.org/changeset/base/241071 Log: MFC r240813: Do not skip two elements of the tid_buffer when reusing the buffer slot. This eventually results in exhaustion of the tid space, causing new threads get tid -1 as identifier. MFC r240951: Make the updates of the tid ring buffer' head and tail pointers explicit by moving them into separate statements from the buffer element accesses. Modified: stable/9/sys/kern/kern_thread.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/kern_thread.c ============================================================================== --- stable/9/sys/kern/kern_thread.c Sun Sep 30 13:17:33 2012 (r241070) +++ stable/9/sys/kern/kern_thread.c Sun Sep 30 13:32:48 2012 (r241071) @@ -102,8 +102,8 @@ tid_alloc(void) mtx_unlock(&tid_lock); return (-1); } - tid = tid_buffer[tid_head++]; - tid_head %= TID_BUFFER_SIZE; + tid = tid_buffer[tid_head]; + tid_head = (tid_head + 1) % TID_BUFFER_SIZE; mtx_unlock(&tid_lock); return (tid); } @@ -115,11 +115,11 @@ tid_free(lwpid_t tid) mtx_lock(&tid_lock); if ((tid_tail + 1) % TID_BUFFER_SIZE == tid_head) { - tmp_tid = tid_buffer[tid_head++]; + tmp_tid = tid_buffer[tid_head]; tid_head = (tid_head + 1) % TID_BUFFER_SIZE; } - tid_buffer[tid_tail++] = tid; - tid_tail %= TID_BUFFER_SIZE; + tid_buffer[tid_tail] = tid; + tid_tail = (tid_tail + 1) % TID_BUFFER_SIZE; mtx_unlock(&tid_lock); if (tmp_tid != -1) free_unr(tid_unrhdr, tmp_tid);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209301332.q8UDWn7R038510>