From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2236 invoked by alias); 4 Nov 2002 20:11:49 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 2229 invoked from network); 4 Nov 2002 20:11:49 -0000 Received: from unknown (HELO mx2.redhat.com) (12.150.115.133) by sources.redhat.com with SMTP; 4 Nov 2002 20:11:49 -0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.11.6/8.11.6) with ESMTP id gA4KAJP16731; Mon, 4 Nov 2002 15:10:19 -0500 Received: from potter.sfbay.redhat.com (potter.sfbay.redhat.com [172.16.27.15]) by int-mx2.corp.redhat.com (8.11.6/8.11.6) with ESMTP id gA4KBkl27856; Mon, 4 Nov 2002 15:11:47 -0500 Received: from dhcp-172-16-25-153.sfbay.redhat.com (dhcp-172-16-25-153.sfbay.redhat.com [172.16.25.153]) by potter.sfbay.redhat.com (8.11.6/8.11.6) with ESMTP id gA4KBkD05077; Mon, 4 Nov 2002 12:11:46 -0800 Subject: Re: [basic-improvements] Remove __gthread_key_dtor From: Eric Christopher To: Zack Weinberg Cc: Richard Henderson , gcc-patches@gcc.gnu.org In-Reply-To: <20021101001223.GK5766@codesourcery.com> References: <20021029223346.GB31573@codesourcery.com> <20021031191828.GU4764@redhat.com> <20021031194229.GB5766@codesourcery.com> <20021031210229.GA5029@redhat.com> <20021031212027.GH5766@codesourcery.com> <1036103481.1438.70.camel@ghostwheel> <20021101001223.GK5766@codesourcery.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Mon, 04 Nov 2002 12:11:00 -0000 Message-Id: <1036442469.1509.22.camel@ghostwheel> Mime-Version: 1.0 X-SW-Source: 2002-11/txt/msg00188.txt.bz2 Zack, > > > static void *key_value[THR_ID_NUM][KEY_NUM] = { { 0 }, { 0 } }; > > static int key_use[KEY_NUM] = { 0 }; > > > > /* Mutex for locking key bitmap. */ > > static __gthread_mutex_t key_mutex; > > There needs to be just one version of these variables, but gthr.h is > included all over the place - this needs to go out-of-line, into a > libgcc.a extra part, probably along with the code that uses it. > Hrm. I was noticing that other ports use this method and that's why I did - I also didn't see a way for it to work otherwise since there's no general .c mechanism for it. > I take it there can be only 256 threads? > Heh. Threads? No. I've got semaphores and only semaphores. > > static inline int > > __gthread_once (__gthread_once_t *once, void (*func) ()) > > { > > return 0; > > } > > You're going to want a real version of this function. It's used in > the unwinder, but also... > OK. > > static inline int > > __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *)) > > { > > int i; > > > > __gthread_mutex_lock (&key_mutex); > > for (i = 0; i < KEY_NUM; i++) > > { > > if (!key_use[i] && dtor != 0) > > { > > key_use[i] = 1; > > __gthread_mutex_unlock (&key_mutex); > > *keyp = i; > > return 0; > > } > > } > > __gthread_mutex_unlock (&key_mutex); > > return -1; > > } > > where does key_mutex get initialized? I have the same requirement on > mutexes in VxWorks (must use an initialization function) and wound up > using __gthread_once to call __gthread_mutex_init_function on the > mutex used to protect the keys table. > oops. thanks :) > There is no requirement that dtor be nonzero, and you threw away its > value; this will cause memory leaks. You're going to need to find > some way to get a callback run at thread exit time. And that callback > can do the clear-out-the-value thing. > hrm. If I could do that I could also free semaphores which would help me avoid the 253 limit that I currently have. I was under the impression that this was not possible though - at least not without rewriting the machinery. > > static inline int > > __gthread_setspecific (__gthread_key_t key, const void *ptr) > > { > > if (key > KEY_NUM || !key_use[key]) > > return -1; > > > > key_value[GetThreadId ()][key] = (void *)ptr; > > return 0; > > } > > This races with key_delete. You'll have to have it take the lock, too. > Thanks. -eric -- Yeah, I used to play basketball...