diff Python/thread_pthread.h @ 61466:cab14be0ada1

Recorded merge of revisions 81029 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r81029 | antoine.pitrou | 2010-05-09 16:46:46 +0200 (dim., 09 mai 2010) | 3 lines Untabify C files. Will watch buildbots. ........
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 09 May 2010 15:52:27 +0000
parents 4fd3ab5fa71d
children 8e428b8e7d81
line wrap: on
line diff
--- a/Python/thread_pthread.h	Sun May 09 14:09:25 2010 +0000
+++ b/Python/thread_pthread.h	Sun May 09 15:52:27 2010 +0000
@@ -16,10 +16,10 @@
    be conditional on _POSIX_THREAD_ATTR_STACKSIZE being defined. */
 #ifdef _POSIX_THREAD_ATTR_STACKSIZE
 #ifndef THREAD_STACK_SIZE
-#define	THREAD_STACK_SIZE	0	/* use default stack size */
+#define THREAD_STACK_SIZE       0       /* use default stack size */
 #endif
 /* for safety, ensure a viable minimum stacksize */
-#define	THREAD_STACK_MIN	0x8000	/* 32kB */
+#define THREAD_STACK_MIN        0x8000  /* 32kB */
 #else  /* !_POSIX_THREAD_ATTR_STACKSIZE */
 #ifdef THREAD_STACK_SIZE
 #error "THREAD_STACK_SIZE defined but _POSIX_THREAD_ATTR_STACKSIZE undefined"
@@ -28,9 +28,9 @@
 
 /* The POSIX spec says that implementations supporting the sem_*
    family of functions must indicate this by defining
-   _POSIX_SEMAPHORES. */   
+   _POSIX_SEMAPHORES. */
 #ifdef _POSIX_SEMAPHORES
-/* On FreeBSD 4.x, _POSIX_SEMAPHORES is defined empty, so 
+/* On FreeBSD 4.x, _POSIX_SEMAPHORES is defined empty, so
    we need to add 0 to make it work there as well. */
 #if (_POSIX_SEMAPHORES+0) == -1
 #define HAVE_BROKEN_POSIX_SEMAPHORES
@@ -92,14 +92,14 @@
 
 #define MICROSECONDS_TO_TIMESPEC(microseconds, ts) \
 do { \
-	struct timeval tv; \
-	GETTIMEOFDAY(&tv); \
-	tv.tv_usec += microseconds % 1000000; \
-	tv.tv_sec += microseconds / 1000000; \
-	tv.tv_sec += tv.tv_usec / 1000000; \
-	tv.tv_usec %= 1000000; \
-	ts.tv_sec = tv.tv_sec; \
-	ts.tv_nsec = tv.tv_usec * 1000; \
+    struct timeval tv; \
+    GETTIMEOFDAY(&tv); \
+    tv.tv_usec += microseconds % 1000000; \
+    tv.tv_sec += microseconds / 1000000; \
+    tv.tv_sec += tv.tv_usec / 1000000; \
+    tv.tv_usec %= 1000000; \
+    ts.tv_sec = tv.tv_sec; \
+    ts.tv_nsec = tv.tv_usec * 1000; \
 } while(0)
 
 
@@ -119,10 +119,10 @@
  */
 
 typedef struct {
-	char             locked; /* 0=unlocked, 1=locked */
-	/* a <cond, mutex> pair to handle an acquire of a locked lock */
-	pthread_cond_t   lock_released;
-	pthread_mutex_t  mut;
+    char             locked; /* 0=unlocked, 1=locked */
+    /* a <cond, mutex> pair to handle an acquire of a locked lock */
+    pthread_cond_t   lock_released;
+    pthread_mutex_t  mut;
 } pthread_lock;
 
 #define CHECK_STATUS(name)  if (status != 0) { perror(name); error = 1; }
@@ -140,11 +140,11 @@
 static void
 PyThread__init_thread(void)
 {
-	/* DO AN INIT BY STARTING THE THREAD */
-	static int dummy = 0;
-	pthread_t thread1;
-	pthread_create(&thread1, NULL, (void *) _noop, &dummy);
-	pthread_join(thread1, NULL);
+    /* DO AN INIT BY STARTING THE THREAD */
+    static int dummy = 0;
+    pthread_t thread1;
+    pthread_create(&thread1, NULL, (void *) _noop, &dummy);
+    pthread_join(thread1, NULL);
 }
 
 #else /* !_HAVE_BSDI */
@@ -153,7 +153,7 @@
 PyThread__init_thread(void)
 {
 #if defined(_AIX) && defined(__GNUC__)
-	pthread_init();
+    pthread_init();
 #endif
 }
 
@@ -167,59 +167,59 @@
 long
 PyThread_start_new_thread(void (*func)(void *), void *arg)
 {
-	pthread_t th;
-	int status;
+    pthread_t th;
+    int status;
 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
-	pthread_attr_t attrs;
+    pthread_attr_t attrs;
 #endif
 #if defined(THREAD_STACK_SIZE)
-	size_t	tss;
+    size_t      tss;
 #endif
 
-	dprintf(("PyThread_start_new_thread called\n"));
-	if (!initialized)
-		PyThread_init_thread();
+    dprintf(("PyThread_start_new_thread called\n"));
+    if (!initialized)
+        PyThread_init_thread();
 
 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
-	if (pthread_attr_init(&attrs) != 0)
-		return -1;
+    if (pthread_attr_init(&attrs) != 0)
+        return -1;
 #endif
 #if defined(THREAD_STACK_SIZE)
-	tss = (_pythread_stacksize != 0) ? _pythread_stacksize
-					 : THREAD_STACK_SIZE;
-	if (tss != 0) {
-		if (pthread_attr_setstacksize(&attrs, tss) != 0) {
-			pthread_attr_destroy(&attrs);
-			return -1;
-		}
-	}
+    tss = (_pythread_stacksize != 0) ? _pythread_stacksize
+                                     : THREAD_STACK_SIZE;
+    if (tss != 0) {
+        if (pthread_attr_setstacksize(&attrs, tss) != 0) {
+            pthread_attr_destroy(&attrs);
+            return -1;
+        }
+    }
 #endif
 #if defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
-        pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
+    pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
 #endif
 
-	status = pthread_create(&th, 
+    status = pthread_create(&th,
 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
-				 &attrs,
+                             &attrs,
 #else
-				 (pthread_attr_t*)NULL,
+                             (pthread_attr_t*)NULL,
 #endif
-				 (void* (*)(void *))func,
-				 (void *)arg
-				 );
+                             (void* (*)(void *))func,
+                             (void *)arg
+                             );
 
 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED)
-	pthread_attr_destroy(&attrs);
+    pthread_attr_destroy(&attrs);
 #endif
-	if (status != 0)
-            return -1;
+    if (status != 0)
+        return -1;
 
-        pthread_detach(th);
+    pthread_detach(th);
 
 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG
-	return (long) th;
+    return (long) th;
 #else
-	return (long) *(long *) &th;
+    return (long) *(long *) &th;
 #endif
 }
 
@@ -230,28 +230,28 @@
      - It is not clear that the 'volatile' (for AIX?) and ugly casting in the
        latter return statement (for Alpha OSF/1) are any longer necessary.
 */
-long 
+long
 PyThread_get_thread_ident(void)
 {
-	volatile pthread_t threadid;
-	if (!initialized)
-		PyThread_init_thread();
-	/* Jump through some hoops for Alpha OSF/1 */
-	threadid = pthread_self();
+    volatile pthread_t threadid;
+    if (!initialized)
+        PyThread_init_thread();
+    /* Jump through some hoops for Alpha OSF/1 */
+    threadid = pthread_self();
 #if SIZEOF_PTHREAD_T <= SIZEOF_LONG
-	return (long) threadid;
+    return (long) threadid;
 #else
-	return (long) *(long *) &threadid;
+    return (long) *(long *) &threadid;
 #endif
 }
 
-void 
+void
 PyThread_exit_thread(void)
 {
-	dprintf(("PyThread_exit_thread called\n"));
-	if (!initialized) {
-		exit(0);
-	}
+    dprintf(("PyThread_exit_thread called\n"));
+    if (!initialized) {
+        exit(0);
+    }
 }
 
 #ifdef USE_SEMAPHORES
@@ -260,47 +260,47 @@
  * Lock support.
  */
 
-PyThread_type_lock 
+PyThread_type_lock
 PyThread_allocate_lock(void)
 {
-	sem_t *lock;
-	int status, error = 0;
+    sem_t *lock;
+    int status, error = 0;
 
-	dprintf(("PyThread_allocate_lock called\n"));
-	if (!initialized)
-		PyThread_init_thread();
+    dprintf(("PyThread_allocate_lock called\n"));
+    if (!initialized)
+        PyThread_init_thread();
 
-	lock = (sem_t *)malloc(sizeof(sem_t));
+    lock = (sem_t *)malloc(sizeof(sem_t));
 
-	if (lock) {
-		status = sem_init(lock,0,1);
-		CHECK_STATUS("sem_init");
+    if (lock) {
+        status = sem_init(lock,0,1);
+        CHECK_STATUS("sem_init");
 
-		if (error) {
-			free((void *)lock);
-			lock = NULL;
-		}
-	}
+        if (error) {
+            free((void *)lock);
+            lock = NULL;
+        }
+    }
 
-	dprintf(("PyThread_allocate_lock() -> %p\n", lock));
-	return (PyThread_type_lock)lock;
+    dprintf(("PyThread_allocate_lock() -> %p\n", lock));
+    return (PyThread_type_lock)lock;
 }
 
-void 
+void
 PyThread_free_lock(PyThread_type_lock lock)
 {
-	sem_t *thelock = (sem_t *)lock;
-	int status, error = 0;
+    sem_t *thelock = (sem_t *)lock;
+    int status, error = 0;
 
-	dprintf(("PyThread_free_lock(%p) called\n", lock));
+    dprintf(("PyThread_free_lock(%p) called\n", lock));
 
-	if (!thelock)
-		return;
+    if (!thelock)
+        return;
 
-	status = sem_destroy(thelock);
-	CHECK_STATUS("sem_destroy");
+    status = sem_destroy(thelock);
+    CHECK_STATUS("sem_destroy");
 
-	free((void *)thelock);
+    free((void *)thelock);
 }
 
 /*
@@ -312,66 +312,66 @@
 static int
 fix_status(int status)
 {
-	return (status == -1) ? errno : status;
+    return (status == -1) ? errno : status;
 }
 
 int
 PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds)
 {
-	int success;
-	sem_t *thelock = (sem_t *)lock;
-	int status, error = 0;
-	struct timespec ts;
+    int success;
+    sem_t *thelock = (sem_t *)lock;
+    int status, error = 0;
+    struct timespec ts;
 
-	dprintf(("PyThread_acquire_lock_timed(%p, %lld) called\n",
-		 lock, microseconds));
+    dprintf(("PyThread_acquire_lock_timed(%p, %lld) called\n",
+             lock, microseconds));
 
-	if (microseconds > 0)
-		MICROSECONDS_TO_TIMESPEC(microseconds, ts);
-	do {
-		if (microseconds > 0)
-			status = fix_status(sem_timedwait(thelock, &ts));
-		else if (microseconds == 0)
-			status = fix_status(sem_trywait(thelock));
-		else
-			status = fix_status(sem_wait(thelock));
-	} while (status == EINTR); /* Retry if interrupted by a signal */
+    if (microseconds > 0)
+        MICROSECONDS_TO_TIMESPEC(microseconds, ts);
+    do {
+        if (microseconds > 0)
+            status = fix_status(sem_timedwait(thelock, &ts));
+        else if (microseconds == 0)
+            status = fix_status(sem_trywait(thelock));
+        else
+            status = fix_status(sem_wait(thelock));
+    } while (status == EINTR); /* Retry if interrupted by a signal */
 
-	if (microseconds > 0) {
-		if (status != ETIMEDOUT)
-			CHECK_STATUS("sem_timedwait");
-	}
-	else if (microseconds == 0) {
-		if (status != EAGAIN)
-			CHECK_STATUS("sem_trywait");
-	}
-	else {
-		CHECK_STATUS("sem_wait");
-	}
-	
-	success = (status == 0) ? 1 : 0;
+    if (microseconds > 0) {
+        if (status != ETIMEDOUT)
+            CHECK_STATUS("sem_timedwait");
+    }
+    else if (microseconds == 0) {
+        if (status != EAGAIN)
+            CHECK_STATUS("sem_trywait");
+    }
+    else {
+        CHECK_STATUS("sem_wait");
+    }
 
-	dprintf(("PyThread_acquire_lock_timed(%p, %lld) -> %d\n",
-		 lock, microseconds, success));
-	return success;
+    success = (status == 0) ? 1 : 0;
+
+    dprintf(("PyThread_acquire_lock_timed(%p, %lld) -> %d\n",
+             lock, microseconds, success));
+    return success;
 }
 
-int 
+int
 PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
 {
-	return PyThread_acquire_lock_timed(lock, waitflag ? -1 : 0);
+    return PyThread_acquire_lock_timed(lock, waitflag ? -1 : 0);
 }
 
-void 
+void
 PyThread_release_lock(PyThread_type_lock lock)
 {
-	sem_t *thelock = (sem_t *)lock;
-	int status, error = 0;
+    sem_t *thelock = (sem_t *)lock;
+    int status, error = 0;
 
-	dprintf(("PyThread_release_lock(%p) called\n", lock));
+    dprintf(("PyThread_release_lock(%p) called\n", lock));
 
-	status = sem_post(thelock);
-	CHECK_STATUS("sem_post");
+    status = sem_post(thelock);
+    CHECK_STATUS("sem_post");
 }
 
 #else /* USE_SEMAPHORES */
@@ -379,137 +379,137 @@
 /*
  * Lock support.
  */
-PyThread_type_lock 
+PyThread_type_lock
 PyThread_allocate_lock(void)
 {
-	pthread_lock *lock;
-	int status, error = 0;
+    pthread_lock *lock;
+    int status, error = 0;
 
-	dprintf(("PyThread_allocate_lock called\n"));
-	if (!initialized)
-		PyThread_init_thread();
+    dprintf(("PyThread_allocate_lock called\n"));
+    if (!initialized)
+        PyThread_init_thread();
 
-	lock = (pthread_lock *) malloc(sizeof(pthread_lock));
-	if (lock) {
-		memset((void *)lock, '\0', sizeof(pthread_lock));
-		lock->locked = 0;
+    lock = (pthread_lock *) malloc(sizeof(pthread_lock));
+    if (lock) {
+        memset((void *)lock, '\0', sizeof(pthread_lock));
+        lock->locked = 0;
 
-		status = pthread_mutex_init(&lock->mut,
-					    pthread_mutexattr_default);
-		CHECK_STATUS("pthread_mutex_init");
-                /* Mark the pthread mutex underlying a Python mutex as
-                   pure happens-before.  We can't simply mark the
-                   Python-level mutex as a mutex because it can be
-                   acquired and released in different threads, which
-                   will cause errors. */
-		_Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(&lock->mut);
+        status = pthread_mutex_init(&lock->mut,
+                                    pthread_mutexattr_default);
+        CHECK_STATUS("pthread_mutex_init");
+        /* Mark the pthread mutex underlying a Python mutex as
+           pure happens-before.  We can't simply mark the
+           Python-level mutex as a mutex because it can be
+           acquired and released in different threads, which
+           will cause errors. */
+        _Py_ANNOTATE_PURE_HAPPENS_BEFORE_MUTEX(&lock->mut);
 
-		status = pthread_cond_init(&lock->lock_released,
-					   pthread_condattr_default);
-		CHECK_STATUS("pthread_cond_init");
+        status = pthread_cond_init(&lock->lock_released,
+                                   pthread_condattr_default);
+        CHECK_STATUS("pthread_cond_init");
 
-		if (error) {
-			free((void *)lock);
-			lock = 0;
-		}
-	}
+        if (error) {
+            free((void *)lock);
+            lock = 0;
+        }
+    }
 
-	dprintf(("PyThread_allocate_lock() -> %p\n", lock));
-	return (PyThread_type_lock) lock;
+    dprintf(("PyThread_allocate_lock() -> %p\n", lock));
+    return (PyThread_type_lock) lock;
 }
 
-void 
+void
 PyThread_free_lock(PyThread_type_lock lock)
 {
-	pthread_lock *thelock = (pthread_lock *)lock;
-	int status, error = 0;
+    pthread_lock *thelock = (pthread_lock *)lock;
+    int status, error = 0;
 
-	dprintf(("PyThread_free_lock(%p) called\n", lock));
+    dprintf(("PyThread_free_lock(%p) called\n", lock));
 
-	status = pthread_mutex_destroy( &thelock->mut );
-	CHECK_STATUS("pthread_mutex_destroy");
+    status = pthread_mutex_destroy( &thelock->mut );
+    CHECK_STATUS("pthread_mutex_destroy");
 
-	status = pthread_cond_destroy( &thelock->lock_released );
-	CHECK_STATUS("pthread_cond_destroy");
+    status = pthread_cond_destroy( &thelock->lock_released );
+    CHECK_STATUS("pthread_cond_destroy");
 
-	free((void *)thelock);
+    free((void *)thelock);
 }
 
 int
 PyThread_acquire_lock_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds)
 {
-	int success;
-	pthread_lock *thelock = (pthread_lock *)lock;
-	int status, error = 0;
+    int success;
+    pthread_lock *thelock = (pthread_lock *)lock;
+    int status, error = 0;
 
-	dprintf(("PyThread_acquire_lock_timed(%p, %lld) called\n",
-		 lock, microseconds));
+    dprintf(("PyThread_acquire_lock_timed(%p, %lld) called\n",
+             lock, microseconds));
 
-	status = pthread_mutex_lock( &thelock->mut );
-	CHECK_STATUS("pthread_mutex_lock[1]");
-	success = thelock->locked == 0;
+    status = pthread_mutex_lock( &thelock->mut );
+    CHECK_STATUS("pthread_mutex_lock[1]");
+    success = thelock->locked == 0;
 
-	if (!success && microseconds != 0) {
-		struct timespec ts;
-		if (microseconds > 0)
-			MICROSECONDS_TO_TIMESPEC(microseconds, ts);
-		/* continue trying until we get the lock */
+    if (!success && microseconds != 0) {
+        struct timespec ts;
+        if (microseconds > 0)
+            MICROSECONDS_TO_TIMESPEC(microseconds, ts);
+        /* continue trying until we get the lock */
 
-		/* mut must be locked by me -- part of the condition
-		 * protocol */
-		while (thelock->locked) {
-			if (microseconds > 0) {
-				status = pthread_cond_timedwait(
-					&thelock->lock_released,
-					&thelock->mut, &ts);
-				if (status == ETIMEDOUT)
-					break;
-				CHECK_STATUS("pthread_cond_timed_wait");
-			}
-			else {
-				status = pthread_cond_wait(
-					&thelock->lock_released,
-					&thelock->mut);
-				CHECK_STATUS("pthread_cond_wait");
-			}
-		}
-		success = (status == 0);
-	}
-	if (success) thelock->locked = 1;
-	status = pthread_mutex_unlock( &thelock->mut );
-	CHECK_STATUS("pthread_mutex_unlock[1]");
+        /* mut must be locked by me -- part of the condition
+         * protocol */
+        while (thelock->locked) {
+            if (microseconds > 0) {
+                status = pthread_cond_timedwait(
+                    &thelock->lock_released,
+                    &thelock->mut, &ts);
+                if (status == ETIMEDOUT)
+                    break;
+                CHECK_STATUS("pthread_cond_timed_wait");
+            }
+            else {
+                status = pthread_cond_wait(
+                    &thelock->lock_released,
+                    &thelock->mut);
+                CHECK_STATUS("pthread_cond_wait");
+            }
+        }
+        success = (status == 0);
+    }
+    if (success) thelock->locked = 1;
+    status = pthread_mutex_unlock( &thelock->mut );
+    CHECK_STATUS("pthread_mutex_unlock[1]");
 
-	if (error) success = 0;
-	dprintf(("PyThread_acquire_lock_timed(%p, %lld) -> %d\n",
-		 lock, microseconds, success));
-	return success;
+    if (error) success = 0;
+    dprintf(("PyThread_acquire_lock_timed(%p, %lld) -> %d\n",
+             lock, microseconds, success));
+    return success;
 }
 
-int 
+int
 PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)
 {
-	return PyThread_acquire_lock_timed(lock, waitflag ? -1 : 0);
+    return PyThread_acquire_lock_timed(lock, waitflag ? -1 : 0);
 }
 
-void 
+void
 PyThread_release_lock(PyThread_type_lock lock)
 {
-	pthread_lock *thelock = (pthread_lock *)lock;
-	int status, error = 0;
+    pthread_lock *thelock = (pthread_lock *)lock;
+    int status, error = 0;
 
-	dprintf(("PyThread_release_lock(%p) called\n", lock));
+    dprintf(("PyThread_release_lock(%p) called\n", lock));
 
-	status = pthread_mutex_lock( &thelock->mut );
-	CHECK_STATUS("pthread_mutex_lock[3]");
+    status = pthread_mutex_lock( &thelock->mut );
+    CHECK_STATUS("pthread_mutex_lock[3]");
 
-	thelock->locked = 0;
+    thelock->locked = 0;
 
-	status = pthread_mutex_unlock( &thelock->mut );
-	CHECK_STATUS("pthread_mutex_unlock[3]");
+    status = pthread_mutex_unlock( &thelock->mut );
+    CHECK_STATUS("pthread_mutex_unlock[3]");
 
-	/* wake up someone (anyone, if any) waiting on the lock */
-	status = pthread_cond_signal( &thelock->lock_released );
-	CHECK_STATUS("pthread_cond_signal");
+    /* wake up someone (anyone, if any) waiting on the lock */
+    status = pthread_cond_signal( &thelock->lock_released );
+    CHECK_STATUS("pthread_cond_signal");
 }
 
 #endif /* USE_SEMAPHORES */
@@ -522,39 +522,39 @@
 _pythread_pthread_set_stacksize(size_t size)
 {
 #if defined(THREAD_STACK_SIZE)
-	pthread_attr_t attrs;
-	size_t tss_min;
-	int rc = 0;
+    pthread_attr_t attrs;
+    size_t tss_min;
+    int rc = 0;
 #endif
 
-	/* set to default */
-	if (size == 0) {
-		_pythread_stacksize = 0;
-		return 0;
-	}
+    /* set to default */
+    if (size == 0) {
+        _pythread_stacksize = 0;
+        return 0;
+    }
 
 #if defined(THREAD_STACK_SIZE)
 #if defined(PTHREAD_STACK_MIN)
-	tss_min = PTHREAD_STACK_MIN > THREAD_STACK_MIN ? PTHREAD_STACK_MIN
-						       : THREAD_STACK_MIN;
+    tss_min = PTHREAD_STACK_MIN > THREAD_STACK_MIN ? PTHREAD_STACK_MIN
+                                                   : THREAD_STACK_MIN;
 #else
-	tss_min = THREAD_STACK_MIN;
+    tss_min = THREAD_STACK_MIN;
 #endif
-	if (size >= tss_min) {
-		/* validate stack size by setting thread attribute */
-		if (pthread_attr_init(&attrs) == 0) {
-			rc = pthread_attr_setstacksize(&attrs, size);
-			pthread_attr_destroy(&attrs);
-			if (rc == 0) {
-				_pythread_stacksize = size;
-				return 0;
-			}
-		}
-	}
-	return -1;
+    if (size >= tss_min) {
+        /* validate stack size by setting thread attribute */
+        if (pthread_attr_init(&attrs) == 0) {
+            rc = pthread_attr_setstacksize(&attrs, size);
+            pthread_attr_destroy(&attrs);
+            if (rc == 0) {
+                _pythread_stacksize = size;
+                return 0;
+            }
+        }
+    }
+    return -1;
 #else
-	return -2;
+    return -2;
 #endif
 }
 
-#define THREAD_SET_STACKSIZE(x)	_pythread_pthread_set_stacksize(x)
+#define THREAD_SET_STACKSIZE(x) _pythread_pthread_set_stacksize(x)