summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--errno.c13
-rw-r--r--pthread.h9
-rw-r--r--tests/Makefile3
-rw-r--r--tests/Template.c1
-rw-r--r--tests/errno1.c145
-rw-r--r--tests/runall.bat1
7 files changed, 167 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index f3655c2..f3ff6db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Apr 7 14:09:52 1999 Ross Johnson <rpj@swan.canberra.edu.au>
+
+ * errno.c (_REENTRANT || _MT): Invert condition.
+
+ * pthread.h (_errno): Conditionally include prototype.
+
Wed Apr 7 09:37:00 1999 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* *.c (comments): Remove individual attributions - these are
diff --git a/errno.c b/errno.c
index e6cf5e7..69fdddd 100644
--- a/errno.c
+++ b/errno.c
@@ -24,7 +24,7 @@
* MA 02111-1307, USA
*/
-#if defined( _REENTRANT ) || defined( _MT )
+#if ! defined( _REENTRANT ) && ! defined( _MT )
#include "pthread.h"
#include "implement.h"
@@ -45,8 +45,7 @@ static int reallyBad = ENOMEM;
* it on thread termination. We get all that for free
* by simply storing the errno on the pthread_t structure.
*
- * Relies on the following being defined in errno.h:
- * (true for MSVC and Mingw32 I think)
+ * MSVC and Mingw32 already have there own thread-safe errno.
*
* #if defined( _REENTRANT ) || defined( _MT )
* #define errno *_errno()
@@ -54,7 +53,7 @@ static int reallyBad = ENOMEM;
* int *_errno( void );
* #else
* extern int errno;
- * #endif /* _REENTRANT */
+ * #endif
*
*/
@@ -80,8 +79,4 @@ int * _errno( void )
} /* _errno */
-#else
-
-#error "errno: Not thread-safe."
-
-#endif /* _REENTRANT || _MT */
+#endif /* !_REENTRANT && !_MT */
diff --git a/pthread.h b/pthread.h
index 8995558..8ce4d5e 100644
--- a/pthread.h
+++ b/pthread.h
@@ -862,7 +862,13 @@ int pthreadCancelableWait (HANDLE waitHandle);
int pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout);
/*
- * Thread-Safe C Runtime Library Mappings
+ * Thread-Safe C Runtime Library Mappings.
+ */
+#if ! defined( _REENTRANT ) && ! defined( _MT )
+int * _errno( void );
+#endif
+
+/*
* WIN32 C runtime library had been made thread-safe
* without affecting the user interface. Provide
* mappings from the UNIX thread-safe versions to
@@ -870,6 +876,7 @@ int pthreadCancelableTimedWait (HANDLE waitHandle, DWORD timeout);
* Only provide function mappings for functions that
* actually exist on WIN32.
*/
+
#if !defined(__MINGW32__)
#define strtok_r( _s, _sep, _lasts ) \
( *(_lasts) = strtok( (_s), (_sep) ) )
diff --git a/tests/Makefile b/tests/Makefile
index a696bf9..21309e5 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -39,7 +39,7 @@ TESTS = mutex1 condvar1 condvar2 exit1 create1 equal1 \
exit2 exit3 \
join1 mutex2 mutex3 \
count1 once1 tsd1 self1 self2 eyal1 \
- condvar3 condvar4
+ condvar3 condvar4 errno1
PASSES = $(TESTS:%=%.pass)
@@ -65,6 +65,7 @@ self2.pass: create1.pass
eyal1.pass: tsd1.pass
condvar3.pass: create1.pass
condvar4.pass: create1.pass
+errno1.pass: mutex3.pass
%.pass: %.exe $(LIB) $(DLL) $(HDR)
$*
diff --git a/tests/Template.c b/tests/Template.c
index c98bbac..4bee7e1 100644
--- a/tests/Template.c
+++ b/tests/Template.c
@@ -75,6 +75,7 @@ int
main()
{
int failed = 0;
+ int i;
pthread_t t[NUMTHREADS + 1];
assert((t[0] = pthread_self()) != NULL);
diff --git a/tests/errno1.c b/tests/errno1.c
new file mode 100644
index 0000000..983b37c
--- /dev/null
+++ b/tests/errno1.c
@@ -0,0 +1,145 @@
+/*
+ * File: errn1.c
+ *
+ * Test Synopsis: Test thread-safety of errno
+ * -
+ *
+ * Test Method (Validation or Falsification):
+ * - Validation
+ *
+ * Requirements Tested:
+ * -
+ *
+ * Features Tested:
+ * -
+ *
+ * Cases Tested:
+ * -
+ *
+ * Description:
+ * -
+ *
+ * Environment:
+ * -
+ *
+ * Input:
+ * - None.
+ *
+ * Output:
+ * - File name, Line number, and failed expression on failure.
+ * - No output on success.
+ *
+ * Assumptions:
+ * -
+ *
+ * Pass Criteria:
+ * - Process returns zero exit status.
+ *
+ * Fail Criteria:
+ * - Process returns non-zero exit status.
+ */
+
+#include "test.h"
+
+/*
+ * Create NUMTHREADS threads in addition to the Main thread.
+ */
+enum {
+ NUMTHREADS = 3
+};
+
+typedef struct bag_t_ bag_t;
+struct bag_t_ {
+ int threadnum;
+ int started;
+ /* Add more per-thread state variables here */
+};
+
+static bag_t threadbag[NUMTHREADS + 1];
+
+pthread_mutex_t stop_here = PTHREAD_MUTEX_INITIALIZER;
+
+void *
+mythread(void * arg)
+{
+ bag_t * bag = (bag_t *) arg;
+
+ assert(bag == &threadbag[bag->threadnum]);
+ assert(bag->started == 0);
+ bag->started = 1;
+
+ errno = bag->threadnum;
+
+ Sleep(1000);
+
+ pthread_mutex_lock(&stop_here);
+
+ assert(errno == bag->threadnum);
+
+ pthread_mutex_unlock(&stop_here);
+
+ Sleep(1000);
+
+ return 0;
+}
+
+int
+main()
+{
+ int failed = 0;
+ int i;
+ pthread_t t[NUMTHREADS + 1];
+
+ pthread_mutex_lock(&stop_here);
+ errno = 0;
+
+ assert((t[0] = pthread_self()) != NULL);
+
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ threadbag[i].started = 0;
+ threadbag[i].threadnum = i;
+ assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
+ }
+
+ /*
+ * Code to control or munipulate child threads should probably go here.
+ */
+ Sleep(2000);
+ pthread_mutex_unlock(&stop_here);
+
+ /*
+ * Give threads time to run.
+ */
+ Sleep(NUMTHREADS * 1000);
+
+ /*
+ * Standard check that all threads started.
+ */
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ failed = !threadbag[i].started;
+
+ if (failed)
+ {
+ fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
+ }
+ }
+
+ assert(!failed);
+
+ /*
+ * Check any results here. Set "failed" and only print ouput on failure.
+ */
+ for (i = 1; i <= NUMTHREADS; i++)
+ {
+ /* ... */
+ }
+
+ assert(!failed);
+
+ /*
+ * Success.
+ */
+ return 0;
+}
diff --git a/tests/runall.bat b/tests/runall.bat
index 3f5498d..f061f3a 100644
--- a/tests/runall.bat
+++ b/tests/runall.bat
@@ -21,3 +21,4 @@ call runtest cl self2
call runtest cl eyal1
call runtest cl condvar3
call runtest cl condvar4
+call runtest cl errno1