WSJT-X/thnix.f90
Joe Taylor 174936fe37 Starting to insert mutex lockouts around Fortran I/O
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/map65@1298 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
2009-07-26 15:12:41 +00:00

55 lines
1.2 KiB
Fortran

subroutine cs_init
character*12 csub0
common/mtxcom/ltrace,mtx,mtxstate,csub0
ltrace=0
mtxstate=0
csub0='**unlocked**'
call fthread_mutex_init(mtx)
return
end subroutine cs_init
subroutine cs_destroy
character*12 csub0
common/mtxcom/ltrace,mtx,mtxstate,csub0
call fthread_mutex_destroy(mtx)
return
end subroutine cs_destroy
subroutine th_create(sub)
call fthread_create(sub,id)
return
end subroutine th_create
subroutine th_exit
call fthread_exit
return
end subroutine th_exit
subroutine cs_lock(csub)
character*(*) csub
character*12 csub0
integer fthread_mutex_lock,fthread_mutex_trylock
common/mtxcom/ltrace,mtx,mtxstate,csub0
n=fthread_mutex_trylock(mtx)
if(n.ne.0) then
! Another thread has already locked the mutex
n=fthread_mutex_lock(mtx)
iz=index(csub0,' ')
if(ltrace.ge.1) print*,'"',csub,'" requested mutex when "', &
csub0(:iz-1),'" owned it.'
endif
mtxstate=1
csub0=csub
if(ltrace.ge.3) print*,'Mutex locked by ',csub
return
end subroutine cs_lock
subroutine cs_unlock
character*12 csub0
common/mtxcom/ltrace,mtx,mtxstate,csub0
if(ltrace.ge.3) print*,'Mutex unlocked,',ltrace,mtx,mtxstate,csub0
mtxstate=0
call fthread_mutex_unlock(mtx)
return
end subroutine cs_unlock