module TclCompatibility (
         primPutEnv
       , primTclDebug
       , primInitTcl
       , primRunTcl
       , primRunNonBlockingTcl
       , primRunOnceTcl
       , primExecuteTcl
       , primExecuteTcl_
       , primGetEvent
       , primSetVar
       , primCheckAnyWindowsTcl
       )
where

import TclPrim hiding (primRunTcl)
import qualified TclPrim as T
import Concurrent

{-
primRunTcl :: IO Bool
primRunTcl = do
  any <- primRunNonBlockingTcl
  if any then do
    primCheckAnyWindowsTcl
   else do
    threadDelay 1000000
    primRunTcl
  -}  


primRunTcl :: IO Bool
primRunTcl = do
  p <- isOnlyProcess
  if p then
     T.primRunTcl
   else do
     any <- primRunNonBlockingTcl
     if any then primCheckAnyWindowsTcl
      else do yield;primRunTcl
     
isOnlyProcess :: IO Bool
isOnlyProcess = return True -- fmap toBool $ _casm_ ``%r = run_queue_hd == END_TSO_QUEUE;''
 where
  toBool :: Int -> Bool
  toBool 0 = False
  toBool _ = True

