svn commit: trunk/uClibc/libpthread/linuxthreads

vapier at uclibc.org vapier at uclibc.org
Thu Sep 8 03:41:41 UTC 2005


Author: vapier
Date: 2005-09-07 20:41:40 -0700 (Wed, 07 Sep 2005)
New Revision: 11392

Log:
sync with glibc coding style to make further updates easier

Modified:
   trunk/uClibc/libpthread/linuxthreads/specific.c


Changeset:
Modified: trunk/uClibc/libpthread/linuxthreads/specific.c
===================================================================
--- trunk/uClibc/libpthread/linuxthreads/specific.c	2005-09-08 03:28:24 UTC (rev 11391)
+++ trunk/uClibc/libpthread/linuxthreads/specific.c	2005-09-08 03:41:40 UTC (rev 11392)
@@ -42,40 +42,41 @@
 
 int pthread_key_create(pthread_key_t * key, destr_function destr)
 {
-    int i;
+  int i;
 
-    pthread_mutex_lock(&pthread_keys_mutex);
-    for (i = 0; i < PTHREAD_KEYS_MAX; i++) {
-	if (! pthread_keys[i].in_use) {
-	    /* Mark key in use */
-	    pthread_keys[i].in_use = 1;
-	    pthread_keys[i].destr = destr;
-	    pthread_mutex_unlock(&pthread_keys_mutex);
-	    *key = i;
-	    return 0;
-	}
+  pthread_mutex_lock(&pthread_keys_mutex);
+  for (i = 0; i < PTHREAD_KEYS_MAX; i++) {
+    if (! pthread_keys[i].in_use) {
+      /* Mark key in use */
+      pthread_keys[i].in_use = 1;
+      pthread_keys[i].destr = destr;
+      pthread_mutex_unlock(&pthread_keys_mutex);
+      *key = i;
+      return 0;
     }
-    pthread_mutex_unlock(&pthread_keys_mutex);
-    return EAGAIN;
+  }
+  pthread_mutex_unlock(&pthread_keys_mutex);
+  return EAGAIN;
 }
 
 /* Delete a key */
 int pthread_key_delete(pthread_key_t key)
 {
-    pthread_descr self = thread_self();
+  pthread_descr self = thread_self();
 
-    pthread_mutex_lock(&pthread_keys_mutex);
-    if (key >= PTHREAD_KEYS_MAX || !pthread_keys[key].in_use) {
-	pthread_mutex_unlock(&pthread_keys_mutex);
-	return EINVAL;
-    }
-    pthread_keys[key].in_use = 0;
-    pthread_keys[key].destr = NULL;
+  pthread_mutex_lock(&pthread_keys_mutex);
+  if (key >= PTHREAD_KEYS_MAX || !pthread_keys[key].in_use) {
+    pthread_mutex_unlock(&pthread_keys_mutex);
+    return EINVAL;
+  }
+  pthread_keys[key].in_use = 0;
+  pthread_keys[key].destr = NULL;
 
-    /* Set the value of the key to NULL in all running threads, so
-       that if the key is reallocated later by pthread_key_create, its
-       associated values will be NULL in all threads.
-       Do nothing if no threads have been created yet.  */
+  /* Set the value of the key to NULL in all running threads, so
+     that if the key is reallocated later by pthread_key_create, its
+     associated values will be NULL in all threads.
+     Do nothing if no threads have been created yet.  */
+
     if (__pthread_manager_request != -1)
     {
 	pthread_descr th;
@@ -87,98 +88,101 @@
 	do {
 	    /* If the thread already is terminated don't modify the memory.  */
 	    if (!th->p_terminated && th->p_specific[idx1st] != NULL)
-		th->p_specific[idx1st][idx2nd] = NULL;
-	    th = th->p_nextlive;
-	} while (th != self);
-    }
+        th->p_specific[idx1st][idx2nd] = NULL;
+        th = th->p_nextlive;
+    } while (th != self);
+  }
 
-    pthread_mutex_unlock(&pthread_keys_mutex);
-    return 0;
+  pthread_mutex_unlock(&pthread_keys_mutex);
+  return 0;
 }
 
 /* Set the value of a key */
 
 int pthread_setspecific(pthread_key_t key, const void * pointer)
 {
-    pthread_descr self = thread_self();
-    unsigned int idx1st, idx2nd;
+  pthread_descr self = thread_self();
+  unsigned int idx1st, idx2nd;
 
-    if (key >= PTHREAD_KEYS_MAX || !pthread_keys[key].in_use)
-	return EINVAL;
-    idx1st = key / PTHREAD_KEY_2NDLEVEL_SIZE;
-    idx2nd = key % PTHREAD_KEY_2NDLEVEL_SIZE;
-    if (THREAD_GETMEM_NC(self, p_specific[idx1st]) == NULL) {
-	void *newp = calloc(PTHREAD_KEY_2NDLEVEL_SIZE, sizeof (void *));
-	if (newp == NULL)
-	    return ENOMEM;
-	THREAD_SETMEM_NC(self, p_specific[idx1st], newp);
-    }
-    THREAD_GETMEM_NC(self, p_specific[idx1st])[idx2nd] = (void *) pointer;
-    return 0;
+  if (key >= PTHREAD_KEYS_MAX || !pthread_keys[key].in_use)
+    return EINVAL;
+  idx1st = key / PTHREAD_KEY_2NDLEVEL_SIZE;
+  idx2nd = key % PTHREAD_KEY_2NDLEVEL_SIZE;
+  if (THREAD_GETMEM_NC(self, p_specific[idx1st]) == NULL) {
+    void *newp = calloc(PTHREAD_KEY_2NDLEVEL_SIZE, sizeof (void *));
+    if (newp == NULL)
+      return ENOMEM;
+    THREAD_SETMEM_NC(self, p_specific[idx1st], newp);
+  }
+  THREAD_GETMEM_NC(self, p_specific[idx1st])[idx2nd] = (void *) pointer;
+  return 0;
 }
 
+
 /* Get the value of a key */
 
 void * pthread_getspecific(pthread_key_t key)
 {
-    pthread_descr self = thread_self();
-    unsigned int idx1st, idx2nd;
+  pthread_descr self = thread_self();
+  unsigned int idx1st, idx2nd;
 
-    if (key >= PTHREAD_KEYS_MAX)
-	return NULL;
-    idx1st = key / PTHREAD_KEY_2NDLEVEL_SIZE;
-    idx2nd = key % PTHREAD_KEY_2NDLEVEL_SIZE;
-    if (THREAD_GETMEM_NC(self, p_specific[idx1st]) == NULL
-	    || !pthread_keys[key].in_use)
-	return NULL;
-    return THREAD_GETMEM_NC(self, p_specific[idx1st])[idx2nd];
+  if (key >= PTHREAD_KEYS_MAX)
+    return NULL;
+  idx1st = key / PTHREAD_KEY_2NDLEVEL_SIZE;
+  idx2nd = key % PTHREAD_KEY_2NDLEVEL_SIZE;
+  if (THREAD_GETMEM_NC(self, p_specific[idx1st]) == NULL
+      || !pthread_keys[key].in_use)
+    return NULL;
+  return THREAD_GETMEM_NC(self, p_specific[idx1st])[idx2nd];
 }
 
+
 /* Call the destruction routines on all keys */
 
 void __pthread_destroy_specifics()
 {
-    pthread_descr self = thread_self();
-    int i, j, round, found_nonzero;
-    destr_function destr;
-    void * data;
+  pthread_descr self = thread_self();
+  int i, j, round, found_nonzero;
+  destr_function destr;
+  void * data;
 
-    for (round = 0, found_nonzero = 1;
-	    found_nonzero && round < PTHREAD_DESTRUCTOR_ITERATIONS;
-	    round++) {
-	found_nonzero = 0;
-	for (i = 0; i < PTHREAD_KEY_1STLEVEL_SIZE; i++)
-	    if (THREAD_GETMEM_NC(self, p_specific[i]) != NULL)
-		for (j = 0; j < PTHREAD_KEY_2NDLEVEL_SIZE; j++) {
-		    destr = pthread_keys[i * PTHREAD_KEY_2NDLEVEL_SIZE + j].destr;
-		    data = THREAD_GETMEM_NC(self, p_specific[i])[j];
-		    if (destr != NULL && data != NULL) {
-			THREAD_GETMEM_NC(self, p_specific[i])[j] = NULL;
-			destr(data);
-			found_nonzero = 1;
-		    }
-		}
+  for (round = 0, found_nonzero = 1;
+       found_nonzero && round < PTHREAD_DESTRUCTOR_ITERATIONS;
+       round++) {
+    found_nonzero = 0;
+    for (i = 0; i < PTHREAD_KEY_1STLEVEL_SIZE; i++)
+      if (THREAD_GETMEM_NC(self, p_specific[i]) != NULL)
+        for (j = 0; j < PTHREAD_KEY_2NDLEVEL_SIZE; j++) {
+          destr = pthread_keys[i * PTHREAD_KEY_2NDLEVEL_SIZE + j].destr;
+          data = THREAD_GETMEM_NC(self, p_specific[i])[j];
+          if (destr != NULL && data != NULL) {
+            THREAD_GETMEM_NC(self, p_specific[i])[j] = NULL;
+            destr(data);
+            found_nonzero = 1;
+          }
+        }
+  }
+  __pthread_lock(THREAD_GETMEM(self, p_lock), self);
+  for (i = 0; i < PTHREAD_KEY_1STLEVEL_SIZE; i++) {
+    if (THREAD_GETMEM_NC(self, p_specific[i]) != NULL) {
+      free(THREAD_GETMEM_NC(self, p_specific[i]));
+      THREAD_SETMEM_NC(self, p_specific[i], NULL);
     }
-    __pthread_lock(THREAD_GETMEM(self, p_lock), self);
-    for (i = 0; i < PTHREAD_KEY_1STLEVEL_SIZE; i++) {
-	if (THREAD_GETMEM_NC(self, p_specific[i]) != NULL) {
-	    free(THREAD_GETMEM_NC(self, p_specific[i]));
-	    THREAD_SETMEM_NC(self, p_specific[i], NULL);
-	}
-    }
-    __pthread_unlock(THREAD_GETMEM(self, p_lock));
+  }
+  __pthread_unlock(THREAD_GETMEM(self, p_lock));
 }
 
+#if !(USE_TLS && HAVE___THREAD)
 
 /* Thread-specific data for libc. */
-#if !(USE_TLS && HAVE___THREAD)
+
 static int
 libc_internal_tsd_set(enum __libc_tsd_key_t key, const void * pointer)
 {
-    pthread_descr self = thread_self();
+  pthread_descr self = thread_self();
 
-    THREAD_SETMEM_NC(self, p_libc_specific[key], (void *) pointer);
-    return 0;
+  THREAD_SETMEM_NC(self, p_libc_specific[key], (void *) pointer);
+  return 0;
 }
 int (*__libc_internal_tsd_set)(enum __libc_tsd_key_t key, const void * pointer)
      = libc_internal_tsd_set;
@@ -186,9 +190,9 @@
 static void *
 libc_internal_tsd_get(enum __libc_tsd_key_t key)
 {
-    pthread_descr self = thread_self();
+  pthread_descr self = thread_self();
 
-    return THREAD_GETMEM_NC(self, p_libc_specific[key]);
+  return THREAD_GETMEM_NC(self, p_libc_specific[key]);
 }
 void * (*__libc_internal_tsd_get)(enum __libc_tsd_key_t key)
      = libc_internal_tsd_get;
@@ -196,8 +200,8 @@
 static void ** __attribute__ ((__const__))
 libc_internal_tsd_address (enum __libc_tsd_key_t key)
 {
-    pthread_descr self = thread_self();
-    return &self->p_libc_specific[key];
+  pthread_descr self = thread_self();
+  return &self->p_libc_specific[key];
 }
 void **(*const __libc_internal_tsd_address) (enum __libc_tsd_key_t key)
      __THROW __attribute__ ((__const__)) = libc_internal_tsd_address;




More information about the uClibc-cvs mailing list