├── ANNOUNCE
├── BUGS
├── Bmakefile
├── CONTRIBUTORS
├── ChangeLog
├── FAQ
├── GNUmakefile.in
├── LICENSE
├── MAINTAINERS
├── Makefile
├── NEWS
├── NOTICE
├── Nmakefile
├── Nmakefile.tests
├── PROGRESS
├── README
├── README.Borland
├── README.CV
├── README.NONPORTABLE
├── README.Watcom
├── README.WinCE
├── TODO
├── WinCE-PORT
├── _ptw32.h
├── aclocal.m4
├── build.vc14
├── pthreads.sln
├── pthreads_dll
│ ├── postbuild.bat
│ ├── pthreads_dll.vcxproj
│ └── pthreads_dll.vcxproj.filters
└── pthreads_lib
│ ├── postbuild.bat
│ ├── pthreads_lib.vcxproj
│ └── pthreads_lib.vcxproj.filters
├── build.vc15
├── pthreads.sln
├── pthreads_dll
│ ├── postbuild.bat
│ ├── pthreads_dll.vcxproj
│ └── pthreads_dll.vcxproj.filters
└── pthreads_lib
│ ├── postbuild.bat
│ ├── pthreads_lib.vcxproj
│ └── pthreads_lib.vcxproj.filters
├── build.vc16
├── pthreads.sln
├── pthreads_dll
│ ├── postbuild.bat
│ ├── pthreads_dll.vcxproj
│ └── pthreads_dll.vcxproj.filters
└── pthreads_lib
│ ├── postbuild.bat
│ ├── pthreads_lib.vcxproj
│ └── pthreads_lib.vcxproj.filters
├── build.vs
├── build_tests
│ ├── _msvccompiler.py
│ ├── build_tests.py
│ └── build_tests.pyproj
├── pthreads.sln
├── pthreads_dll
│ ├── postbuild.bat
│ ├── pthreads_dll.vcxproj
│ └── pthreads_dll.vcxproj.filters
├── pthreads_lib
│ ├── postbuild.bat
│ ├── pthreads_lib.vcxproj
│ └── pthreads_lib.vcxproj.filters
└── run_tests
│ ├── run_tests.py
│ └── run_tests.pyproj
├── builddmc.bat
├── cleanup.c
├── common.mk
├── config.h
├── configure.ac
├── context.h
├── create.c
├── dll.c
├── errno.c
├── global.c
├── implement.h
├── install-sh
├── manual
├── ChangeLog
├── PortabilityIssues.html
├── cpu_set.html
├── index.html
├── pthreadCancelableWait.html
├── pthread_attr_init.html
├── pthread_attr_setstackaddr.html
├── pthread_attr_setstacksize.html
├── pthread_barrier_init.html
├── pthread_barrier_wait.html
├── pthread_barrierattr_init.html
├── pthread_barrierattr_setpshared.html
├── pthread_cancel.html
├── pthread_cleanup_push.html
├── pthread_cond_init.html
├── pthread_condattr_init.html
├── pthread_condattr_setpshared.html
├── pthread_create.html
├── pthread_delay_np.html
├── pthread_detach.html
├── pthread_equal.html
├── pthread_exit.html
├── pthread_getunique_np.html
├── pthread_getw32threadhandle_np.html
├── pthread_join.html
├── pthread_key_create.html
├── pthread_kill.html
├── pthread_mutex_init.html
├── pthread_mutexattr_init.html
├── pthread_mutexattr_setpshared.html
├── pthread_num_processors_np.html
├── pthread_once.html
├── pthread_rwlock_init.html
├── pthread_rwlock_rdlock.html
├── pthread_rwlock_timedrdlock.html
├── pthread_rwlock_timedwrlock.html
├── pthread_rwlock_unlock.html
├── pthread_rwlock_wrlock.html
├── pthread_rwlockattr_init.html
├── pthread_rwlockattr_setpshared.html
├── pthread_self.html
├── pthread_setaffinity_np.html
├── pthread_setcancelstate.html
├── pthread_setcanceltype.html
├── pthread_setconcurrency.html
├── pthread_setname_np.html
├── pthread_setschedparam.html
├── pthread_spin_init.html
├── pthread_spin_lock.html
├── pthread_spin_unlock.html
├── pthread_timechange_handler_np.html
├── pthread_win32_attach_detach_np.html
├── pthread_win32_getabstime_np.html
├── pthread_win32_test_features_np.html
├── sched_get_priority_max.html
├── sched_getscheduler.html
├── sched_setaffinity.html
├── sched_setscheduler.html
├── sched_yield.html
└── sem_init.html
├── need_errno.h
├── pthread.c
├── pthread.h
├── pthread_attr_destroy.c
├── pthread_attr_getaffinity_np.c
├── pthread_attr_getdetachstate.c
├── pthread_attr_getinheritsched.c
├── pthread_attr_getname_np.c
├── pthread_attr_getschedparam.c
├── pthread_attr_getschedpolicy.c
├── pthread_attr_getscope.c
├── pthread_attr_getstackaddr.c
├── pthread_attr_getstacksize.c
├── pthread_attr_init.c
├── pthread_attr_setaffinity_np.c
├── pthread_attr_setdetachstate.c
├── pthread_attr_setinheritsched.c
├── pthread_attr_setname_np.c
├── pthread_attr_setschedparam.c
├── pthread_attr_setschedpolicy.c
├── pthread_attr_setscope.c
├── pthread_attr_setstackaddr.c
├── pthread_attr_setstacksize.c
├── pthread_barrier_destroy.c
├── pthread_barrier_init.c
├── pthread_barrier_wait.c
├── pthread_barrierattr_destroy.c
├── pthread_barrierattr_getpshared.c
├── pthread_barrierattr_init.c
├── pthread_barrierattr_setpshared.c
├── pthread_cancel.c
├── pthread_cond_destroy.c
├── pthread_cond_init.c
├── pthread_cond_signal.c
├── pthread_cond_wait.c
├── pthread_condattr_destroy.c
├── pthread_condattr_getpshared.c
├── pthread_condattr_init.c
├── pthread_condattr_setpshared.c
├── pthread_delay_np.c
├── pthread_detach.c
├── pthread_equal.c
├── pthread_exit.c
├── pthread_getconcurrency.c
├── pthread_getname_np.c
├── pthread_getschedparam.c
├── pthread_getspecific.c
├── pthread_getunique_np.c
├── pthread_getw32threadhandle_np.c
├── pthread_join.c
├── pthread_key_create.c
├── pthread_key_delete.c
├── pthread_kill.c
├── pthread_mutex_consistent.c
├── pthread_mutex_destroy.c
├── pthread_mutex_init.c
├── pthread_mutex_lock.c
├── pthread_mutex_timedlock.c
├── pthread_mutex_trylock.c
├── pthread_mutex_unlock.c
├── pthread_mutexattr_destroy.c
├── pthread_mutexattr_getkind_np.c
├── pthread_mutexattr_getpshared.c
├── pthread_mutexattr_getrobust.c
├── pthread_mutexattr_gettype.c
├── pthread_mutexattr_init.c
├── pthread_mutexattr_setkind_np.c
├── pthread_mutexattr_setpshared.c
├── pthread_mutexattr_setrobust.c
├── pthread_mutexattr_settype.c
├── pthread_num_processors_np.c
├── pthread_once.c
├── pthread_rwlock_destroy.c
├── pthread_rwlock_init.c
├── pthread_rwlock_rdlock.c
├── pthread_rwlock_timedrdlock.c
├── pthread_rwlock_timedwrlock.c
├── pthread_rwlock_tryrdlock.c
├── pthread_rwlock_trywrlock.c
├── pthread_rwlock_unlock.c
├── pthread_rwlock_wrlock.c
├── pthread_rwlockattr_destroy.c
├── pthread_rwlockattr_getpshared.c
├── pthread_rwlockattr_init.c
├── pthread_rwlockattr_setpshared.c
├── pthread_self.c
├── pthread_setaffinity.c
├── pthread_setcancelstate.c
├── pthread_setcanceltype.c
├── pthread_setconcurrency.c
├── pthread_setname_np.c
├── pthread_setschedparam.c
├── pthread_setspecific.c
├── pthread_spin_destroy.c
├── pthread_spin_init.c
├── pthread_spin_lock.c
├── pthread_spin_trylock.c
├── pthread_spin_unlock.c
├── pthread_testcancel.c
├── pthread_timechange_handler_np.c
├── pthread_timedjoin_np.c
├── pthread_tryjoin_np.c
├── pthread_win32_attach_detach_np.c
├── ptw32_MCS_lock.c
├── ptw32_callUserDestroyRoutines.c
├── ptw32_calloc.c
├── ptw32_cond_check_need_init.c
├── ptw32_getprocessors.c
├── ptw32_is_attr.c
├── ptw32_mutex_check_need_init.c
├── ptw32_new.c
├── ptw32_processInitialize.c
├── ptw32_processTerminate.c
├── ptw32_relmillisecs.c
├── ptw32_reuse.c
├── ptw32_rwlock_cancelwrwait.c
├── ptw32_rwlock_check_need_init.c
├── ptw32_semwait.c
├── ptw32_spinlock_check_need_init.c
├── ptw32_threadDestroy.c
├── ptw32_threadStart.c
├── ptw32_throw.c
├── ptw32_timespec.c
├── ptw32_tkAssocCreate.c
├── ptw32_tkAssocDestroy.c
├── sched.h
├── sched_get_priority_max.c
├── sched_get_priority_min.c
├── sched_getscheduler.c
├── sched_setaffinity.c
├── sched_setscheduler.c
├── sched_yield.c
├── sem_close.c
├── sem_destroy.c
├── sem_getvalue.c
├── sem_init.c
├── sem_open.c
├── sem_post.c
├── sem_post_multiple.c
├── sem_timedwait.c
├── sem_trywait.c
├── sem_unlink.c
├── sem_wait.c
├── semaphore.h
├── signal.c
├── tests
├── Bmakefile
├── ChangeLog
├── Debug.dsp
├── Debug.dsw
├── Debug.plg
├── Debug.txt
├── GNUmakefile.in
├── Makefile
├── README
├── README.BENCHTESTS
├── Wmakefile
├── affinity1.c
├── affinity2.c
├── affinity3.c
├── affinity4.c
├── affinity5.c
├── affinity6.c
├── barrier1.c
├── barrier2.c
├── barrier3.c
├── barrier4.c
├── barrier5.c
├── barrier6.c
├── benchlib.c
├── benchtest.h
├── benchtest1.c
├── benchtest2.c
├── benchtest3.c
├── benchtest4.c
├── benchtest5.c
├── cancel1.c
├── cancel2.c
├── cancel3.c
├── cancel4.c
├── cancel5.c
├── cancel6a.c
├── cancel6d.c
├── cancel7.c
├── cancel8.c
├── cancel9.c
├── cleanup0.c
├── cleanup1.c
├── cleanup2.c
├── cleanup3.c
├── common.mk
├── condvar1.c
├── condvar1_1.c
├── condvar1_2.c
├── condvar2.c
├── condvar2_1.c
├── condvar3.c
├── condvar3_1.c
├── condvar3_2.c
├── condvar3_3.c
├── condvar4.c
├── condvar5.c
├── condvar6.c
├── condvar7.c
├── condvar8.c
├── condvar9.c
├── context1.c
├── context2.c
├── count1.c
├── create1.c
├── create2.c
├── create3.c
├── delay1.c
├── delay2.c
├── detach1.c
├── equal1.c
├── errno0.c
├── errno1.c
├── exception1.c
├── exception2.c
├── exception3.c
├── exception3_0.c
├── exit1.c
├── exit2.c
├── exit3.c
├── exit4.c
├── exit5.c
├── exit6.c
├── eyal1.c
├── inherit1.c
├── join0.c
├── join1.c
├── join2.c
├── join3.c
├── join4.c
├── kill1.c
├── mutex1.c
├── mutex1e.c
├── mutex1n.c
├── mutex1r.c
├── mutex2.c
├── mutex2e.c
├── mutex2r.c
├── mutex3.c
├── mutex3e.c
├── mutex3r.c
├── mutex4.c
├── mutex5.c
├── mutex6.c
├── mutex6e.c
├── mutex6es.c
├── mutex6n.c
├── mutex6r.c
├── mutex6rs.c
├── mutex6s.c
├── mutex7.c
├── mutex7e.c
├── mutex7n.c
├── mutex7r.c
├── mutex8.c
├── mutex8e.c
├── mutex8n.c
├── mutex8r.c
├── name_np1.c
├── name_np2.c
├── once1.c
├── once2.c
├── once3.c
├── once4.c
├── openmp1.c
├── priority1.c
├── priority2.c
├── reinit1.c
├── reuse1.c
├── reuse2.c
├── robust1.c
├── robust2.c
├── robust3.c
├── robust4.c
├── robust5.c
├── runorder.mk
├── rwlock1.c
├── rwlock2.c
├── rwlock2_t.c
├── rwlock3.c
├── rwlock3_t.c
├── rwlock4.c
├── rwlock4_t.c
├── rwlock5.c
├── rwlock5_t.c
├── rwlock6.c
├── rwlock6_t.c
├── rwlock6_t2.c
├── rwlock7.c
├── rwlock8.c
├── rwlock8_1.c
├── self1.c
├── self2.c
├── semaphore1.c
├── semaphore2.c
├── semaphore3.c
├── semaphore4.c
├── semaphore4t.c
├── semaphore5.c
├── sequence1.c
├── sizes.c
├── spin1.c
├── spin2.c
├── spin3.c
├── spin4.c
├── stress1.c
├── test.h
├── threestage.c
├── timeouts.c
├── tryentercs.c
├── tryentercs2.c
├── tsd1.c
├── tsd2.c
├── tsd3.c
├── valid1.c
└── valid2.c
├── version.rc
└── w32_CancelableWait.c
/Bmakefile:
--------------------------------------------------------------------------------
1 | # This makefile is compatible with BCB make. Use "make -fBMakefile" to compile.
2 | #
3 | # The variables $DLLDEST and $LIBDEST hold the destination directories for the
4 | # dll and the lib, respectively. Probably all that needs to change is $DEVROOT.
5 | #
6 | # Currently only the recommended pthreadBC.dll is built by this makefile.
7 | #
8 |
9 |
10 | PTW32_VER = 3
11 |
12 | DEVROOT = .
13 |
14 | DLLDEST = $(DEVROOT)\DLL
15 | LIBDEST = $(DEVROOT)\DLL
16 |
17 | DLLS = pthreadBC$(PTW32_VER).dll
18 |
19 | OPTIM = /O2
20 |
21 | RC = brcc32
22 | RCFLAGS = -i.
23 |
24 | CFLAGS = /q /I. /DHAVE_CONFIG_H=1 /4 /tWD /tWM \
25 | /w-aus /w-asc /w-par
26 |
27 | #C cleanup code
28 | BCFLAGS = $ (__PTW32_FLAGS) $(CFLAGS)
29 |
30 | OBJEXT = obj
31 | RESEXT = res
32 |
33 | include common.mk
34 |
35 | all: clean $(DLLS)
36 |
37 | realclean: clean
38 | if exist pthread*.dll del pthread*.dll
39 | if exist pthread*.lib del pthread*.lib
40 | if exist *.stamp del *.stamp
41 |
42 | clean:
43 | if exist *.obj del *.obj
44 | if exist *.ilk del *.ilk
45 | if exist *.ilc del *.ilc
46 | if exist *.ild del *.ild
47 | if exist *.ilf del *.ilf
48 | if exist *.ils del *.ils
49 | if exist *.tds del *.tds
50 | if exist *.pdb del *.pdb
51 | if exist *.exp del *.exp
52 | if exist *.map del *.map
53 | if exist *.o del *.o
54 | if exist *.i del *.i
55 | if exist *.res del *.res
56 |
57 |
58 | install: $(DLLS)
59 | copy pthread*.dll $(DLLDEST)
60 | copy pthread*.lib $(LIBDEST)
61 |
62 | $(DLLS): $(DLL_OBJS) $(RESOURCE_OBJS)
63 | ilink32 /Tpd /Gi c0d32x.obj $(DLL_OBJS), \
64 | $@, ,\
65 | cw32mti.lib import32.lib, ,\
66 | $(RESOURCE_OBJS)
67 |
68 | .c.obj:
69 | $(CC) $(OPTIM) $(BCFLAGS) -c $<
70 |
71 | .rc.res:
72 | $(RC) $(RCFLAGS) $<
73 |
--------------------------------------------------------------------------------
/MAINTAINERS:
--------------------------------------------------------------------------------
1 | CVS Repository maintainers
2 |
3 | Ross Johnson Firstname.Lastname at LoungeByTheLake dot net
4 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | PThreads4W - POSIX threads for Windows
2 | Copyright 1998 John E. Bossom
3 | Copyright 1999-2018, Pthreads4w contributors
4 |
5 | This product includes software developed through the colaborative
6 | effort of several individuals, each of whom is listed in the file
7 | CONTRIBUTORS included with this software.
8 |
9 | The following files are not covered under the Copyrights
10 | listed above:
11 |
12 | [1] tests/rwlock7.c
13 | [1] tests/rwlock7_1.c
14 | [1] tests/rwlock8.c
15 | [1] tests/rwlock8_1.c
16 | [2] tests/threestage.c
17 |
18 | [1] The file tests/rwlock7.c and those similarly named are derived from
19 | code written by Dave Butenhof for his book 'Programming With POSIX(R)
20 | Threads'. The original code was obtained by free download from his
21 | website http://home.earthlink.net/~anneart/family/Threads/source.html
22 |
23 | [2] The file tests/threestage.c is taken directly from examples in the
24 | book "Windows System Programming, Edition 4" by Johnson (John) Hart
25 | Session 6, Chapter 10. ThreeStage.c
26 | Several required additional header and source files from the
27 | book examples have been included inline to simplify compilation.
28 | The only modification to the code has been to provide default
29 | values when run without arguments.
30 |
--------------------------------------------------------------------------------
/Nmakefile:
--------------------------------------------------------------------------------
1 | /*
2 | * nmake file for uwin pthread library
3 | */
4 |
5 | VERSION = -
6 | CCFLAGS = -V -g $(CC.DLL)
7 | HAVE_CONFIG_H == 1
8 | _MT == 1
9 | _timeb == timeb
10 | _ftime == ftime
11 | _errno == _ast_errno
12 |
13 | $(INCLUDEDIR) :INSTALLDIR: pthread.h sched.h
14 |
15 | pthread $(VERSION) :LIBRARY: attr.c barrier.c cancel.c cleanup.c condvar.c \
16 | create.c dll.c exit.c fork.c global.c misc.c mutex.c private.c \
17 | rwlock.c sched.c semaphore.c spin.c sync.c tsd.c nonportable.c
18 |
19 | :: ANNOUNCE CONTRIBUTORS COPYING.LIB ChangeLog FAQ GNUmakefile MAINTAINERS \
20 | Makefile Makefile.in Makefile.vc NEWS PROGRESS README README.WinCE \
21 | TODO WinCE-PORT install-sh errno.c tests tests.mk acconfig.h \
22 | config.guess config.h.in config.sub configure configure.in signal.c \
23 | README.CV README.NONPORTABLE pthread.dsp pthread.dsw
24 |
25 |
--------------------------------------------------------------------------------
/PROGRESS:
--------------------------------------------------------------------------------
1 | Please see the ANNOUNCE file "Level of Standards Conformance"
2 | or the web page:
3 |
4 | https://sourceforge.net/projects/pthreads4w/conformance.html
5 |
--------------------------------------------------------------------------------
/README.WinCE:
--------------------------------------------------------------------------------
1 | WinCE port
2 | ----------
3 | (See the file WinCE-PORT for a detailed explanation.)
4 |
5 | Make sure you define "WINCE" amongst your compiler flags (eg. -DWINCE).
6 | The config.h file will define all the necessary defines for you.
7 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | Things that aren't done yet
2 | ---------------------------
3 |
4 | 1. Implement PTHREAD_PROCESS_SHARED for semaphores, mutexes,
5 | condition variables, read/write locks, barriers.
6 |
7 | IMO, to do this in a source code compatible way requires implementation of
8 | POSIX shared memory functions, etc.
9 |
--------------------------------------------------------------------------------
/build.vc14/pthreads.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30723.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pthreads_lib", "pthreads_lib\pthreads_lib.vcxproj", "{666D916A-45A5-4069-B59E-2AA7C8ABF921}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pthreads_dll", "pthreads_dll\pthreads_dll.vcxproj", "{E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Win32 = Debug|Win32
13 | Debug|x64 = Debug|x64
14 | Release|Win32 = Release|Win32
15 | Release|x64 = Release|x64
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|Win32.ActiveCfg = Debug|Win32
19 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|Win32.Build.0 = Debug|Win32
20 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|x64.ActiveCfg = Debug|x64
21 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|x64.Build.0 = Debug|x64
22 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|Win32.ActiveCfg = Release|Win32
23 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|Win32.Build.0 = Release|Win32
24 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|x64.ActiveCfg = Release|x64
25 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|x64.Build.0 = Release|x64
26 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|Win32.ActiveCfg = Debug|Win32
27 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|Win32.Build.0 = Debug|Win32
28 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|x64.ActiveCfg = Debug|x64
29 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|x64.Build.0 = Debug|x64
30 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|Win32.ActiveCfg = Release|Win32
31 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|Win32.Build.0 = Release|Win32
32 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|x64.ActiveCfg = Release|x64
33 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|x64.Build.0 = Release|x64
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/build.vc14/pthreads_dll/postbuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if /i %2 EQU LIB (set two=lib)
4 | if /i %2 EQU DLL (set two=dll)
5 |
6 | if not exist ..\..\%two% (md ..\..\%two%)
7 | call :copy_hdr_files %1 ..\..\%two%\%1 %two%
8 | call :copy_bin_files %1 ..\..\%two%\%1 %two%
9 | exit /b 0
10 |
11 | :copy_hdr_files
12 |
13 | for %%i in ("..\..\*.h") do (call :copy_rename %%i %2 %%~nxi > nul 2>&1)
14 | exit /b 0
15 |
16 | :copy_bin_files
17 | rem copy the static library and related files
18 | if /i %3 EQU LIB (
19 | if exist ..\%1\pthreads.lib (
20 | echo ..\%1\pthreads.lib
21 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
22 | if exist ..\%1\pthreads.pdb (
23 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
24 | )
25 | )
26 | )
27 |
28 | rem copy the dynamic library and related files
29 | if /i %3 EQU DLL (
30 | if exist ..\%1\pthreads.dll (
31 | call :copy_rename ..\%1\pthreads.dll %2 > nul 2>&1
32 | if exist ..\%1\pthreads.pdb (
33 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
34 | )
35 | if exist ..\%1\pthreads.lib (
36 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
37 | )
38 | if exist ..\%1\pthreads.exp (
39 | call :copy_rename ..\%1\pthreads.exp %2 > nul 2>&1
40 | )
41 | )
42 | )
43 | exit /b 0
44 |
45 | rem copy rename 'in_file_name directory out_file_name'
46 | :copy_rename
47 | @echo off
48 | if not exist %1 goto cr_nofile
49 |
50 | if "%3" EQU "" (set outname=%~nx1) else (set outname=%3)
51 | if exist %2 goto cr_next
52 |
53 | echo creating directory %2
54 | md %2 > nul
55 |
56 | :cr_next
57 | rem strip quotes if present
58 | set str=%2
59 | for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
60 |
61 | rem add a backslash if the output directory lacks one
62 | set str=%str:~-1%
63 |
64 | if "%str%" == "\" (set outf=%2%outname%) else (set outf=%2\%outname%)
65 | if exist "%outf%" goto cr_check
66 |
67 | echo copying %1 to %outf%
68 | copy %1 %outf% > nul
69 | goto cr_exit
70 |
71 | :cr_check
72 | rem don't overwrite if output exists and is not changed
73 | fc %1 %outf% > nul && if not %errorlevel 1 goto cr_exit
74 | echo overwriting...... %outf% with %1
75 | copy %1 %outf% > nul
76 | goto cr_exit
77 |
78 | :cr_nofile
79 | echo %1 not found
80 |
81 | :cr_exit
82 | exit /b 0
83 |
--------------------------------------------------------------------------------
/build.vc14/pthreads_dll/pthreads_dll.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 |
41 |
42 | Resource Files
43 |
44 |
45 |
46 |
47 | Source Files
48 |
49 |
50 |
--------------------------------------------------------------------------------
/build.vc14/pthreads_lib/postbuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if /i %2 EQU LIB (set two=lib)
4 | if /i %2 EQU DLL (set two=dll)
5 |
6 | if not exist ..\..\%two% (md ..\..\%two%)
7 | call :copy_hdr_files %1 ..\..\%two%\%1 %two%
8 | call :copy_bin_files %1 ..\..\%two%\%1 %two%
9 | exit /b 0
10 |
11 | :copy_hdr_files
12 |
13 | for %%i in ("..\..\*.h") do (call :copy_rename %%i %2 %%~nxi > nul 2>&1)
14 | exit /b 0
15 |
16 | :copy_bin_files
17 | rem copy the static library and related files
18 | if /i %3 EQU LIB (
19 | if exist ..\%1\pthreads.lib (
20 | echo ..\%1\pthreads.lib
21 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
22 | if exist ..\%1\pthreads.pdb (
23 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
24 | )
25 | )
26 | )
27 |
28 | rem copy the dynamic library and related files
29 | if /i %3 EQU DLL (
30 | if exist ..\%1\pthreads.dll (
31 | call :copy_rename ..\%1\pthreads.dll %2 > nul 2>&1
32 | if exist ..\%1\pthreads.pdb (
33 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
34 | )
35 | if exist ..\%1\pthreads.lib (
36 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
37 | )
38 | if exist ..\%1\pthreads.exp (
39 | call :copy_rename ..\%1\pthreads.exp %2 > nul 2>&1
40 | )
41 | )
42 | )
43 | exit /b 0
44 |
45 | rem copy rename 'in_file_name directory out_file_name'
46 | :copy_rename
47 | @echo off
48 | if not exist %1 goto cr_nofile
49 |
50 | if "%3" EQU "" (set outname=%~nx1) else (set outname=%3)
51 | if exist %2 goto cr_next
52 |
53 | echo creating directory %2
54 | md %2 > nul
55 |
56 | :cr_next
57 | rem strip quotes if present
58 | set str=%2
59 | for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
60 |
61 | rem add a backslash if the output directory lacks one
62 | set str=%str:~-1%
63 |
64 | if "%str%" == "\" (set outf=%2%outname%) else (set outf=%2\%outname%)
65 | if exist "%outf%" goto cr_check
66 |
67 | echo copying %1 to %outf%
68 | copy %1 %outf% > nul
69 | goto cr_exit
70 |
71 | :cr_check
72 | rem don't overwrite if output exists and is not changed
73 | fc %1 %outf% > nul && if not %errorlevel 1 goto cr_exit
74 | echo overwriting...... %outf% with %1
75 | copy %1 %outf% > nul
76 | goto cr_exit
77 |
78 | :cr_nofile
79 | echo %1 not found
80 |
81 | :cr_exit
82 | exit /b 0
83 |
--------------------------------------------------------------------------------
/build.vc14/pthreads_lib/pthreads_lib.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 |
41 |
42 | Resource Files
43 |
44 |
45 |
46 |
47 | Source Files
48 |
49 |
50 |
--------------------------------------------------------------------------------
/build.vc15/pthreads.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30723.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pthreads_lib", "pthreads_lib\pthreads_lib.vcxproj", "{666D916A-45A5-4069-B59E-2AA7C8ABF921}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pthreads_dll", "pthreads_dll\pthreads_dll.vcxproj", "{E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Win32 = Debug|Win32
13 | Debug|x64 = Debug|x64
14 | Release|Win32 = Release|Win32
15 | Release|x64 = Release|x64
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|Win32.ActiveCfg = Debug|Win32
19 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|Win32.Build.0 = Debug|Win32
20 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|x64.ActiveCfg = Debug|x64
21 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|x64.Build.0 = Debug|x64
22 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|Win32.ActiveCfg = Release|Win32
23 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|Win32.Build.0 = Release|Win32
24 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|x64.ActiveCfg = Release|x64
25 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|x64.Build.0 = Release|x64
26 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|Win32.ActiveCfg = Debug|Win32
27 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|Win32.Build.0 = Debug|Win32
28 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|x64.ActiveCfg = Debug|x64
29 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|x64.Build.0 = Debug|x64
30 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|Win32.ActiveCfg = Release|Win32
31 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|Win32.Build.0 = Release|Win32
32 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|x64.ActiveCfg = Release|x64
33 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|x64.Build.0 = Release|x64
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/build.vc15/pthreads_dll/postbuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if /i %2 EQU LIB (set two=lib)
4 | if /i %2 EQU DLL (set two=dll)
5 |
6 | if not exist ..\..\%two% (md ..\..\%two%)
7 | call :copy_hdr_files %1 ..\..\%two%\%1 %two%
8 | call :copy_bin_files %1 ..\..\%two%\%1 %two%
9 | exit /b 0
10 |
11 | :copy_hdr_files
12 |
13 | for %%i in ("..\..\*.h") do (call :copy_rename %%i %2 %%~nxi > nul 2>&1)
14 | exit /b 0
15 |
16 | :copy_bin_files
17 | rem copy the static library and related files
18 | if /i %3 EQU LIB (
19 | if exist ..\%1\pthreads.lib (
20 | echo ..\%1\pthreads.lib
21 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
22 | if exist ..\%1\pthreads.pdb (
23 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
24 | )
25 | )
26 | )
27 |
28 | rem copy the dynamic library and related files
29 | if /i %3 EQU DLL (
30 | if exist ..\%1\pthreads.dll (
31 | call :copy_rename ..\%1\pthreads.dll %2 > nul 2>&1
32 | if exist ..\%1\pthreads.pdb (
33 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
34 | )
35 | if exist ..\%1\pthreads.lib (
36 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
37 | )
38 | if exist ..\%1\pthreads.exp (
39 | call :copy_rename ..\%1\pthreads.exp %2 > nul 2>&1
40 | )
41 | )
42 | )
43 | exit /b 0
44 |
45 | rem copy rename 'in_file_name directory out_file_name'
46 | :copy_rename
47 | @echo off
48 | if not exist %1 goto cr_nofile
49 |
50 | if "%3" EQU "" (set outname=%~nx1) else (set outname=%3)
51 | if exist %2 goto cr_next
52 |
53 | echo creating directory %2
54 | md %2 > nul
55 |
56 | :cr_next
57 | rem strip quotes if present
58 | set str=%2
59 | for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
60 |
61 | rem add a backslash if the output directory lacks one
62 | set str=%str:~-1%
63 |
64 | if "%str%" == "\" (set outf=%2%outname%) else (set outf=%2\%outname%)
65 | if exist "%outf%" goto cr_check
66 |
67 | echo copying %1 to %outf%
68 | copy %1 %outf% > nul
69 | goto cr_exit
70 |
71 | :cr_check
72 | rem don't overwrite if output exists and is not changed
73 | fc %1 %outf% > nul && if not %errorlevel 1 goto cr_exit
74 | echo overwriting...... %outf% with %1
75 | copy %1 %outf% > nul
76 | goto cr_exit
77 |
78 | :cr_nofile
79 | echo %1 not found
80 |
81 | :cr_exit
82 | exit /b 0
83 |
--------------------------------------------------------------------------------
/build.vc15/pthreads_dll/pthreads_dll.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 |
41 |
42 | Resource Files
43 |
44 |
45 |
46 |
47 | Source Files
48 |
49 |
50 |
--------------------------------------------------------------------------------
/build.vc15/pthreads_lib/postbuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if /i %2 EQU LIB (set two=lib)
4 | if /i %2 EQU DLL (set two=dll)
5 |
6 | if not exist ..\..\%two% (md ..\..\%two%)
7 | call :copy_hdr_files %1 ..\..\%two%\%1 %two%
8 | call :copy_bin_files %1 ..\..\%two%\%1 %two%
9 | exit /b 0
10 |
11 | :copy_hdr_files
12 |
13 | for %%i in ("..\..\*.h") do (call :copy_rename %%i %2 %%~nxi > nul 2>&1)
14 | exit /b 0
15 |
16 | :copy_bin_files
17 | rem copy the static library and related files
18 | if /i %3 EQU LIB (
19 | if exist ..\%1\pthreads.lib (
20 | echo ..\%1\pthreads.lib
21 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
22 | if exist ..\%1\pthreads.pdb (
23 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
24 | )
25 | )
26 | )
27 |
28 | rem copy the dynamic library and related files
29 | if /i %3 EQU DLL (
30 | if exist ..\%1\pthreads.dll (
31 | call :copy_rename ..\%1\pthreads.dll %2 > nul 2>&1
32 | if exist ..\%1\pthreads.pdb (
33 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
34 | )
35 | if exist ..\%1\pthreads.lib (
36 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
37 | )
38 | if exist ..\%1\pthreads.exp (
39 | call :copy_rename ..\%1\pthreads.exp %2 > nul 2>&1
40 | )
41 | )
42 | )
43 | exit /b 0
44 |
45 | rem copy rename 'in_file_name directory out_file_name'
46 | :copy_rename
47 | @echo off
48 | if not exist %1 goto cr_nofile
49 |
50 | if "%3" EQU "" (set outname=%~nx1) else (set outname=%3)
51 | if exist %2 goto cr_next
52 |
53 | echo creating directory %2
54 | md %2 > nul
55 |
56 | :cr_next
57 | rem strip quotes if present
58 | set str=%2
59 | for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
60 |
61 | rem add a backslash if the output directory lacks one
62 | set str=%str:~-1%
63 |
64 | if "%str%" == "\" (set outf=%2%outname%) else (set outf=%2\%outname%)
65 | if exist "%outf%" goto cr_check
66 |
67 | echo copying %1 to %outf%
68 | copy %1 %outf% > nul
69 | goto cr_exit
70 |
71 | :cr_check
72 | rem don't overwrite if output exists and is not changed
73 | fc %1 %outf% > nul && if not %errorlevel 1 goto cr_exit
74 | echo overwriting...... %outf% with %1
75 | copy %1 %outf% > nul
76 | goto cr_exit
77 |
78 | :cr_nofile
79 | echo %1 not found
80 |
81 | :cr_exit
82 | exit /b 0
83 |
--------------------------------------------------------------------------------
/build.vc15/pthreads_lib/pthreads_lib.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 |
41 |
42 | Resource Files
43 |
44 |
45 |
46 |
47 | Source Files
48 |
49 |
50 |
--------------------------------------------------------------------------------
/build.vc16/pthreads.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30723.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pthreads_lib", "pthreads_lib\pthreads_lib.vcxproj", "{666D916A-45A5-4069-B59E-2AA7C8ABF921}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pthreads_dll", "pthreads_dll\pthreads_dll.vcxproj", "{E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Win32 = Debug|Win32
13 | Debug|x64 = Debug|x64
14 | Release|Win32 = Release|Win32
15 | Release|x64 = Release|x64
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|Win32.ActiveCfg = Debug|Win32
19 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|Win32.Build.0 = Debug|Win32
20 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|x64.ActiveCfg = Debug|x64
21 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Debug|x64.Build.0 = Debug|x64
22 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|Win32.ActiveCfg = Release|Win32
23 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|Win32.Build.0 = Release|Win32
24 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|x64.ActiveCfg = Release|x64
25 | {666D916A-45A5-4069-B59E-2AA7C8ABF921}.Release|x64.Build.0 = Release|x64
26 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|Win32.ActiveCfg = Debug|Win32
27 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|Win32.Build.0 = Debug|Win32
28 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|x64.ActiveCfg = Debug|x64
29 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Debug|x64.Build.0 = Debug|x64
30 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|Win32.ActiveCfg = Release|Win32
31 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|Win32.Build.0 = Release|Win32
32 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|x64.ActiveCfg = Release|x64
33 | {E0EBB8A5-B577-414C-A5F9-9B4E2A0A66E9}.Release|x64.Build.0 = Release|x64
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/build.vc16/pthreads_dll/postbuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if /i %2 EQU LIB (set two=lib)
4 | if /i %2 EQU DLL (set two=dll)
5 |
6 | if not exist ..\..\%two% (md ..\..\%two%)
7 | call :copy_hdr_files %1 ..\..\%two%\%1 %two%
8 | call :copy_bin_files %1 ..\..\%two%\%1 %two%
9 | exit /b 0
10 |
11 | :copy_hdr_files
12 |
13 | for %%i in ("..\..\*.h") do (call :copy_rename %%i %2 %%~nxi > nul 2>&1)
14 | exit /b 0
15 |
16 | :copy_bin_files
17 | rem copy the static library and related files
18 | if /i %3 EQU LIB (
19 | if exist ..\%1\pthreads.lib (
20 | echo ..\%1\pthreads.lib
21 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
22 | if exist ..\%1\pthreads.pdb (
23 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
24 | )
25 | )
26 | )
27 |
28 | rem copy the dynamic library and related files
29 | if /i %3 EQU DLL (
30 | if exist ..\%1\pthreads.dll (
31 | call :copy_rename ..\%1\pthreads.dll %2 > nul 2>&1
32 | if exist ..\%1\pthreads.pdb (
33 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
34 | )
35 | if exist ..\%1\pthreads.lib (
36 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
37 | )
38 | if exist ..\%1\pthreads.exp (
39 | call :copy_rename ..\%1\pthreads.exp %2 > nul 2>&1
40 | )
41 | )
42 | )
43 | exit /b 0
44 |
45 | rem copy rename 'in_file_name directory out_file_name'
46 | :copy_rename
47 | @echo off
48 | if not exist %1 goto cr_nofile
49 |
50 | if "%3" EQU "" (set outname=%~nx1) else (set outname=%3)
51 | if exist %2 goto cr_next
52 |
53 | echo creating directory %2
54 | md %2 > nul
55 |
56 | :cr_next
57 | rem strip quotes if present
58 | set str=%2
59 | for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
60 |
61 | rem add a backslash if the output directory lacks one
62 | set str=%str:~-1%
63 |
64 | if "%str%" == "\" (set outf=%2%outname%) else (set outf=%2\%outname%)
65 | if exist "%outf%" goto cr_check
66 |
67 | echo copying %1 to %outf%
68 | copy %1 %outf% > nul
69 | goto cr_exit
70 |
71 | :cr_check
72 | rem don't overwrite if output exists and is not changed
73 | fc %1 %outf% > nul && if not %errorlevel 1 goto cr_exit
74 | echo overwriting...... %outf% with %1
75 | copy %1 %outf% > nul
76 | goto cr_exit
77 |
78 | :cr_nofile
79 | echo %1 not found
80 |
81 | :cr_exit
82 | exit /b 0
83 |
--------------------------------------------------------------------------------
/build.vc16/pthreads_dll/pthreads_dll.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 |
41 |
42 | Resource Files
43 |
44 |
45 |
46 |
47 | Source Files
48 |
49 |
50 |
--------------------------------------------------------------------------------
/build.vc16/pthreads_lib/postbuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if /i %2 EQU LIB (set two=lib)
4 | if /i %2 EQU DLL (set two=dll)
5 |
6 | if not exist ..\..\%two% (md ..\..\%two%)
7 | call :copy_hdr_files %1 ..\..\%two%\%1 %two%
8 | call :copy_bin_files %1 ..\..\%two%\%1 %two%
9 | exit /b 0
10 |
11 | :copy_hdr_files
12 |
13 | for %%i in ("..\..\*.h") do (call :copy_rename %%i %2 %%~nxi > nul 2>&1)
14 | exit /b 0
15 |
16 | :copy_bin_files
17 | rem copy the static library and related files
18 | if /i %3 EQU LIB (
19 | if exist ..\%1\pthreads.lib (
20 | echo ..\%1\pthreads.lib
21 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
22 | if exist ..\%1\pthreads.pdb (
23 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
24 | )
25 | )
26 | )
27 |
28 | rem copy the dynamic library and related files
29 | if /i %3 EQU DLL (
30 | if exist ..\%1\pthreads.dll (
31 | call :copy_rename ..\%1\pthreads.dll %2 > nul 2>&1
32 | if exist ..\%1\pthreads.pdb (
33 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
34 | )
35 | if exist ..\%1\pthreads.lib (
36 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
37 | )
38 | if exist ..\%1\pthreads.exp (
39 | call :copy_rename ..\%1\pthreads.exp %2 > nul 2>&1
40 | )
41 | )
42 | )
43 | exit /b 0
44 |
45 | rem copy rename 'in_file_name directory out_file_name'
46 | :copy_rename
47 | @echo off
48 | if not exist %1 goto cr_nofile
49 |
50 | if "%3" EQU "" (set outname=%~nx1) else (set outname=%3)
51 | if exist %2 goto cr_next
52 |
53 | echo creating directory %2
54 | md %2 > nul
55 |
56 | :cr_next
57 | rem strip quotes if present
58 | set str=%2
59 | for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
60 |
61 | rem add a backslash if the output directory lacks one
62 | set str=%str:~-1%
63 |
64 | if "%str%" == "\" (set outf=%2%outname%) else (set outf=%2\%outname%)
65 | if exist "%outf%" goto cr_check
66 |
67 | echo copying %1 to %outf%
68 | copy %1 %outf% > nul
69 | goto cr_exit
70 |
71 | :cr_check
72 | rem don't overwrite if output exists and is not changed
73 | fc %1 %outf% > nul && if not %errorlevel 1 goto cr_exit
74 | echo overwriting...... %outf% with %1
75 | copy %1 %outf% > nul
76 | goto cr_exit
77 |
78 | :cr_nofile
79 | echo %1 not found
80 |
81 | :cr_exit
82 | exit /b 0
83 |
--------------------------------------------------------------------------------
/build.vc16/pthreads_lib/pthreads_lib.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 |
41 |
42 | Resource Files
43 |
44 |
45 |
46 |
47 | Source Files
48 |
49 |
50 |
--------------------------------------------------------------------------------
/build.vs/build_tests/build_tests.pyproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Debug
4 | 2.0
5 | 5b50725a-8888-4467-a1d1-df6f8eca0a23
6 | .
7 | build_tests.py
8 |
9 |
10 | .
11 | .
12 | build_tests
13 | build_tests
14 |
15 |
16 | true
17 | false
18 |
19 |
20 | true
21 | false
22 |
23 |
24 |
25 |
26 |
27 |
28 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/build.vs/pthreads_dll/postbuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if /i %2 EQU LIB (set two=lib)
4 | if /i %2 EQU DLL (set two=dll)
5 |
6 | if not exist ..\..\%two% (md ..\..\%two%)
7 | call :copy_hdr_files %1 ..\..\%two%\%1 %two%
8 | call :copy_bin_files %1 ..\..\%two%\%1 %two%
9 | exit /b 0
10 |
11 | :copy_hdr_files
12 |
13 | for %%i in ("..\..\*.h") do (call :copy_rename %%i %2 %%~nxi > nul 2>&1)
14 | exit /b 0
15 |
16 | :copy_bin_files
17 | rem copy the static library and related files
18 | if /i %3 EQU LIB (
19 | if exist ..\%1\pthreads.lib (
20 | echo ..\%1\pthreads.lib
21 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
22 | if exist ..\%1\pthreads.pdb (
23 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
24 | )
25 | )
26 | )
27 |
28 | rem copy the dynamic library and related files
29 | if /i %3 EQU DLL (
30 | if exist ..\%1\pthreads.dll (
31 | call :copy_rename ..\%1\pthreads.dll %2 > nul 2>&1
32 | if exist ..\%1\pthreads.pdb (
33 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
34 | )
35 | if exist ..\%1\pthreads.lib (
36 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
37 | )
38 | if exist ..\%1\pthreads.exp (
39 | call :copy_rename ..\%1\pthreads.exp %2 > nul 2>&1
40 | )
41 | )
42 | )
43 | exit /b 0
44 |
45 | rem copy rename 'in_file_name directory out_file_name'
46 | :copy_rename
47 | @echo off
48 | if not exist %1 goto cr_nofile
49 |
50 | if "%3" EQU "" (set outname=%~nx1) else (set outname=%3)
51 | if exist %2 goto cr_next
52 |
53 | echo creating directory %2
54 | md %2 > nul
55 |
56 | :cr_next
57 | rem strip quotes if present
58 | set str=%2
59 | for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
60 |
61 | rem add a backslash if the output directory lacks one
62 | set str=%str:~-1%
63 |
64 | if "%str%" == "\" (set outf=%2%outname%) else (set outf=%2\%outname%)
65 | if exist "%outf%" goto cr_check
66 |
67 | echo copying %1 to %outf%
68 | copy %1 %outf% > nul
69 | goto cr_exit
70 |
71 | :cr_check
72 | rem don't overwrite if output exists and is not changed
73 | fc %1 %outf% > nul && if not %errorlevel 1 goto cr_exit
74 | echo overwriting...... %outf% with %1
75 | copy %1 %outf% > nul
76 | goto cr_exit
77 |
78 | :cr_nofile
79 | echo %1 not found
80 |
81 | :cr_exit
82 | exit /b 0
83 |
--------------------------------------------------------------------------------
/build.vs/pthreads_dll/pthreads_dll.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 |
41 |
42 | Resource Files
43 |
44 |
45 |
46 |
47 | Source Files
48 |
49 |
50 |
--------------------------------------------------------------------------------
/build.vs/pthreads_lib/postbuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 |
3 | if /i %2 EQU LIB (set two=lib)
4 | if /i %2 EQU DLL (set two=dll)
5 |
6 | if not exist ..\..\%two% (md ..\..\%two%)
7 | call :copy_hdr_files %1 ..\..\%two%\%1 %two%
8 | call :copy_bin_files %1 ..\..\%two%\%1 %two%
9 | exit /b 0
10 |
11 | :copy_hdr_files
12 |
13 | for %%i in ("..\..\*.h") do (call :copy_rename %%i %2 %%~nxi > nul 2>&1)
14 | exit /b 0
15 |
16 | :copy_bin_files
17 | rem copy the static library and related files
18 | if /i %3 EQU LIB (
19 | if exist ..\%1\pthreads.lib (
20 | echo ..\%1\pthreads.lib
21 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
22 | if exist ..\%1\pthreads.pdb (
23 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
24 | )
25 | )
26 | )
27 |
28 | rem copy the dynamic library and related files
29 | if /i %3 EQU DLL (
30 | if exist ..\%1\pthreads.dll (
31 | call :copy_rename ..\%1\pthreads.dll %2 > nul 2>&1
32 | if exist ..\%1\pthreads.pdb (
33 | call :copy_rename ..\%1\pthreads.pdb %2 > nul 2>&1
34 | )
35 | if exist ..\%1\pthreads.lib (
36 | call :copy_rename ..\%1\pthreads.lib %2 > nul 2>&1
37 | )
38 | if exist ..\%1\pthreads.exp (
39 | call :copy_rename ..\%1\pthreads.exp %2 > nul 2>&1
40 | )
41 | )
42 | )
43 | exit /b 0
44 |
45 | rem copy rename 'in_file_name directory out_file_name'
46 | :copy_rename
47 | @echo off
48 | if not exist %1 goto cr_nofile
49 |
50 | if "%3" EQU "" (set outname=%~nx1) else (set outname=%3)
51 | if exist %2 goto cr_next
52 |
53 | echo creating directory %2
54 | md %2 > nul
55 |
56 | :cr_next
57 | rem strip quotes if present
58 | set str=%2
59 | for /f "useback tokens=*" %%a in ('%str%') do set str=%%~a
60 |
61 | rem add a backslash if the output directory lacks one
62 | set str=%str:~-1%
63 |
64 | if "%str%" == "\" (set outf=%2%outname%) else (set outf=%2\%outname%)
65 | if exist "%outf%" goto cr_check
66 |
67 | echo copying %1 to %outf%
68 | copy %1 %outf% > nul
69 | goto cr_exit
70 |
71 | :cr_check
72 | rem don't overwrite if output exists and is not changed
73 | fc %1 %outf% > nul && if not %errorlevel 1 goto cr_exit
74 | echo overwriting...... %outf% with %1
75 | copy %1 %outf% > nul
76 | goto cr_exit
77 |
78 | :cr_nofile
79 | echo %1 not found
80 |
81 | :cr_exit
82 | exit /b 0
83 |
--------------------------------------------------------------------------------
/build.vs/pthreads_lib/pthreads_lib.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 | Header Files
35 |
36 |
37 | Header Files
38 |
39 |
40 |
41 |
42 | Resource Files
43 |
44 |
45 |
46 |
47 | Source Files
48 |
49 |
50 |
--------------------------------------------------------------------------------
/build.vs/run_tests/run_tests.pyproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Debug
4 | 2.0
5 | 334546e9-d2a9-4f97-91a9-5da7aaee5207
6 | .
7 | run_tests.py
8 |
9 |
10 | .
11 | .
12 | run_tests
13 | run_tests
14 |
15 |
16 | true
17 | false
18 |
19 |
20 | true
21 | false
22 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/builddmc.bat:
--------------------------------------------------------------------------------
1 | ; Build the pthreads library with the Digital Mars Compiler
2 | ;
3 | set DMCDIR=c:\dm
4 |
5 | ; RELEASE
6 | %DMCDIR%\bin\dmc -D_MT -DHAVE_CONFIG_H -I.;c:\dm\include -o+all -WD pthread.c user32.lib+kernel32.lib+wsock32.lib -L/impl -L/NODEBUG -L/SU:WINDOWS
7 |
8 | ; DEBUG
9 | %DMCDIR%\bin\dmc -g -D_MT -DHAVE_CONFIG_H -I.;c:\dm\include -o+all -WD pthread.c user32.lib+kernel32.lib+wsock32.lib -L/impl -L/SU:WINDOWS
10 |
--------------------------------------------------------------------------------
/context.h:
--------------------------------------------------------------------------------
1 | /*
2 | * context.h
3 | *
4 | * Description:
5 | * POSIX thread macros related to thread cancellation.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifndef __PTW32_CONTEXT_H
36 | #define __PTW32_CONTEXT_H
37 |
38 | #undef __PTW32_PROGCTR
39 |
40 | #if defined(_M_IX86) || (defined(_X86_) && !defined(__amd64__))
41 | #define __PTW32_PROGCTR(Context) ((Context).Eip)
42 | #endif
43 |
44 | #if defined (_M_IA64) || defined(_IA64)
45 | #define __PTW32_PROGCTR(Context) ((Context).StIIP)
46 | #endif
47 |
48 | #if defined(_MIPS_) || defined(MIPS)
49 | #define __PTW32_PROGCTR(Context) ((Context).Fir)
50 | #endif
51 |
52 | #if defined(_ALPHA_)
53 | #define __PTW32_PROGCTR(Context) ((Context).Fir)
54 | #endif
55 |
56 | #if defined(_PPC_)
57 | #define __PTW32_PROGCTR(Context) ((Context).Iar)
58 | #endif
59 |
60 | #if defined(_AMD64_) || defined(__amd64__)
61 | #define __PTW32_PROGCTR(Context) ((Context).Rip)
62 | #endif
63 |
64 | #if defined(_ARM_) || defined(ARM) || defined(_M_ARM) || defined(_M_ARM64)
65 | #define PTW32_PROGCTR(Context) ((Context).Pc)
66 | #endif
67 |
68 | #if !defined (__PTW32_PROGCTR)
69 | #error Module contains CPU-specific code; modify and recompile.
70 | #endif
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/manual/pthread_getw32threadhandle_np.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PTHREAD_GETW32THREADHANDLE_NP(3) manual page
6 |
7 |
8 | POSIX Threads for Windows – REFERENCE - Pthreads4W
9 | Reference Index
10 | Table of Contents
11 |
12 | pthread_getw32threadhandle_np – get
13 | the Win32 thread handle associated with a thread
14 |
15 | #include <pthread.h>
16 |
17 | HANDLE pthread_getw32threadhandle_np(pthread_t thread);
18 |
19 | Returns the Win32 native thread HANDLE that the POSIX
20 | thread thread is running as.
21 | Applications can use the Win32 handle to set Win32 specific
22 | attributes of the thread.
23 |
24 | None.
25 |
26 | pthread_getw32threadhandle_np returns the Win32 native
27 | thread HANDLE for the specified POSIX thread thread.
28 |
29 | None.
30 |
31 | Ross Johnson for use with Pthreads4W.
32 |
33 | Table of Contents
34 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/manual/pthread_num_processors_np.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PTHREAD_NUM_PROCESSORS_NP(3) manual page
6 |
7 |
8 | POSIX Threads for Windows – REFERENCE - Pthreads4W
9 | Reference Index
10 | Table of Contents
11 |
12 | pthread_num_processors_np – get the
13 | number of processors (CPUs) in use by the process
14 |
15 | #include <pthread.h>
16 |
17 | int pthread_num_processors_np(void);
18 |
19 | pthread_num_processors_np returns the number of processors
20 | in the system. This implementation actually returns the number of
21 | processors available to the process, which can be a lower number than
22 | the system's number, depending on the process's affinity mask.
23 |
24 | None.
25 |
26 | pthread_num_processors_np returns the number of processors
27 | currently available to the process.
28 |
29 | None.
30 |
31 | Ross Johnson for use with Pthreads4W.
32 |
33 | Table of Contents
34 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/pthread_attr_getaffinity_np.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_getaffinity_np.c
3 | *
4 | * Description:
5 | * POSIX thread functions that deal with thread CPU affinity.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 | #include "sched.h"
42 |
43 | int
44 | pthread_attr_getaffinity_np (const pthread_attr_t * attr, size_t cpusetsize, cpu_set_t * cpuset)
45 | {
46 | if (__ptw32_is_attr (attr) != 0 || cpuset == NULL)
47 | {
48 | return EINVAL;
49 | }
50 |
51 | ((_sched_cpu_set_vector_*)cpuset)->_cpuset = (*attr)->cpuset;
52 |
53 | return 0;
54 | }
55 |
--------------------------------------------------------------------------------
/pthread_attr_getinheritsched.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_getinheritsched.c
3 | *
4 | * Description:
5 | * POSIX thread functions that deal with thread scheduling.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 | #include "sched.h"
42 |
43 | int
44 | pthread_attr_getinheritsched (const pthread_attr_t * attr, int *inheritsched)
45 | {
46 | if (__ptw32_is_attr (attr) != 0 || inheritsched == NULL)
47 | {
48 | return EINVAL;
49 | }
50 |
51 | *inheritsched = (*attr)->inheritsched;
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/pthread_attr_getname_np.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_getname_np.c
3 | *
4 | * --------------------------------------------------------------------------
5 | *
6 | * Pthreads4w - POSIX Threads for Windows
7 | * Copyright 1998 John E. Bossom
8 | * Copyright 1999-2018, Pthreads4w contributors
9 | *
10 | * Homepage: https://sourceforge.net/projects/pthreads4w/
11 | *
12 | * The current list of contributors is contained
13 | * in the file CONTRIBUTORS included with the source
14 | * code distribution. The list can also be seen at the
15 | * following World Wide Web location:
16 | *
17 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
18 | *
19 | * Licensed under the Apache License, Version 2.0 (the "License");
20 | * you may not use this file except in compliance with the License.
21 | * You may obtain a copy of the License at
22 | *
23 | * http://www.apache.org/licenses/LICENSE-2.0
24 | *
25 | * Unless required by applicable law or agreed to in writing, software
26 | * distributed under the License is distributed on an "AS IS" BASIS,
27 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 | * See the License for the specific language governing permissions and
29 | * limitations under the License.
30 | */
31 |
32 | #ifdef HAVE_CONFIG_H
33 | # include
34 | #endif
35 |
36 | #include
37 | #include "pthread.h"
38 | #include "implement.h"
39 |
40 | int
41 | pthread_attr_getname_np(pthread_attr_t * attr, char *name, int len)
42 | {
43 | //strncpy_s(name, len - 1, (*attr)->thrname, len - 1);
44 | #if defined(_MSVCRT_)
45 | # pragma warning(suppress:4996)
46 | strncpy(name, (*attr)->thrname, len - 1);
47 | (*attr)->thrname[len - 1] = '\0';
48 | #endif
49 |
50 | return 0;
51 | }
52 |
--------------------------------------------------------------------------------
/pthread_attr_getschedparam.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_getschedparam.c
3 | *
4 | * Description:
5 | * POSIX thread functions that deal with thread scheduling.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 | #include "sched.h"
42 |
43 | int
44 | pthread_attr_getschedparam (const pthread_attr_t * attr,
45 | struct sched_param *param)
46 | {
47 | if (__ptw32_is_attr (attr) != 0 || param == NULL)
48 | {
49 | return EINVAL;
50 | }
51 |
52 | memcpy (param, &(*attr)->param, sizeof (*param));
53 | return 0;
54 | }
55 |
--------------------------------------------------------------------------------
/pthread_attr_getschedpolicy.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_getschedpolicy.c
3 | *
4 | * Description:
5 | * POSIX thread functions that deal with thread scheduling.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 | #include "sched.h"
42 |
43 | int
44 | pthread_attr_getschedpolicy (const pthread_attr_t * attr, int *policy)
45 | {
46 | if (__ptw32_is_attr (attr) != 0 || policy == NULL)
47 | {
48 | return EINVAL;
49 | }
50 |
51 | *policy = SCHED_OTHER;
52 |
53 | return 0;
54 | }
55 |
--------------------------------------------------------------------------------
/pthread_attr_getscope.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_getscope.c
3 | *
4 | * Description:
5 | * This translation unit implements operations on thread attribute objects.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 | /* ignore warning "unreferenced formal parameter" */
43 | #if defined(_MSC_VER)
44 | #pragma warning( disable : 4100 )
45 | #endif
46 |
47 | int
48 | pthread_attr_getscope (const pthread_attr_t * attr, int *contentionscope)
49 | {
50 | #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
51 | *contentionscope = (*attr)->contentionscope;
52 | return 0;
53 | #else
54 | return ENOSYS;
55 | #endif
56 | }
57 |
--------------------------------------------------------------------------------
/pthread_attr_setaffinity_np.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_setaffinity_np.c
3 | *
4 | * Description:
5 | * POSIX thread functions that deal with thread CPU affinity.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 | #include "sched.h"
42 |
43 | int
44 | pthread_attr_setaffinity_np (pthread_attr_t * attr, size_t cpusetsize, const cpu_set_t * cpuset)
45 | {
46 | if (__ptw32_is_attr (attr) != 0 || cpuset == NULL)
47 | {
48 | return EINVAL;
49 | }
50 |
51 | (*attr)->cpuset = ((_sched_cpu_set_vector_*)cpuset)->_cpuset;
52 |
53 | return 0;
54 | }
55 |
--------------------------------------------------------------------------------
/pthread_attr_setinheritsched.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_setinheritsched.c
3 | *
4 | * Description:
5 | * POSIX thread functions that deal with thread scheduling.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 | #include "sched.h"
42 |
43 | int
44 | pthread_attr_setinheritsched (pthread_attr_t * attr, int inheritsched)
45 | {
46 | if (__ptw32_is_attr (attr) != 0)
47 | {
48 | return EINVAL;
49 | }
50 |
51 | if (PTHREAD_INHERIT_SCHED != inheritsched
52 | && PTHREAD_EXPLICIT_SCHED != inheritsched)
53 | {
54 | return EINVAL;
55 | }
56 |
57 | (*attr)->inheritsched = inheritsched;
58 | return 0;
59 | }
60 |
--------------------------------------------------------------------------------
/pthread_attr_setschedparam.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_setschedparam.c
3 | *
4 | * Description:
5 | * POSIX thread functions that deal with thread scheduling.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 | #include "sched.h"
42 |
43 | int
44 | pthread_attr_setschedparam (pthread_attr_t * attr,
45 | const struct sched_param *param)
46 | {
47 | int priority;
48 |
49 | if (__ptw32_is_attr (attr) != 0 || param == NULL)
50 | {
51 | return EINVAL;
52 | }
53 |
54 | priority = param->sched_priority;
55 |
56 | /* Validate priority level. */
57 | if (priority < sched_get_priority_min (SCHED_OTHER) ||
58 | priority > sched_get_priority_max (SCHED_OTHER))
59 | {
60 | return EINVAL;
61 | }
62 |
63 | memcpy (&(*attr)->param, param, sizeof (*param));
64 | return 0;
65 | }
66 |
--------------------------------------------------------------------------------
/pthread_attr_setschedpolicy.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_setschedpolicy.c
3 | *
4 | * Description:
5 | * POSIX thread functions that deal with thread scheduling.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 | #include "sched.h"
42 |
43 | int
44 | pthread_attr_setschedpolicy (pthread_attr_t * attr, int policy)
45 | {
46 | if (__ptw32_is_attr (attr) != 0)
47 | {
48 | return EINVAL;
49 | }
50 |
51 | if (policy != SCHED_OTHER)
52 | {
53 | return ENOTSUP;
54 | }
55 |
56 | return 0;
57 | }
58 |
--------------------------------------------------------------------------------
/pthread_attr_setscope.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_attr_setscope.c
3 | *
4 | * Description:
5 | * This translation unit implements operations on thread attribute objects.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 | /* ignore warning "unreferenced formal parameter" */
43 | #if defined(_MSC_VER)
44 | #pragma warning( disable : 4100 )
45 | #endif
46 |
47 | int
48 | pthread_attr_setscope (pthread_attr_t * attr, int contentionscope)
49 | {
50 | #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
51 | switch (contentionscope)
52 | {
53 | case PTHREAD_SCOPE_SYSTEM:
54 | (*attr)->contentionscope = contentionscope;
55 | return 0;
56 | case PTHREAD_SCOPE_PROCESS:
57 | return ENOTSUP;
58 | default:
59 | return EINVAL;
60 | }
61 | #else
62 | return ENOSYS;
63 | #endif
64 | }
65 |
--------------------------------------------------------------------------------
/pthread_barrier_init.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_barrier_init.c
3 | *
4 | * Description:
5 | * This translation unit implements barrier primitives.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 |
43 | int
44 | pthread_barrier_init (pthread_barrier_t * barrier,
45 | const pthread_barrierattr_t * attr, unsigned int count)
46 | {
47 | pthread_barrier_t b;
48 |
49 | if (barrier == NULL || count == 0)
50 | {
51 | return EINVAL;
52 | }
53 |
54 | if (NULL != (b = (pthread_barrier_t) calloc (1, sizeof (*b))))
55 | {
56 | b->pshared = (attr != NULL && *attr != NULL
57 | ? (*attr)->pshared : PTHREAD_PROCESS_PRIVATE);
58 |
59 | b->nCurrentBarrierHeight = b->nInitialBarrierHeight = count;
60 | b->lock = 0;
61 |
62 | if (0 == sem_init (&(b->semBarrierBreeched), b->pshared, 0))
63 | {
64 | *barrier = b;
65 | return 0;
66 | }
67 | (void) free (b);
68 | }
69 |
70 | return ENOMEM;
71 | }
72 |
--------------------------------------------------------------------------------
/pthread_getconcurrency.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_getconcurrency.c
3 | *
4 | * Description:
5 | * This translation unit implements miscellaneous thread functions.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 |
43 | int
44 | pthread_getconcurrency (void)
45 | {
46 | return __ptw32_concurrency;
47 | }
48 |
--------------------------------------------------------------------------------
/pthread_getname_np.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_getname_np.c
3 | *
4 | * --------------------------------------------------------------------------
5 | *
6 | * Pthreads4w - POSIX Threads for Windows
7 | * Copyright 1998 John E. Bossom
8 | * Copyright 1999-2018, Pthreads4w contributors
9 | *
10 | * Homepage: https://sourceforge.net/projects/pthreads4w/
11 | *
12 | * The current list of contributors is contained
13 | * in the file CONTRIBUTORS included with the source
14 | * code distribution. The list can also be seen at the
15 | * following World Wide Web location:
16 | *
17 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
18 | *
19 | * Licensed under the Apache License, Version 2.0 (the "License");
20 | * you may not use this file except in compliance with the License.
21 | * You may obtain a copy of the License at
22 | *
23 | * http://www.apache.org/licenses/LICENSE-2.0
24 | *
25 | * Unless required by applicable law or agreed to in writing, software
26 | * distributed under the License is distributed on an "AS IS" BASIS,
27 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 | * See the License for the specific language governing permissions and
29 | * limitations under the License.
30 | */
31 |
32 | #ifdef HAVE_CONFIG_H
33 | # include
34 | #endif
35 |
36 | #include "pthread.h"
37 | #include "implement.h"
38 |
39 | int
40 | pthread_getname_np(pthread_t thr, char *name, int len)
41 | {
42 | __ptw32_mcs_local_node_t threadLock;
43 | __ptw32_thread_t * tp;
44 | char * s, * d;
45 | int result;
46 |
47 | /*
48 | * Validate the thread id. This method works for pthreads-win32 because
49 | * pthread_kill and pthread_t are designed to accommodate it, but the
50 | * method is not portable.
51 | */
52 | result = pthread_kill (thr, 0);
53 | if (0 != result)
54 | {
55 | return result;
56 | }
57 |
58 | tp = (__ptw32_thread_t *) thr.p;
59 |
60 | __ptw32_mcs_lock_acquire (&tp->threadLock, &threadLock);
61 |
62 | for (s = tp->name, d = name; *s && d < &name[len - 1]; *d++ = *s++)
63 | {}
64 |
65 | *d = '\0';
66 | __ptw32_mcs_lock_release (&threadLock);
67 |
68 | return result;
69 | }
70 |
--------------------------------------------------------------------------------
/pthread_getunique_np.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_getunique_np.c
3 | *
4 | * Description:
5 | * This translation unit implements non-portable thread functions.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 | /*
43 | *
44 | */
45 | unsigned __int64
46 | pthread_getunique_np (pthread_t thread)
47 | {
48 | return ((__ptw32_thread_t*)thread.p)->seqNumber;
49 | }
50 |
--------------------------------------------------------------------------------
/pthread_getw32threadhandle_np.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_getw32threadhandle_np.c
3 | *
4 | * Description:
5 | * This translation unit implements non-portable thread functions.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 | /*
43 | * pthread_getw32threadhandle_np()
44 | *
45 | * Returns the win32 thread handle that the POSIX
46 | * thread "thread" is running as.
47 | *
48 | * Applications can use the win32 handle to set
49 | * win32 specific attributes of the thread.
50 | */
51 | HANDLE
52 | pthread_getw32threadhandle_np (pthread_t thread)
53 | {
54 | return ((__ptw32_thread_t *)thread.p)->threadH;
55 | }
56 |
57 | /*
58 | * pthread_getw32threadid_np()
59 | *
60 | * Returns the win32 thread id that the POSIX
61 | * thread "thread" is running as.
62 | */
63 | DWORD
64 | pthread_getw32threadid_np (pthread_t thread)
65 | {
66 | return ((__ptw32_thread_t *)thread.p)->thread;
67 | }
68 |
--------------------------------------------------------------------------------
/pthread_mutexattr_getkind_np.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_mutexattr_getkind_np.c
3 | *
4 | * Description:
5 | * This translation unit implements non-portable thread functions.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 | int
43 | pthread_mutexattr_getkind_np (pthread_mutexattr_t * attr, int *kind)
44 | {
45 | return pthread_mutexattr_gettype (attr, kind);
46 | }
47 |
--------------------------------------------------------------------------------
/pthread_mutexattr_gettype.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_mutexattr_gettype.c
3 | *
4 | * Description:
5 | * This translation unit implements mutual exclusion (mutex) primitives.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 |
43 | int
44 | pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *kind)
45 | {
46 | int result = 0;
47 |
48 | if (attr != NULL && *attr != NULL && kind != NULL)
49 | {
50 | *kind = (*attr)->kind;
51 | }
52 | else
53 | {
54 | result = EINVAL;
55 | }
56 |
57 | return (result);
58 | }
59 |
--------------------------------------------------------------------------------
/pthread_mutexattr_setkind_np.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_mutexattr_setkind_np.c
3 | *
4 | * Description:
5 | * This translation unit implements non-portable thread functions.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 | int
43 | pthread_mutexattr_setkind_np (pthread_mutexattr_t * attr, int kind)
44 | {
45 | return pthread_mutexattr_settype (attr, kind);
46 | }
47 |
--------------------------------------------------------------------------------
/pthread_num_processors_np.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_num_processors_np.c
3 | *
4 | * Description:
5 | * This translation unit implements non-portable thread functions.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 | /*
43 | * pthread_num_processors_np()
44 | *
45 | * Get the number of CPUs available to the process.
46 | */
47 | int
48 | pthread_num_processors_np (void)
49 | {
50 | int count;
51 |
52 | if (__ptw32_getprocessors (&count) != 0)
53 | {
54 | count = 1;
55 | }
56 |
57 | return (count);
58 | }
59 |
--------------------------------------------------------------------------------
/pthread_setconcurrency.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_setconcurrency.c
3 | *
4 | * Description:
5 | * This translation unit implements miscellaneous thread functions.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 |
43 | int
44 | pthread_setconcurrency (int level)
45 | {
46 | if (level < 0)
47 | {
48 | return EINVAL;
49 | }
50 | else
51 | {
52 | __ptw32_concurrency = level;
53 | return 0;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/pthread_spin_unlock.c:
--------------------------------------------------------------------------------
1 | /*
2 | * pthread_spin_unlock.c
3 | *
4 | * Description:
5 | * This translation unit implements spin lock primitives.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 |
43 | int
44 | pthread_spin_unlock (pthread_spinlock_t * lock)
45 | {
46 | register pthread_spinlock_t s;
47 |
48 | if (NULL == lock || NULL == *lock)
49 | {
50 | return (EINVAL);
51 | }
52 |
53 | s = *lock;
54 |
55 | if (s == PTHREAD_SPINLOCK_INITIALIZER)
56 | {
57 | return EPERM;
58 | }
59 |
60 | switch ((long)
61 | __PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG ((__PTW32_INTERLOCKED_LONGPTR) &s->interlock,
62 | (__PTW32_INTERLOCKED_LONG) __PTW32_SPIN_UNLOCKED,
63 | (__PTW32_INTERLOCKED_LONG) __PTW32_SPIN_LOCKED))
64 | {
65 | case __PTW32_SPIN_LOCKED:
66 | case __PTW32_SPIN_UNLOCKED:
67 | return 0;
68 | case __PTW32_SPIN_USE_MUTEX:
69 | return pthread_mutex_unlock (&(s->u.mutex));
70 | }
71 |
72 | return EINVAL;
73 | }
74 |
--------------------------------------------------------------------------------
/ptw32_calloc.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ptw32_calloc.c
3 | *
4 | * Description:
5 | * This translation unit implements miscellaneous thread functions.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 |
43 | #if defined(NEED_CALLOC)
44 | void *
45 | __ptw32_calloc (size_t n, size_t s)
46 | {
47 | unsigned int m = n * s;
48 | void *p;
49 |
50 | p = malloc (m);
51 | if (p == NULL)
52 | return NULL;
53 |
54 | memset (p, 0, m);
55 |
56 | return p;
57 | }
58 | #endif
59 |
--------------------------------------------------------------------------------
/ptw32_is_attr.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ptw32_is_attr.c
3 | *
4 | * Description:
5 | * This translation unit implements operations on thread attribute objects.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 | int
43 | __ptw32_is_attr (const pthread_attr_t * attr)
44 | {
45 | /* Return 0 if the attr object is valid, non-zero otherwise. */
46 |
47 | return (attr == NULL ||
48 | *attr == NULL || (*attr)->valid != __PTW32_ATTR_VALID);
49 | }
50 |
--------------------------------------------------------------------------------
/ptw32_rwlock_cancelwrwait.c:
--------------------------------------------------------------------------------
1 | /*
2 | * ptw32_rwlock_cancelwrwait.c
3 | *
4 | * Description:
5 | * This translation unit implements read/write lock primitives.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 |
42 | void
43 | __ptw32_rwlock_cancelwrwait (void *arg)
44 | {
45 | pthread_rwlock_t rwl = (pthread_rwlock_t) arg;
46 |
47 | rwl->nSharedAccessCount = -rwl->nCompletedSharedAccessCount;
48 | rwl->nCompletedSharedAccessCount = 0;
49 |
50 | (void) pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted));
51 | (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess));
52 | }
53 |
--------------------------------------------------------------------------------
/sched_getscheduler.c:
--------------------------------------------------------------------------------
1 | /*
2 | * sched_getscheduler.c
3 | *
4 | * Description:
5 | * POSIX thread functions that deal with thread scheduling.
6 | *
7 | * --------------------------------------------------------------------------
8 | *
9 | * Pthreads4w - POSIX Threads for Windows
10 | * Copyright 1998 John E. Bossom
11 | * Copyright 1999-2018, Pthreads4w contributors
12 | *
13 | * Homepage: https://sourceforge.net/projects/pthreads4w/
14 | *
15 | * The current list of contributors is contained
16 | * in the file CONTRIBUTORS included with the source
17 | * code distribution. The list can also be seen at the
18 | * following World Wide Web location:
19 | *
20 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
21 | *
22 | * Licensed under the Apache License, Version 2.0 (the "License");
23 | * you may not use this file except in compliance with the License.
24 | * You may obtain a copy of the License at
25 | *
26 | * http://www.apache.org/licenses/LICENSE-2.0
27 | *
28 | * Unless required by applicable law or agreed to in writing, software
29 | * distributed under the License is distributed on an "AS IS" BASIS,
30 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 | * See the License for the specific language governing permissions and
32 | * limitations under the License.
33 | */
34 |
35 | #ifdef HAVE_CONFIG_H
36 | # include
37 | #endif
38 |
39 | #include "pthread.h"
40 | #include "implement.h"
41 | #include "sched.h"
42 |
43 | int
44 | sched_getscheduler (pid_t pid)
45 | {
46 | /*
47 | * Win32 only has one policy which we call SCHED_OTHER.
48 | * However, we try to provide other valid side-effects
49 | * such as EPERM and ESRCH errors.
50 | */
51 | if (0 != pid)
52 | {
53 | int selfPid = (int) GetCurrentProcessId ();
54 |
55 | if (pid != selfPid)
56 | {
57 | HANDLE h =
58 | OpenProcess (PROCESS_QUERY_INFORMATION, __PTW32_FALSE, (DWORD) pid);
59 |
60 | if (NULL == h)
61 | {
62 | __PTW32_SET_ERRNO(((0xFF & ERROR_ACCESS_DENIED) == GetLastError()) ? EPERM : ESRCH);
63 | return -1;
64 | }
65 | else
66 | CloseHandle(h);
67 | }
68 | }
69 |
70 | return SCHED_OTHER;
71 | }
72 |
--------------------------------------------------------------------------------
/sem_close.c:
--------------------------------------------------------------------------------
1 | /*
2 | * -------------------------------------------------------------
3 | *
4 | * Module: sem_close.c
5 | *
6 | * Purpose:
7 | * Semaphores aren't actually part of the PThreads standard.
8 | * They are defined by the POSIX Standard:
9 | *
10 | * POSIX 1003.1b-1993 (POSIX.1b)
11 | *
12 | * -------------------------------------------------------------
13 | *
14 | * --------------------------------------------------------------------------
15 | *
16 | * Pthreads4w - POSIX Threads for Windows
17 | * Copyright 1998 John E. Bossom
18 | * Copyright 1999-2018, Pthreads4w contributors
19 | *
20 | * Homepage: https://sourceforge.net/projects/pthreads4w/
21 | *
22 | * The current list of contributors is contained
23 | * in the file CONTRIBUTORS included with the source
24 | * code distribution. The list can also be seen at the
25 | * following World Wide Web location:
26 | *
27 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
28 | *
29 | * Licensed under the Apache License, Version 2.0 (the "License");
30 | * you may not use this file except in compliance with the License.
31 | * You may obtain a copy of the License at
32 | *
33 | * http://www.apache.org/licenses/LICENSE-2.0
34 | *
35 | * Unless required by applicable law or agreed to in writing, software
36 | * distributed under the License is distributed on an "AS IS" BASIS,
37 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 | * See the License for the specific language governing permissions and
39 | * limitations under the License.
40 | */
41 |
42 | #ifdef HAVE_CONFIG_H
43 | # include
44 | #endif
45 |
46 | #include "pthread.h"
47 | #include "semaphore.h"
48 | #include "implement.h"
49 |
50 | /* ignore warning "unreferenced formal parameter" */
51 | #if defined(_MSC_VER)
52 | #pragma warning( disable : 4100 )
53 | #endif
54 |
55 | int
56 | sem_close (sem_t * sem)
57 | {
58 | __PTW32_SET_ERRNO(ENOSYS);
59 | return -1;
60 | } /* sem_close */
61 |
--------------------------------------------------------------------------------
/sem_open.c:
--------------------------------------------------------------------------------
1 | /*
2 | * -------------------------------------------------------------
3 | *
4 | * Module: sem_open.c
5 | *
6 | * Purpose:
7 | * Semaphores aren't actually part of the PThreads standard.
8 | * They are defined by the POSIX Standard:
9 | *
10 | * POSIX 1003.1b-1993 (POSIX.1b)
11 | *
12 | * -------------------------------------------------------------
13 | *
14 | * --------------------------------------------------------------------------
15 | *
16 | * Pthreads4w - POSIX Threads for Windows
17 | * Copyright 1998 John E. Bossom
18 | * Copyright 1999-2018, Pthreads4w contributors
19 | *
20 | * Homepage: https://sourceforge.net/projects/pthreads4w/
21 | *
22 | * The current list of contributors is contained
23 | * in the file CONTRIBUTORS included with the source
24 | * code distribution. The list can also be seen at the
25 | * following World Wide Web location:
26 | *
27 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
28 | *
29 | * Licensed under the Apache License, Version 2.0 (the "License");
30 | * you may not use this file except in compliance with the License.
31 | * You may obtain a copy of the License at
32 | *
33 | * http://www.apache.org/licenses/LICENSE-2.0
34 | *
35 | * Unless required by applicable law or agreed to in writing, software
36 | * distributed under the License is distributed on an "AS IS" BASIS,
37 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 | * See the License for the specific language governing permissions and
39 | * limitations under the License.
40 | */
41 |
42 | #ifdef HAVE_CONFIG_H
43 | # include
44 | #endif
45 |
46 | #include "pthread.h"
47 | #include "semaphore.h"
48 | #include "implement.h"
49 |
50 | /* ignore warning "unreferenced formal parameter" */
51 | #if defined(_MSC_VER)
52 | #pragma warning( disable : 4100 )
53 | #endif
54 |
55 | sem_t
56 | *sem_open (const char *name, int oflag, ...)
57 | {
58 | /* Note: this is a POSIX.1b-1993 conforming stub; POSIX.1-2001 removed
59 | * the requirement to provide this stub, and also removed the validity
60 | * of ENOSYS as a resultant errno state; nevertheless, it makes sense
61 | * to retain the POSIX.1b-1993 conforming behaviour here.
62 | */
63 | __PTW32_SET_ERRNO(ENOSYS);
64 | return SEM_FAILED;
65 | } /* sem_open */
66 |
--------------------------------------------------------------------------------
/sem_unlink.c:
--------------------------------------------------------------------------------
1 | /*
2 | * -------------------------------------------------------------
3 | *
4 | * Module: sem_unlink.c
5 | *
6 | * Purpose:
7 | * Semaphores aren't actually part of the PThreads standard.
8 | * They are defined by the POSIX Standard:
9 | *
10 | * POSIX 1003.1b-1993 (POSIX.1b)
11 | *
12 | * -------------------------------------------------------------
13 | *
14 | * --------------------------------------------------------------------------
15 | *
16 | * Pthreads4w - POSIX Threads for Windows
17 | * Copyright 1998 John E. Bossom
18 | * Copyright 1999-2018, Pthreads4w contributors
19 | *
20 | * Homepage: https://sourceforge.net/projects/pthreads4w/
21 | *
22 | * The current list of contributors is contained
23 | * in the file CONTRIBUTORS included with the source
24 | * code distribution. The list can also be seen at the
25 | * following World Wide Web location:
26 | *
27 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
28 | *
29 | * Licensed under the Apache License, Version 2.0 (the "License");
30 | * you may not use this file except in compliance with the License.
31 | * You may obtain a copy of the License at
32 | *
33 | * http://www.apache.org/licenses/LICENSE-2.0
34 | *
35 | * Unless required by applicable law or agreed to in writing, software
36 | * distributed under the License is distributed on an "AS IS" BASIS,
37 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38 | * See the License for the specific language governing permissions and
39 | * limitations under the License.
40 | */
41 |
42 | #ifdef HAVE_CONFIG_H
43 | # include
44 | #endif
45 |
46 | #include "pthread.h"
47 | #include "semaphore.h"
48 | #include "implement.h"
49 |
50 | /* ignore warning "unreferenced formal parameter" */
51 | #if defined(_MSC_VER)
52 | #pragma warning( disable : 4100 )
53 | #endif
54 |
55 | int
56 | sem_unlink (const char *name)
57 | {
58 | __PTW32_SET_ERRNO(ENOSYS);
59 | return -1;
60 | } /* sem_unlink */
61 |
--------------------------------------------------------------------------------
/tests/Debug.dsw:
--------------------------------------------------------------------------------
1 | Microsoft Developer Studio Workspace File, Format Version 6.00
2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
3 |
4 | ###############################################################################
5 |
6 | Project: "Debug"=.\Debug.dsp - Package Owner=<4>
7 |
8 | Package=<5>
9 | {{{
10 | }}}
11 |
12 | Package=<4>
13 | {{{
14 | }}}
15 |
16 | ###############################################################################
17 |
18 | Global:
19 |
20 | Package=<5>
21 | {{{
22 | }}}
23 |
24 | Package=<3>
25 | {{{
26 | }}}
27 |
28 | ###############################################################################
29 |
30 |
--------------------------------------------------------------------------------
/tests/Debug.plg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Build Log
5 |
6 | --------------------Configuration: Debug - Win32 Debug--------------------
7 |
8 | Command Lines
9 | Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP9.tmp" with contents
10 | [
11 | /nologo /MDd /W3 /WX /Gm /ZI /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "CLEANUP_C" /FR"Debug/" /Fp"Debug/Debug.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
12 | "E:\PTHREADS\pthreads.2\tests\semaphore1.c"
13 | ]
14 | Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP9.tmp"
15 | Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSPA.tmp" with contents
16 | [
17 | kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib pthreadVC2d.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/Debug.pdb" /debug /machine:I386 /out:"Debug/Debug.exe" /pdbtype:sept /libpath:".."
18 | .\Debug\semaphore1.obj
19 | ]
20 | Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSPA.tmp"
21 | Output Window
22 | Compiling...
23 | semaphore1.c
24 | Linking...
25 |
26 |
27 |
28 | Results
29 | Debug.exe - 0 error(s), 0 warning(s)
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/tests/Debug.txt:
--------------------------------------------------------------------------------
1 | This project is used to debug individual test case programs.
2 |
3 | To build and debug a test case:
4 | - add the .c file to this project;
5 | - remove any .c files from other test cases from this project.
6 | - build and debug as usual.
--------------------------------------------------------------------------------
/tests/README:
--------------------------------------------------------------------------------
1 | Running test cases in this directory
2 | ------------------------------------
3 |
4 | These make scripts expect to be able to copy the dll, library
5 | and header files from this directory's parent directory,
6 | which should be the pthreads-win32 source directory.
7 |
8 | MS VC nmake
9 | -------------
10 |
11 | Run the target corresponding to the DLL version being tested:
12 |
13 | nmake clean VC
14 |
15 | or:
16 |
17 | nmake clean VS
18 |
19 |
20 | GNU GCC make
21 | ------------
22 |
23 | Run "make clean" and then "make". See the "Known bugs" section
24 | in ..\README.
25 |
26 |
27 | Writing Test Cases
28 | ------------------
29 |
30 | Tests written in this test suite should behave in the following manner:
31 |
32 | * If a test fails, leave main() with a result of 1.
33 |
34 | * If a test succeeds, leave main() with a result of 0.
35 |
36 | * No diagnostic output should appear when the test is succeeding
37 | unless it is particularly useful to visualise test behaviour.
38 | Diagnostic output should be emitted if something in the test
39 | fails, to help determine the cause of the test failure. Use assert()
40 | for all API calls if possible.
41 |
42 | Notes:
43 | ------
44 |
45 | Many test cases use knowledge of implementation internals which are supposed
46 | to be opaque to portable applications. These should not be used as examples
47 | of methods that can be conformantly applied to application code.
48 |
--------------------------------------------------------------------------------
/tests/README.BENCHTESTS:
--------------------------------------------------------------------------------
1 |
2 | ------------
3 | Benchmarking
4 | ------------
5 | There is a set a benchmarking programs in the
6 | "tests" directory. These should be runnable using the
7 | following command-lines corresponding to each of the possible
8 | library builds:
9 |
10 | MSVC:
11 | nmake clean VC-bench
12 | nmake clean VCE-bench
13 | nmake clean VSE-bench
14 |
15 | Mingw32:
16 | make clean GC-bench
17 | make clean GCE-bench
18 |
19 | UWIN:
20 | The benchtests are run as part of the testsuite.
21 |
22 |
23 | Mutex benchtests
24 | ----------------
25 |
26 | benchtest1 - Lock plus unlock on an unlocked mutex.
27 | benchtest2 - Lock plus unlock on a locked mutex.
28 | benchtest3 - Trylock on a locked mutex.
29 | benchtest4 - Trylock plus unlock on an unlocked mutex.
30 |
31 |
32 | Each test times up to three alternate synchronisation
33 | implementations as a reference, and then times each of
34 | the four mutex types provided by the library. Each is
35 | described below:
36 |
37 | Simple Critical Section
38 | - uses a simple Win32 critical section. There is no
39 | additional overhead for this case as there is in the
40 | remaining cases.
41 |
42 | POSIX mutex implemented using a Critical Section
43 | - The old implementation which uses runtime adaptation
44 | depending on the Windows variant being run on. When
45 | the pthreads DLL was run on WinNT or higher then
46 | POSIX mutexes would use Win32 Critical Sections.
47 |
48 | POSIX mutex implemented using a Win32 Mutex
49 | - The old implementation which uses runtime adaptation
50 | depending on the Windows variant being run on. When
51 | the pthreads DLL was run on Win9x then POSIX mutexes
52 | would use Win32 Mutexes (because TryEnterCriticalSection
53 | is not implemented on Win9x).
54 |
55 | PTHREAD_MUTEX_DEFAULT
56 | PTHREAD_MUTEX_NORMAL
57 | PTHREAD_MUTEX_ERRORCHECK
58 | PTHREAD_MUTEX_RECURSIVE
59 | - The current implementation supports these mutex types.
60 | The underlying basis of POSIX mutexes is now the same
61 | irrespective of the Windows variant, and should therefore
62 | have consistent performance.
63 |
64 |
65 | Semaphore benchtests
66 | --------------------
67 |
68 | benchtest5 - Timing for various uncontended cases.
69 |
70 |
71 | In all benchtests, the operation is repeated a large
72 | number of times and an average is calculated. Loop
73 | overhead is measured and subtracted from all test times.
74 |
75 |
--------------------------------------------------------------------------------
/tests/barrier1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * barrier1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Create a barrier object and then destroy it.
35 | *
36 | */
37 |
38 | #include "test.h"
39 |
40 | pthread_barrier_t barrier = NULL;
41 |
42 | int
43 | main()
44 | {
45 | assert(barrier == NULL);
46 |
47 | assert(pthread_barrier_init(&barrier, NULL, 1) == 0);
48 |
49 | assert(barrier != NULL);
50 |
51 | assert(pthread_barrier_destroy(&barrier) == 0);
52 |
53 | assert(barrier == NULL);
54 |
55 | return 0;
56 | }
57 |
--------------------------------------------------------------------------------
/tests/barrier2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * barrier2.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a single barrier object, wait on it,
35 | * and then destroy it.
36 | *
37 | */
38 |
39 | #include "test.h"
40 |
41 | pthread_barrier_t barrier = NULL;
42 |
43 | int
44 | main()
45 | {
46 | assert(pthread_barrier_init(&barrier, NULL, 1) == 0);
47 |
48 | assert(pthread_barrier_wait(&barrier) == PTHREAD_BARRIER_SERIAL_THREAD);
49 |
50 | assert(pthread_barrier_destroy(&barrier) == 0);
51 |
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/tests/barrier3.c:
--------------------------------------------------------------------------------
1 | /*
2 | * barrier3.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a single barrier object with barrier attribute, wait on it,
35 | * and then destroy it.
36 | *
37 | */
38 |
39 | #include "test.h"
40 |
41 | pthread_barrier_t barrier = NULL;
42 | static void* result = (void*)1;
43 |
44 | void * func(void * arg)
45 | {
46 | return (void *) (size_t)pthread_barrier_wait(&barrier);
47 | }
48 |
49 | int
50 | main()
51 | {
52 | pthread_t t;
53 | pthread_barrierattr_t ba;
54 |
55 | assert(pthread_barrierattr_init(&ba) == 0);
56 | assert(pthread_barrierattr_setpshared(&ba, PTHREAD_PROCESS_PRIVATE) == 0);
57 | assert(pthread_barrier_init(&barrier, &ba, 1) == 0);
58 |
59 | assert(pthread_create(&t, NULL, func, NULL) == 0);
60 |
61 | assert(pthread_join(t, &result) == 0);
62 |
63 | assert((int)(size_t)result == PTHREAD_BARRIER_SERIAL_THREAD);
64 |
65 | assert(pthread_barrier_destroy(&barrier) == 0);
66 | assert(pthread_barrierattr_destroy(&ba) == 0);
67 |
68 | return 0;
69 | }
70 |
--------------------------------------------------------------------------------
/tests/benchtest.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | *
4 | * --------------------------------------------------------------------------
5 | *
6 | * Pthreads4w - POSIX Threads for Windows
7 | * Copyright 1998 John E. Bossom
8 | * Copyright 1999-2018, Pthreads4w contributors
9 | *
10 | * Homepage: https://sourceforge.net/projects/pthreads4w/
11 | *
12 | * The current list of contributors is contained
13 | * in the file CONTRIBUTORS included with the source
14 | * code distribution. The list can also be seen at the
15 | * following World Wide Web location:
16 | *
17 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
18 | *
19 | * Licensed under the Apache License, Version 2.0 (the "License");
20 | * you may not use this file except in compliance with the License.
21 | * You may obtain a copy of the License at
22 | *
23 | * http://www.apache.org/licenses/LICENSE-2.0
24 | *
25 | * Unless required by applicable law or agreed to in writing, software
26 | * distributed under the License is distributed on an "AS IS" BASIS,
27 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 | * See the License for the specific language governing permissions and
29 | * limitations under the License.
30 | *
31 | */
32 |
33 | #include "../config.h"
34 |
35 | enum {
36 | OLD_WIN32CS,
37 | OLD_WIN32MUTEX
38 | };
39 |
40 | extern int old_mutex_use;
41 |
42 | struct old_mutex_t_ {
43 | HANDLE mutex;
44 | CRITICAL_SECTION cs;
45 | };
46 |
47 | typedef struct old_mutex_t_ * old_mutex_t;
48 |
49 | struct old_mutexattr_t_ {
50 | int pshared;
51 | };
52 |
53 | typedef struct old_mutexattr_t_ * old_mutexattr_t;
54 |
55 | extern BOOL (WINAPI *__ptw32_try_enter_critical_section)(LPCRITICAL_SECTION);
56 | extern HINSTANCE __ptw32_h_kernel32;
57 |
58 | #define __PTW32_OBJECT_AUTO_INIT ((void *) -1)
59 |
60 | void dummy_call(int * a);
61 | void interlocked_inc_with_conditionals(int *a);
62 | void interlocked_dec_with_conditionals(int *a);
63 | int old_mutex_init(old_mutex_t *mutex, const old_mutexattr_t *attr);
64 | int old_mutex_lock(old_mutex_t *mutex);
65 | int old_mutex_unlock(old_mutex_t *mutex);
66 | int old_mutex_trylock(old_mutex_t *mutex);
67 | int old_mutex_destroy(old_mutex_t *mutex);
68 | /****************************************************************************************/
69 |
--------------------------------------------------------------------------------
/tests/create1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * create1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Description:
35 | * Create a thread and check that it ran.
36 | *
37 | * Depends on API functions: None.
38 | */
39 |
40 | #include "test.h"
41 |
42 | static int washere = 0;
43 |
44 | void * func(void * arg)
45 | {
46 | washere = 1;
47 | return 0;
48 | }
49 |
50 | int
51 | main()
52 | {
53 | pthread_t t;
54 |
55 | assert(pthread_create(&t, NULL, func, NULL) == 0);
56 |
57 | /* A dirty hack, but we cannot rely on pthread_join in this
58 | primitive test. */
59 | Sleep(2000);
60 |
61 | assert(washere == 1);
62 |
63 | return 0;
64 | }
65 |
--------------------------------------------------------------------------------
/tests/delay1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * delay1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on API functions:
35 | * pthread_delay_np
36 | */
37 |
38 | #include "test.h"
39 |
40 | int
41 | main(int argc, char * argv[])
42 | {
43 | struct timespec interval = {1L, 500000000L};
44 |
45 | assert(pthread_delay_np(&interval) == 0);
46 |
47 | return 0;
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/tests/delay2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * delay1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on API functions:
35 | * pthread_delay_np
36 | */
37 |
38 | #include "test.h"
39 |
40 | pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
41 |
42 | void *
43 | func(void * arg)
44 | {
45 | struct timespec interval = {5, 500000000L};
46 |
47 | assert(pthread_mutex_lock(&mx) == 0);
48 |
49 | #ifdef _MSC_VER
50 | #pragma inline_depth(0)
51 | #endif
52 | pthread_cleanup_push(pthread_mutex_unlock, &mx);
53 | assert(pthread_delay_np(&interval) == 0);
54 | pthread_cleanup_pop(1);
55 | #ifdef _MSC_VER
56 | #pragma inline_depth()
57 | #endif
58 |
59 | return (void *)(size_t)1;
60 | }
61 |
62 | int
63 | main(int argc, char * argv[])
64 | {
65 | pthread_t t;
66 | void* result = (void*)0;
67 |
68 | assert(pthread_mutex_lock(&mx) == 0);
69 |
70 | assert(pthread_create(&t, NULL, func, NULL) == 0);
71 | assert(pthread_cancel(t) == 0);
72 |
73 | assert(pthread_mutex_unlock(&mx) == 0);
74 |
75 | assert(pthread_join(t, &result) == 0);
76 | assert(result == (void*)PTHREAD_CANCELED);
77 |
78 | return 0;
79 | }
80 |
81 |
--------------------------------------------------------------------------------
/tests/equal1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test for pthread_equal.
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on functions: pthread_create().
35 | */
36 |
37 | #include "test.h"
38 |
39 | void * func(void * arg)
40 | {
41 | Sleep(2000);
42 | return 0;
43 | }
44 |
45 | int
46 | main()
47 | {
48 | pthread_t t1, t2;
49 |
50 | assert(pthread_create(&t1, NULL, func, (void *) 1) == 0);
51 |
52 | assert(pthread_create(&t2, NULL, func, (void *) 2) == 0);
53 |
54 | assert(pthread_equal(t1, t2) == 0);
55 |
56 | assert(pthread_equal(t1,t1) != 0);
57 |
58 | /* This is a hack. We don't want to rely on pthread_join
59 | yet if we can help it. */
60 | Sleep(4000);
61 |
62 | /* Success. */
63 | return 0;
64 | }
65 |
--------------------------------------------------------------------------------
/tests/exit1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test for pthread_exit().
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on API functions: None.
35 | */
36 |
37 | #include "test.h"
38 |
39 | int
40 | main(int argc, char * argv[])
41 | {
42 | /* A simple test first. */
43 | pthread_exit((void *) 0);
44 |
45 | /* Not reached */
46 | return 1;
47 | }
48 |
--------------------------------------------------------------------------------
/tests/exit2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test for pthread_exit().
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on API functions:
35 | * pthread_create()
36 | * pthread_exit()
37 | */
38 |
39 | #include "test.h"
40 |
41 | void *
42 | func(void * arg)
43 | {
44 | int failed = (int) arg;
45 |
46 | pthread_exit(arg);
47 |
48 | /* Never reached. */
49 | /*
50 | * Trick gcc compiler into not issuing a warning here
51 | */
52 | assert(failed - (int)arg);
53 |
54 | return NULL;
55 | }
56 |
57 | int
58 | main(int argc, char * argv[])
59 | {
60 | pthread_t t;
61 |
62 | assert(pthread_create(&t, NULL, func, (void *) NULL) == 0);
63 |
64 | Sleep(100);
65 |
66 | return 0;
67 | }
68 |
--------------------------------------------------------------------------------
/tests/exit3.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test for pthread_exit().
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on API functions: pthread_create().
35 | */
36 |
37 | #include "test.h"
38 |
39 | void *
40 | func(void * arg)
41 | {
42 | int failed = (int) arg;
43 |
44 | pthread_exit(arg);
45 |
46 | /* Never reached. */
47 | /*
48 | * assert(0) in a way to prevent warning or optimising away.
49 | */
50 | assert(failed - (int) arg);
51 |
52 | return NULL;
53 | }
54 |
55 | int
56 | main(int argc, char * argv[])
57 | {
58 | pthread_t id[4];
59 | int i;
60 |
61 | /* Create a few threads and then exit. */
62 | for (i = 0; i < 4; i++)
63 | {
64 | assert(pthread_create(&id[i], NULL, func, (void *)(size_t)i) == 0);
65 | }
66 |
67 | Sleep(400);
68 |
69 | /* Success. */
70 | return 0;
71 | }
72 |
--------------------------------------------------------------------------------
/tests/exit6.c:
--------------------------------------------------------------------------------
1 | /*
2 | * exit6.c
3 | *
4 | * Created on: 14/05/2013
5 | * Author: ross
6 | */
7 |
8 | #include "test.h"
9 | #ifndef _UWIN
10 | #include
11 | #endif
12 |
13 | #include
14 | //#include
15 |
16 | static pthread_key_t key;
17 | static int where;
18 |
19 | static unsigned __stdcall
20 | start_routine(void * arg)
21 | {
22 | int *val = (int *) malloc(4);
23 |
24 | where = 2;
25 | //printf("start_routine: native thread\n");
26 |
27 | *val = 48;
28 | pthread_setspecific(key, val);
29 | return 0;
30 | }
31 |
32 | static void
33 | key_dtor(void *arg)
34 | {
35 | //printf("key_dtor: %d\n", *(int*)arg);
36 | if (where == 2)
37 | printf("Library has thread exit POSIX cleanup for native threads.\n");
38 | else
39 | printf("Library has process exit POSIX cleanup for native threads.\n");
40 | free(arg);
41 | }
42 |
43 | int main(int argc, char **argv)
44 | {
45 | HANDLE hthread;
46 |
47 | where = 1;
48 | pthread_key_create(&key, key_dtor);
49 | hthread = (HANDLE)_beginthreadex(NULL, 0, start_routine, NULL, 0, NULL);
50 | WaitForSingleObject(hthread, INFINITE);
51 | CloseHandle(hthread);
52 | where = 3;
53 | pthread_key_delete(key);
54 |
55 | //printf("main: exiting\n");
56 | return 0;
57 | }
58 |
--------------------------------------------------------------------------------
/tests/join0.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test for pthread_join().
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on API functions: pthread_create(), pthread_exit().
35 | */
36 |
37 | #include "test.h"
38 |
39 | void *
40 | func(void * arg)
41 | {
42 | Sleep(2000);
43 |
44 | pthread_exit(arg);
45 |
46 | /* Never reached. */
47 | exit(1);
48 | }
49 |
50 | int
51 | main(int argc, char * argv[])
52 | {
53 | pthread_t id;
54 | void* result = (void*)0;
55 |
56 | /* Create a single thread and wait for it to exit. */
57 | assert(pthread_create(&id, NULL, func, (void *) 123) == 0);
58 |
59 | assert(pthread_join(id, &result) == 0);
60 |
61 | assert((int)(size_t)result == 123);
62 |
63 | /* Success. */
64 | return 0;
65 | }
66 |
--------------------------------------------------------------------------------
/tests/join1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test for pthread_join().
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on API functions: pthread_create(), pthread_join(), pthread_exit().
35 | */
36 |
37 | #include "test.h"
38 |
39 | void *
40 | func(void * arg)
41 | {
42 | int i = (int)(size_t)arg;
43 |
44 | Sleep(i * 100);
45 |
46 | pthread_exit(arg);
47 |
48 | /* Never reached. */
49 | exit(1);
50 | }
51 |
52 | int
53 | main(int argc, char * argv[])
54 | {
55 | pthread_t id[4];
56 | int i;
57 | void* result = (void*)-1;
58 |
59 | /* Create a few threads and then exit. */
60 | for (i = 0; i < 4; i++)
61 | {
62 | assert(pthread_create(&id[i], NULL, func, (void *)(size_t)i) == 0);
63 | }
64 |
65 | /* Some threads will finish before they are joined, some after. */
66 | Sleep(2 * 100 + 50);
67 |
68 | for (i = 0; i < 4; i++)
69 | {
70 | assert(pthread_join(id[i], &result) == 0);
71 | assert((int)(size_t)result == i);
72 | }
73 |
74 | /* Success. */
75 | return 0;
76 | }
77 |
--------------------------------------------------------------------------------
/tests/join2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test for pthread_join() returning return value from threads.
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on API functions: pthread_create().
35 | */
36 |
37 | #include "test.h"
38 |
39 | void *
40 | func(void * arg)
41 | {
42 | Sleep(1000);
43 | return arg;
44 | }
45 |
46 | int
47 | main(int argc, char * argv[])
48 | {
49 | pthread_t id[4];
50 | int i;
51 | void* result = (void*)-1;
52 |
53 | /* Create a few threads and then exit. */
54 | for (i = 0; i < 4; i++)
55 | {
56 | assert(pthread_create(&id[i], NULL, func, (void *)(size_t)i) == 0);
57 | }
58 |
59 | for (i = 0; i < 4; i++)
60 | {
61 | assert(pthread_join(id[i], &result) == 0);
62 | assert((int)(size_t)result == i);
63 | }
64 |
65 | /* Success. */
66 | return 0;
67 | }
68 |
--------------------------------------------------------------------------------
/tests/join3.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Test for pthread_join() returning return value from threads.
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Depends on API functions: pthread_create().
35 | */
36 |
37 | #include "test.h"
38 |
39 | void *
40 | func(void * arg)
41 | {
42 | sched_yield();
43 | return arg;
44 | }
45 |
46 | int
47 | main(int argc, char * argv[])
48 | {
49 | pthread_t id[4];
50 | int i;
51 | void* result = (void*)-1;
52 |
53 | /* Create a few threads and then exit. */
54 | for (i = 0; i < 4; i++)
55 | {
56 | assert(pthread_create(&id[i], NULL, func, (void *)(size_t)i) == 0);
57 | }
58 |
59 | /*
60 | * Let threads exit before we join them.
61 | * We should still retrieve the exit code for the threads.
62 | */
63 | Sleep(1000);
64 |
65 | for (i = 0; i < 4; i++)
66 | {
67 | assert(pthread_join(id[i], &result) == 0);
68 | assert((int)(size_t)result == i);
69 | }
70 |
71 | /* Success. */
72 | return 0;
73 | }
74 |
--------------------------------------------------------------------------------
/tests/kill1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * File: kill1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Test Synopsis:
35 | * - pthread_kill() does not support non zero signals..
36 | *
37 | * Test Method (Validation or Falsification):
38 | * -
39 | *
40 | * Requirements Tested:
41 | * -
42 | *
43 | * Features Tested:
44 | * -
45 | *
46 | * Cases Tested:
47 | * -
48 | *
49 | * Description:
50 | * -
51 | *
52 | * Environment:
53 | * -
54 | *
55 | * Input:
56 | * - None.
57 | *
58 | * Output:
59 | * - File name, Line number, and failed expression on failure.
60 | * - No output on success.
61 | *
62 | * Assumptions:
63 | * -
64 | *
65 | * Pass Criteria:
66 | * - Process returns zero exit status.
67 | *
68 | * Fail Criteria:
69 | * - Process returns non-zero exit status.
70 | */
71 |
72 | #include "test.h"
73 |
74 |
75 | int
76 | main()
77 | {
78 | assert(pthread_kill(pthread_self(), 1) == EINVAL);
79 |
80 | return 0;
81 | }
82 |
--------------------------------------------------------------------------------
/tests/mutex1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Create a simple mutex object, lock it, and then unlock it again.
35 | * This is the simplest test of the pthread mutex family that we can do.
36 | *
37 | * Depends on API functions:
38 | * pthread_mutex_init()
39 | * pthread_mutex_lock()
40 | * pthread_mutex_unlock()
41 | * pthread_mutex_destroy()
42 | */
43 |
44 | #include "test.h"
45 |
46 | pthread_mutex_t mutex = NULL;
47 |
48 | int
49 | main()
50 | {
51 | assert(mutex == NULL);
52 |
53 | assert(pthread_mutex_init(&mutex, NULL) == 0);
54 |
55 | assert(mutex != NULL);
56 |
57 | assert(pthread_mutex_lock(&mutex) == 0);
58 |
59 | assert(pthread_mutex_unlock(&mutex) == 0);
60 |
61 | assert(pthread_mutex_destroy(&mutex) == 0);
62 |
63 | assert(mutex == NULL);
64 |
65 | return 0;
66 | }
67 |
--------------------------------------------------------------------------------
/tests/mutex1e.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex1e.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * As for mutex1.c but with type set to PTHREAD_MUTEX_ERRORCHECK.
35 | *
36 | * Create a simple mutex object, lock it, unlock it, then destroy it.
37 | * This is the simplest test of the pthread mutex family that we can do.
38 | *
39 | * Depends on API functions:
40 | * pthread_mutexattr_settype()
41 | * pthread_mutex_init()
42 | * pthread_mutex_destroy()
43 | */
44 |
45 | #include "test.h"
46 |
47 | pthread_mutex_t mutex = NULL;
48 | pthread_mutexattr_t mxAttr;
49 |
50 | int
51 | main()
52 | {
53 | assert(pthread_mutexattr_init(&mxAttr) == 0);
54 |
55 | BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
56 |
57 | assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_ERRORCHECK) == 0);
58 |
59 | assert(mutex == NULL);
60 |
61 | assert(pthread_mutex_init(&mutex, &mxAttr) == 0);
62 |
63 | assert(mutex != NULL);
64 |
65 | assert(pthread_mutex_lock(&mutex) == 0);
66 |
67 | assert(pthread_mutex_unlock(&mutex) == 0);
68 |
69 | assert(pthread_mutex_destroy(&mutex) == 0);
70 |
71 | assert(mutex == NULL);
72 |
73 | END_MUTEX_STALLED_ROBUST(mxAttr)
74 |
75 | return 0;
76 | }
77 |
--------------------------------------------------------------------------------
/tests/mutex1n.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex1n.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * As for mutex1.c but with type set to PTHREAD_MUTEX_NORMAL.
35 | *
36 | * Create a simple mutex object, lock it, unlock it, then destroy it.
37 | * This is the simplest test of the pthread mutex family that we can do.
38 | *
39 | * Depends on API functions:
40 | * pthread_mutexattr_settype()
41 | * pthread_mutex_init()
42 | * pthread_mutex_destroy()
43 | */
44 |
45 | #include "test.h"
46 |
47 | pthread_mutex_t mutex = NULL;
48 | pthread_mutexattr_t mxAttr;
49 |
50 | int
51 | main()
52 | {
53 | assert(pthread_mutexattr_init(&mxAttr) == 0);
54 |
55 | BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
56 |
57 | assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_NORMAL) == 0);
58 |
59 | assert(mutex == NULL);
60 |
61 | assert(pthread_mutex_init(&mutex, &mxAttr) == 0);
62 |
63 | assert(mutex != NULL);
64 |
65 | assert(pthread_mutex_lock(&mutex) == 0);
66 |
67 | assert(pthread_mutex_unlock(&mutex) == 0);
68 |
69 | assert(pthread_mutex_destroy(&mutex) == 0);
70 |
71 | assert(mutex == NULL);
72 |
73 | END_MUTEX_STALLED_ROBUST(mxAttr)
74 |
75 | return 0;
76 | }
77 |
--------------------------------------------------------------------------------
/tests/mutex1r.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex1r.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * As for mutex1.c but with type set to PTHREAD_MUTEX_RECURSIVE.
35 | *
36 | * Create a simple mutex object, lock it, unlock it, then destroy it.
37 | * This is the simplest test of the pthread mutex family that we can do.
38 | *
39 | * Depends on API functions:
40 | * pthread_mutexattr_settype()
41 | * pthread_mutex_init()
42 | * pthread_mutex_destroy()
43 | */
44 |
45 | #include "test.h"
46 |
47 | pthread_mutex_t mutex = NULL;
48 | pthread_mutexattr_t mxAttr;
49 |
50 | int
51 | main()
52 | {
53 | assert(pthread_mutexattr_init(&mxAttr) == 0);
54 |
55 | BEGIN_MUTEX_STALLED_ROBUST(mxAttr)
56 |
57 | assert(pthread_mutexattr_settype(&mxAttr, PTHREAD_MUTEX_RECURSIVE) == 0);
58 |
59 | assert(mutex == NULL);
60 |
61 | assert(pthread_mutex_init(&mutex, &mxAttr) == 0);
62 |
63 | assert(mutex != NULL);
64 |
65 | assert(pthread_mutex_lock(&mutex) == 0);
66 |
67 | assert(pthread_mutex_unlock(&mutex) == 0);
68 |
69 | assert(pthread_mutex_destroy(&mutex) == 0);
70 |
71 | assert(mutex == NULL);
72 |
73 | END_MUTEX_STALLED_ROBUST(mxAttr)
74 |
75 | return 0;
76 | }
77 |
--------------------------------------------------------------------------------
/tests/mutex2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex2.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static mutex object, lock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_mutex_lock()
39 | * pthread_mutex_unlock()
40 | */
41 |
42 | #include "test.h"
43 |
44 | pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
45 |
46 | int
47 | main()
48 | {
49 | assert(mutex == PTHREAD_MUTEX_INITIALIZER);
50 |
51 | assert(pthread_mutex_lock(&mutex) == 0);
52 |
53 | assert(mutex != PTHREAD_MUTEX_INITIALIZER);
54 |
55 | assert(mutex != NULL);
56 |
57 | assert(pthread_mutex_unlock(&mutex) == 0);
58 |
59 | assert(pthread_mutex_destroy(&mutex) == 0);
60 |
61 | assert(mutex == NULL);
62 |
63 | return 0;
64 | }
65 |
--------------------------------------------------------------------------------
/tests/mutex2e.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex2e.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static mutex object, lock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_mutex_lock()
39 | * pthread_mutex_unlock()
40 | */
41 |
42 | #include "test.h"
43 |
44 | pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
45 |
46 | int
47 | main()
48 | {
49 | assert(mutex == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER);
50 |
51 | assert(pthread_mutex_lock(&mutex) == 0);
52 |
53 | assert(mutex != PTHREAD_ERRORCHECK_MUTEX_INITIALIZER);
54 |
55 | assert(mutex != NULL);
56 |
57 | assert(pthread_mutex_unlock(&mutex) == 0);
58 |
59 | assert(pthread_mutex_destroy(&mutex) == 0);
60 |
61 | assert(mutex == NULL);
62 |
63 | return 0;
64 | }
65 |
--------------------------------------------------------------------------------
/tests/mutex2r.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex2r.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static mutex object, lock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_mutex_lock()
39 | * pthread_mutex_unlock()
40 | */
41 |
42 | #include "test.h"
43 |
44 | pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
45 |
46 | int
47 | main()
48 | {
49 | assert(mutex == PTHREAD_RECURSIVE_MUTEX_INITIALIZER);
50 |
51 | assert(pthread_mutex_lock(&mutex) == 0);
52 |
53 | assert(mutex != PTHREAD_RECURSIVE_MUTEX_INITIALIZER);
54 |
55 | assert(mutex != NULL);
56 |
57 | assert(pthread_mutex_unlock(&mutex) == 0);
58 |
59 | assert(pthread_mutex_destroy(&mutex) == 0);
60 |
61 | assert(mutex == NULL);
62 |
63 | return 0;
64 | }
65 |
--------------------------------------------------------------------------------
/tests/mutex3.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex3.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static mutex object, lock it, trylock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_mutex_lock()
39 | * pthread_mutex_trylock()
40 | * pthread_mutex_unlock()
41 | */
42 |
43 | #include "test.h"
44 |
45 | pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
46 |
47 | static int washere = 0;
48 |
49 | void * func(void * arg)
50 | {
51 | assert(pthread_mutex_trylock(&mutex1) == EBUSY);
52 |
53 | washere = 1;
54 |
55 | return 0;
56 | }
57 |
58 | int
59 | main()
60 | {
61 | pthread_t t;
62 |
63 | assert(pthread_mutex_lock(&mutex1) == 0);
64 |
65 | assert(pthread_create(&t, NULL, func, NULL) == 0);
66 | assert(pthread_join(t, NULL) == 0);
67 |
68 | assert(pthread_mutex_unlock(&mutex1) == 0);
69 |
70 | assert(washere == 1);
71 |
72 | return 0;
73 | }
74 |
--------------------------------------------------------------------------------
/tests/mutex3e.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex3e.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static mutex object, lock it, trylock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_mutex_lock()
39 | * pthread_mutex_trylock()
40 | * pthread_mutex_unlock()
41 | */
42 |
43 | #include "test.h"
44 |
45 | pthread_mutex_t mutex1 = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER;
46 |
47 | static int washere = 0;
48 |
49 | void * func(void * arg)
50 | {
51 | assert(pthread_mutex_trylock(&mutex1) == EBUSY);
52 |
53 | washere = 1;
54 |
55 | return 0;
56 | }
57 |
58 | int
59 | main()
60 | {
61 | pthread_t t;
62 |
63 | assert(pthread_mutex_lock(&mutex1) == 0);
64 |
65 | assert(pthread_create(&t, NULL, func, NULL) == 0);
66 | assert(pthread_join(t, NULL) == 0);
67 |
68 | assert(pthread_mutex_unlock(&mutex1) == 0);
69 |
70 | assert(washere == 1);
71 |
72 | return 0;
73 | }
74 |
--------------------------------------------------------------------------------
/tests/mutex3r.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex3r.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static mutex object, lock it, trylock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_mutex_lock()
39 | * pthread_mutex_trylock()
40 | * pthread_mutex_unlock()
41 | */
42 |
43 | #include "test.h"
44 |
45 | pthread_mutex_t mutex1 = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
46 |
47 | static int washere = 0;
48 |
49 | void * func(void * arg)
50 | {
51 | assert(pthread_mutex_trylock(&mutex1) == EBUSY);
52 |
53 | washere = 1;
54 |
55 | return 0;
56 | }
57 |
58 | int
59 | main()
60 | {
61 | pthread_t t;
62 |
63 | assert(pthread_mutex_lock(&mutex1) == 0);
64 |
65 | assert(pthread_create(&t, NULL, func, NULL) == 0);
66 | assert(pthread_join(t, NULL) == 0);
67 |
68 | assert(pthread_mutex_unlock(&mutex1) == 0);
69 |
70 | assert(washere == 1);
71 |
72 | return 0;
73 | }
74 |
--------------------------------------------------------------------------------
/tests/mutex5.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex5.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Confirm the equality/inequality of the various mutex types,
35 | * and the default not-set value.
36 | */
37 |
38 | #include "test.h"
39 |
40 | static pthread_mutexattr_t mxAttr;
41 |
42 | /* Prevent optimiser from removing dead or obvious asserts. */
43 | int _optimiseFoil;
44 | #define FOIL(x) (_optimiseFoil = x)
45 |
46 | int
47 | main()
48 | {
49 | int mxType = -1;
50 |
51 | assert(FOIL(PTHREAD_MUTEX_DEFAULT) == PTHREAD_MUTEX_NORMAL);
52 | assert(FOIL(PTHREAD_MUTEX_DEFAULT) != PTHREAD_MUTEX_ERRORCHECK);
53 | assert(FOIL(PTHREAD_MUTEX_DEFAULT) != PTHREAD_MUTEX_RECURSIVE);
54 | assert(FOIL(PTHREAD_MUTEX_RECURSIVE) != PTHREAD_MUTEX_ERRORCHECK);
55 |
56 | assert(FOIL(PTHREAD_MUTEX_NORMAL) == PTHREAD_MUTEX_FAST_NP);
57 | assert(FOIL(PTHREAD_MUTEX_RECURSIVE) == PTHREAD_MUTEX_RECURSIVE_NP);
58 | assert(FOIL(PTHREAD_MUTEX_ERRORCHECK) == PTHREAD_MUTEX_ERRORCHECK_NP);
59 |
60 | assert(pthread_mutexattr_init(&mxAttr) == 0);
61 | assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
62 | assert(mxType == PTHREAD_MUTEX_NORMAL);
63 |
64 | return 0;
65 | }
66 |
--------------------------------------------------------------------------------
/tests/mutex7.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex7.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Test the default (type not set) mutex type.
35 | * Should be the same as PTHREAD_MUTEX_NORMAL.
36 | * Thread locks then trylocks mutex (attempted recursive lock).
37 | * The thread should lock first time and EBUSY second time.
38 | *
39 | * Depends on API functions:
40 | * pthread_mutex_lock()
41 | * pthread_mutex_trylock()
42 | * pthread_mutex_unlock()
43 | */
44 |
45 | #include "test.h"
46 |
47 | static int lockCount = 0;
48 |
49 | static pthread_mutex_t mutex;
50 |
51 | void * locker(void * arg)
52 | {
53 | assert(pthread_mutex_lock(&mutex) == 0);
54 | lockCount++;
55 | assert(pthread_mutex_trylock(&mutex) == EBUSY);
56 | lockCount++;
57 | assert(pthread_mutex_unlock(&mutex) == 0);
58 | assert(pthread_mutex_unlock(&mutex) == 0);
59 |
60 | return 0;
61 | }
62 |
63 | int
64 | main()
65 | {
66 | pthread_t t;
67 |
68 | assert(pthread_mutex_init(&mutex, NULL) == 0);
69 |
70 | assert(pthread_create(&t, NULL, locker, NULL) == 0);
71 |
72 | while (lockCount < 2)
73 | {
74 | Sleep(1);
75 | }
76 |
77 | assert(lockCount == 2);
78 |
79 | return 0;
80 | }
81 |
--------------------------------------------------------------------------------
/tests/mutex8.c:
--------------------------------------------------------------------------------
1 | /*
2 | * mutex8.c
3 | *
4 | *
5 | * Pthreads4w - POSIX Threads for Windows
6 | * Copyright 1998 John E. Bossom
7 | * Copyright 1999-2018, Pthreads4w contributors
8 | *
9 | * Homepage: https://sourceforge.net/projects/pthreads4w/
10 | *
11 | * The current list of contributors is contained
12 | * in the file CONTRIBUTORS included with the source
13 | * code distribution. The list can also be seen at the
14 | * following World Wide Web location:
15 | *
16 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
17 | *
18 | * Licensed under the Apache License, Version 2.0 (the "License");
19 | * you may not use this file except in compliance with the License.
20 | * You may obtain a copy of the License at
21 | *
22 | * http://www.apache.org/licenses/LICENSE-2.0
23 | *
24 | * Unless required by applicable law or agreed to in writing, software
25 | * distributed under the License is distributed on an "AS IS" BASIS,
26 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 | * See the License for the specific language governing permissions and
28 | * limitations under the License.
29 | *
30 | * --------------------------------------------------------------------------
31 | *
32 | * Test the default (type not set) mutex type exercising timedlock.
33 | * Thread locks mutex, another thread timedlocks the mutex.
34 | * Timed thread should timeout.
35 | *
36 | * Depends on API functions:
37 | * pthread_mutex_lock()
38 | * pthread_mutex_timedlock()
39 | * pthread_mutex_unlock()
40 | */
41 |
42 | #include "test.h"
43 |
44 | static int lockCount = 0;
45 |
46 | static pthread_mutex_t mutex;
47 |
48 | void * locker(void * arg)
49 | {
50 | struct timespec abstime, reltime = { 1, 0 };
51 |
52 | (void) pthread_win32_getabstime_np(&abstime, &reltime);
53 |
54 | assert(pthread_mutex_timedlock(&mutex, &abstime) == ETIMEDOUT);
55 |
56 | lockCount++;
57 |
58 | return 0;
59 | }
60 |
61 | int
62 | main()
63 | {
64 | pthread_t t;
65 |
66 | assert(pthread_mutex_init(&mutex, NULL) == 0);
67 |
68 | assert(pthread_mutex_lock(&mutex) == 0);
69 |
70 | assert(pthread_create(&t, NULL, locker, NULL) == 0);
71 |
72 | while (lockCount < 1)
73 | {
74 | Sleep(1);
75 | }
76 |
77 | assert(lockCount == 1);
78 |
79 | assert(pthread_mutex_unlock(&mutex) == 0);
80 |
81 | return 0;
82 | }
83 |
--------------------------------------------------------------------------------
/tests/once1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * once1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Create a static pthread_once and test that it calls myfunc once.
35 | *
36 | * Depends on API functions:
37 | * pthread_once()
38 | * pthread_create()
39 | */
40 |
41 | #include "test.h"
42 |
43 | pthread_once_t once = PTHREAD_ONCE_INIT;
44 |
45 | static int washere = 0;
46 |
47 | void
48 | myfunc(void)
49 | {
50 | washere++;
51 | }
52 |
53 | void *
54 | mythread(void * arg)
55 | {
56 | assert(pthread_once(&once, myfunc) == 0);
57 |
58 | return 0;
59 | }
60 |
61 | int
62 | main()
63 | {
64 | pthread_t t1, t2;
65 |
66 | assert(pthread_create(&t1, NULL, mythread, NULL) == 0);
67 |
68 | assert(pthread_create(&t2, NULL, mythread, NULL) == 0);
69 |
70 | Sleep(2000);
71 |
72 | assert(washere == 1);
73 |
74 | return 0;
75 | }
76 |
--------------------------------------------------------------------------------
/tests/rwlock1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rwlock1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Create a simple rwlock object and then destroy it.
35 | *
36 | * Depends on API functions:
37 | * pthread_rwlock_init()
38 | * pthread_rwlock_destroy()
39 | */
40 |
41 | #include "test.h"
42 |
43 | pthread_rwlock_t rwlock = NULL;
44 |
45 | int
46 | main()
47 | {
48 | assert(rwlock == NULL);
49 |
50 | assert(pthread_rwlock_init(&rwlock, NULL) == 0);
51 |
52 | assert(rwlock != NULL);
53 |
54 | assert(pthread_rwlock_destroy(&rwlock) == 0);
55 |
56 | assert(rwlock == NULL);
57 |
58 | return 0;
59 | }
60 |
--------------------------------------------------------------------------------
/tests/rwlock2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rwlock2.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static rwlock object, lock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_rwlock_rdlock()
39 | * pthread_rwlock_unlock()
40 | */
41 |
42 | #include "test.h"
43 |
44 | pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
45 |
46 | int
47 | main()
48 | {
49 | assert(rwlock == PTHREAD_RWLOCK_INITIALIZER);
50 |
51 | assert(pthread_rwlock_rdlock(&rwlock) == 0);
52 |
53 | assert(rwlock != PTHREAD_RWLOCK_INITIALIZER);
54 |
55 | assert(rwlock != NULL);
56 |
57 | assert(pthread_rwlock_unlock(&rwlock) == 0);
58 |
59 | assert(pthread_rwlock_destroy(&rwlock) == 0);
60 |
61 | assert(rwlock == NULL);
62 |
63 | return 0;
64 | }
65 |
--------------------------------------------------------------------------------
/tests/rwlock2_t.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rwlock2_t.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static rwlock object, timed-lock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_rwlock_timedrdlock()
39 | * pthread_rwlock_unlock()
40 | */
41 |
42 | #include "test.h"
43 | #include
44 |
45 | pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
46 |
47 | int
48 | main()
49 | {
50 | struct timespec abstime, reltime = { 1, 0 };
51 |
52 | (void) pthread_win32_getabstime_np(&abstime, &reltime);
53 |
54 | assert(rwlock == PTHREAD_RWLOCK_INITIALIZER);
55 |
56 | assert(pthread_rwlock_timedrdlock(&rwlock, &abstime) == 0);
57 |
58 | assert(rwlock != PTHREAD_RWLOCK_INITIALIZER);
59 |
60 | assert(rwlock != NULL);
61 |
62 | assert(pthread_rwlock_unlock(&rwlock) == 0);
63 |
64 | assert(pthread_rwlock_destroy(&rwlock) == 0);
65 |
66 | assert(rwlock == NULL);
67 |
68 | return 0;
69 | }
70 |
--------------------------------------------------------------------------------
/tests/rwlock3.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rwlock3.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static rwlock object, wrlock it, trywrlock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_create()
39 | * pthread_join()
40 | * pthread_rwlock_wrlock()
41 | * pthread_rwlock_trywrlock()
42 | * pthread_rwlock_unlock()
43 | */
44 |
45 | #include "test.h"
46 |
47 | pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
48 |
49 | static int washere = 0;
50 |
51 | void * func(void * arg)
52 | {
53 | assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);
54 |
55 | washere = 1;
56 |
57 | return 0;
58 | }
59 |
60 | int
61 | main()
62 | {
63 | pthread_t t;
64 |
65 | assert(pthread_rwlock_wrlock(&rwlock1) == 0);
66 |
67 | assert(pthread_create(&t, NULL, func, NULL) == 0);
68 |
69 | assert(pthread_join(t, NULL) == 0);
70 |
71 | assert(pthread_rwlock_unlock(&rwlock1) == 0);
72 |
73 | assert(washere == 1);
74 |
75 | return 0;
76 | }
77 |
--------------------------------------------------------------------------------
/tests/rwlock3_t.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rwlock3_t.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static rwlock object, timed-wrlock it, trywrlock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_rwlock_timedwrlock()
39 | * pthread_rwlock_trywrlock()
40 | * pthread_rwlock_unlock()
41 | */
42 |
43 | #include "test.h"
44 | #include
45 |
46 | pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
47 |
48 | static int washere = 0;
49 |
50 | void * func(void * arg)
51 | {
52 | assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);
53 |
54 | washere = 1;
55 |
56 | return 0;
57 | }
58 |
59 | int
60 | main()
61 | {
62 | pthread_t t;
63 | struct timespec abstime, reltime = { 1, 0 };
64 |
65 | (void) pthread_win32_getabstime_np(&abstime, &reltime);
66 |
67 | assert(pthread_rwlock_timedwrlock(&rwlock1, &abstime) == 0);
68 |
69 | assert(pthread_create(&t, NULL, func, NULL) == 0);
70 |
71 | Sleep(2000);
72 |
73 | assert(pthread_rwlock_unlock(&rwlock1) == 0);
74 |
75 | assert(washere == 1);
76 |
77 | return 0;
78 | }
79 |
--------------------------------------------------------------------------------
/tests/rwlock4.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rwlock4.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static rwlock object, rdlock it, trywrlock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_create()
39 | * pthread_join()
40 | * pthread_rwlock_rdlock()
41 | * pthread_rwlock_trywrlock()
42 | * pthread_rwlock_unlock()
43 | */
44 |
45 | #include "test.h"
46 |
47 | pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
48 |
49 | static int washere = 0;
50 |
51 | void * func(void * arg)
52 | {
53 | assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);
54 |
55 | washere = 1;
56 |
57 | return 0;
58 | }
59 |
60 | int
61 | main()
62 | {
63 | pthread_t t;
64 |
65 | assert(pthread_rwlock_rdlock(&rwlock1) == 0);
66 |
67 | assert(pthread_create(&t, NULL, func, NULL) == 0);
68 |
69 | assert(pthread_join(t, NULL) == 0);
70 |
71 | assert(pthread_rwlock_unlock(&rwlock1) == 0);
72 |
73 | assert(washere == 1);
74 |
75 | return 0;
76 | }
77 |
--------------------------------------------------------------------------------
/tests/rwlock4_t.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rwlock4_t.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static rwlock object, timed-rdlock it, trywrlock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_rwlock_timedrdlock()
39 | * pthread_rwlock_trywrlock()
40 | * pthread_rwlock_unlock()
41 | */
42 |
43 | #include "test.h"
44 | #include
45 |
46 | pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
47 |
48 | static int washere = 0;
49 |
50 | void * func(void * arg)
51 | {
52 | assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY);
53 |
54 | washere = 1;
55 |
56 | return 0;
57 | }
58 |
59 | int
60 | main()
61 | {
62 | pthread_t t;
63 | struct timespec abstime = { 0, 0 };
64 | struct timespec reltime = { 1, 0 };
65 |
66 | assert(pthread_rwlock_timedrdlock(&rwlock1, pthread_win32_getabstime_np(&abstime, &reltime)) == 0);
67 |
68 | assert(pthread_create(&t, NULL, func, NULL) == 0);
69 |
70 | Sleep(2000);
71 |
72 | assert(pthread_rwlock_unlock(&rwlock1) == 0);
73 |
74 | assert(washere == 1);
75 |
76 | return 0;
77 | }
78 |
--------------------------------------------------------------------------------
/tests/rwlock5.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rwlock5.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static rwlock object, rdlock it, tryrdlock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_create()
39 | * pthread_join()
40 | * pthread_rwlock_rdlock()
41 | * pthread_rwlock_tryrdlock()
42 | * pthread_rwlock_unlock()
43 | */
44 |
45 | #include "test.h"
46 |
47 | pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
48 |
49 | static int washere = 0;
50 |
51 | void * func(void * arg)
52 | {
53 | assert(pthread_rwlock_tryrdlock(&rwlock1) == 0);
54 |
55 | assert(pthread_rwlock_unlock(&rwlock1) == 0);
56 |
57 | washere = 1;
58 |
59 | return 0;
60 | }
61 |
62 | int
63 | main()
64 | {
65 | pthread_t t;
66 |
67 | assert(pthread_rwlock_rdlock(&rwlock1) == 0);
68 |
69 | assert(pthread_create(&t, NULL, func, NULL) == 0);
70 |
71 | assert(pthread_join(t, NULL) == 0);
72 |
73 | assert(pthread_rwlock_unlock(&rwlock1) == 0);
74 |
75 | assert(washere == 1);
76 |
77 | return 0;
78 | }
79 |
--------------------------------------------------------------------------------
/tests/rwlock5_t.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rwlock5_t.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a static rwlock object, timed-rdlock it, tryrdlock it,
35 | * and then unlock it again.
36 | *
37 | * Depends on API functions:
38 | * pthread_rwlock_timedrdlock()
39 | * pthread_rwlock_tryrdlock()
40 | * pthread_rwlock_unlock()
41 | */
42 |
43 | #include "test.h"
44 | #include
45 |
46 | pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER;
47 |
48 | static int washere = 0;
49 |
50 | void * func(void * arg)
51 | {
52 | assert(pthread_rwlock_tryrdlock(&rwlock1) == 0);
53 |
54 | assert(pthread_rwlock_unlock(&rwlock1) == 0);
55 |
56 | washere = 1;
57 |
58 | return 0;
59 | }
60 |
61 | int
62 | main()
63 | {
64 | pthread_t t;
65 | struct timespec abstime, reltime = { 1, 0 };
66 |
67 | (void) pthread_win32_getabstime_np(&abstime, &reltime);
68 |
69 | assert(pthread_rwlock_timedrdlock(&rwlock1, &abstime) == 0);
70 |
71 | assert(pthread_create(&t, NULL, func, NULL) == 0);
72 |
73 | Sleep(2000);
74 |
75 | assert(pthread_rwlock_unlock(&rwlock1) == 0);
76 |
77 | assert(washere == 1);
78 |
79 | return 0;
80 | }
81 |
--------------------------------------------------------------------------------
/tests/self1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * self1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Test for pthread_self().
35 | *
36 | * Depends on API functions:
37 | * pthread_self()
38 | *
39 | * Implicitly depends on:
40 | * pthread_getspecific()
41 | * pthread_setspecific()
42 | */
43 |
44 | #include "test.h"
45 |
46 | int
47 | main(int argc, char * argv[])
48 | {
49 | /*
50 | * This should always succeed unless the system has no
51 | * resources (memory) left.
52 | */
53 | pthread_t self;
54 |
55 | #if defined (__PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__))
56 | pthread_win32_process_attach_np();
57 | #endif
58 |
59 | self = pthread_self();
60 |
61 | assert(self.p != NULL);
62 |
63 | #if defined (__PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__))
64 | pthread_win32_process_detach_np();
65 | #endif
66 | return 0;
67 | }
68 |
--------------------------------------------------------------------------------
/tests/self2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * self2.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Test for pthread_self().
35 | *
36 | * Depends on API functions:
37 | * pthread_create()
38 | * pthread_self()
39 | *
40 | * Implicitly depends on:
41 | * pthread_getspecific()
42 | * pthread_setspecific()
43 | */
44 |
45 | #include "test.h"
46 | #include
47 |
48 | static pthread_t me;
49 |
50 | void *
51 | entry(void * arg)
52 | {
53 | me = pthread_self();
54 |
55 | return arg;
56 | }
57 |
58 | int
59 | main()
60 | {
61 | pthread_t t;
62 |
63 | assert(pthread_create(&t, NULL, entry, NULL) == 0);
64 |
65 | Sleep(100);
66 |
67 | assert(pthread_equal(t, me) != 0);
68 |
69 | /* Success. */
70 | return 0;
71 | }
72 |
--------------------------------------------------------------------------------
/tests/sizes.c:
--------------------------------------------------------------------------------
1 | #define _WIN32_WINNT 0x400
2 |
3 | #include "test.h"
4 | /* Cheating here - sneaking a peek at library internals */
5 | #include "../config.h"
6 | #include "../implement.h"
7 |
8 | int
9 | main()
10 | {
11 | printf("Sizes of pthreads-win32 structs\n");
12 | printf("-------------------------------\n");
13 | printf("%30s %4d\n", "pthread_t", (int)sizeof(pthread_t));
14 | printf("%30s %4d\n", "__ptw32_thread_t", (int)sizeof(__ptw32_thread_t));
15 | printf("%30s %4d\n", "pthread_attr_t_", (int)sizeof(struct pthread_attr_t_));
16 | printf("%30s %4d\n", "sem_t_", (int)sizeof(struct sem_t_));
17 | printf("%30s %4d\n", "pthread_mutex_t_", (int)sizeof(struct pthread_mutex_t_));
18 | printf("%30s %4d\n", "pthread_mutexattr_t_", (int)sizeof(struct pthread_mutexattr_t_));
19 | printf("%30s %4d\n", "pthread_spinlock_t_", (int)sizeof(struct pthread_spinlock_t_));
20 | printf("%30s %4d\n", "pthread_barrier_t_", (int)sizeof(struct pthread_barrier_t_));
21 | printf("%30s %4d\n", "pthread_barrierattr_t_", (int)sizeof(struct pthread_barrierattr_t_));
22 | printf("%30s %4d\n", "pthread_key_t_", (int)sizeof(struct pthread_key_t_));
23 | printf("%30s %4d\n", "pthread_cond_t_", (int)sizeof(struct pthread_cond_t_));
24 | printf("%30s %4d\n", "pthread_condattr_t_", (int)sizeof(struct pthread_condattr_t_));
25 | printf("%30s %4d\n", "pthread_rwlock_t_", (int)sizeof(struct pthread_rwlock_t_));
26 | printf("%30s %4d\n", "pthread_rwlockattr_t_", (int)sizeof(struct pthread_rwlockattr_t_));
27 | printf("%30s %4d\n", "pthread_once_t_", (int)sizeof(struct pthread_once_t_));
28 | printf("%30s %4d\n", "__ptw32_cleanup_t", (int)sizeof(struct __ptw32_cleanup_t));
29 | printf("%30s %4d\n", "__ptw32_mcs_node_t_", (int)sizeof(struct __ptw32_mcs_node_t_));
30 | printf("%30s %4d\n", "sched_param", (int)sizeof(struct sched_param));
31 | printf("-------------------------------\n");
32 |
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/tests/spin1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * spin1.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Create a simple spinlock object, lock it, and then unlock it again.
35 | * This is the simplest test of the pthread mutex family that we can do.
36 | *
37 | */
38 |
39 | #include "test.h"
40 |
41 | pthread_spinlock_t lock;
42 |
43 | int
44 | main()
45 | {
46 | assert(pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE) == 0);
47 |
48 | assert(pthread_spin_lock(&lock) == 0);
49 |
50 | assert(pthread_spin_unlock(&lock) == 0);
51 |
52 | assert(pthread_spin_destroy(&lock) == 0);
53 |
54 | assert(pthread_spin_lock(&lock) == EINVAL);
55 |
56 | return 0;
57 | }
58 |
--------------------------------------------------------------------------------
/tests/spin2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * spin2.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Declare a spinlock object, lock it, trylock it,
35 | * and then unlock it again.
36 | *
37 | */
38 |
39 | #include "test.h"
40 |
41 | pthread_spinlock_t lock = NULL;
42 |
43 | static int washere = 0;
44 |
45 | void * func(void * arg)
46 | {
47 | assert(pthread_spin_trylock(&lock) == EBUSY);
48 |
49 | washere = 1;
50 |
51 | return 0;
52 | }
53 |
54 | int
55 | main()
56 | {
57 | pthread_t t;
58 |
59 | assert(pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE) == 0);
60 |
61 | assert(pthread_spin_lock(&lock) == 0);
62 |
63 | assert(pthread_create(&t, NULL, func, NULL) == 0);
64 | assert(pthread_join(t, NULL) == 0);
65 |
66 | assert(pthread_spin_unlock(&lock) == 0);
67 |
68 | assert(pthread_spin_destroy(&lock) == 0);
69 |
70 | assert(washere == 1);
71 |
72 | return 0;
73 | }
74 |
--------------------------------------------------------------------------------
/tests/spin3.c:
--------------------------------------------------------------------------------
1 | /*
2 | * spin3.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Thread A locks spin - thread B tries to unlock.
35 | * This should succeed, but it's undefined behaviour.
36 | *
37 | */
38 |
39 | #include "test.h"
40 |
41 | static int wasHere = 0;
42 |
43 | static pthread_spinlock_t spin;
44 |
45 | void * unlocker(void * arg)
46 | {
47 | int expectedResult = (int)(size_t)arg;
48 |
49 | wasHere++;
50 | assert(pthread_spin_unlock(&spin) == expectedResult);
51 | wasHere++;
52 | return NULL;
53 | }
54 |
55 | int
56 | main()
57 | {
58 | pthread_t t;
59 |
60 | wasHere = 0;
61 | assert(pthread_spin_init(&spin, PTHREAD_PROCESS_PRIVATE) == 0);
62 | assert(pthread_spin_lock(&spin) == 0);
63 | assert(pthread_create(&t, NULL, unlocker, (void*)0) == 0);
64 | assert(pthread_join(t, NULL) == 0);
65 | /*
66 | * Our spinlocks don't record the owner thread so any thread can unlock the spinlock,
67 | * but nor is it an error for any thread to unlock a spinlock that is not locked.
68 | */
69 | assert(pthread_spin_unlock(&spin) == 0);
70 | assert(pthread_spin_destroy(&spin) == 0);
71 | assert(wasHere == 2);
72 |
73 | return 0;
74 | }
75 |
--------------------------------------------------------------------------------
/tests/valid2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * File: valid2.c
3 | *
4 | *
5 | * --------------------------------------------------------------------------
6 | *
7 | * Pthreads4w - POSIX Threads for Windows
8 | * Copyright 1998 John E. Bossom
9 | * Copyright 1999-2018, Pthreads4w contributors
10 | *
11 | * Homepage: https://sourceforge.net/projects/pthreads4w/
12 | *
13 | * The current list of contributors is contained
14 | * in the file CONTRIBUTORS included with the source
15 | * code distribution. The list can also be seen at the
16 | * following World Wide Web location:
17 | *
18 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/
19 | *
20 | * Licensed under the Apache License, Version 2.0 (the "License");
21 | * you may not use this file except in compliance with the License.
22 | * You may obtain a copy of the License at
23 | *
24 | * http://www.apache.org/licenses/LICENSE-2.0
25 | *
26 | * Unless required by applicable law or agreed to in writing, software
27 | * distributed under the License is distributed on an "AS IS" BASIS,
28 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 | * See the License for the specific language governing permissions and
30 | * limitations under the License.
31 | *
32 | * --------------------------------------------------------------------------
33 | *
34 | * Test Synopsis:
35 | * - Confirm that thread validation fails for garbage thread ID.
36 | *
37 | * Test Method (Validation or Falsification):
38 | * -
39 | *
40 | * Requirements Tested:
41 | * -
42 | *
43 | * Features Tested:
44 | * -
45 | *
46 | * Cases Tested:
47 | * -
48 | *
49 | * Description:
50 | * -
51 | *
52 | * Environment:
53 | * -
54 | *
55 | * Input:
56 | * - None.
57 | *
58 | * Output:
59 | * - File name, Line number, and failed expression on failure.
60 | * - No output on success.
61 | *
62 | * Assumptions:
63 | * -
64 | *
65 | * Pass Criteria:
66 | * - Process returns zero exit status.
67 | *
68 | * Fail Criteria:
69 | * - Process returns non-zero exit status.
70 | */
71 |
72 | #include "test.h"
73 |
74 | int
75 | main()
76 | {
77 | pthread_t NullThread = __PTW32_THREAD_NULL_ID;
78 |
79 | assert(pthread_kill(NullThread, 0) == ESRCH);
80 |
81 | return 0;
82 | }
83 |
--------------------------------------------------------------------------------