Depends on how 'smart" you want it to be. It can be done, but you will need something to control logic of what to turn off and when. It's probably not going to be one gate, it's probably going to require 4 gates, two on each route, and entrance and an exit. The gates will have to be set back far enough from the diamond that when a train hits the dead spot on its route it won't foul the diamond. For example if you have 3 diesel on the head end of a train, the first diesel will keep running until the trailing truck is past the gaps, which is one engine length, but there is also the possibility that the other two units that will have enough power to shove the train further until the 2nd unit passes the gaps.
You will need an entrance and an exit, the system should be set up where the other route is off unless both the entrance and exit are clear. That logic also makes it bi-directional.
The fancy circuit would have 8 gates, four entrance gates set out aways from the diamond (the approach gates) and four exit gates near the diamond. The first approach gate to be tripped turns off the conflicting route. Then the circuit doesn't reset until the exit gate for that route trips and then clears. That clears the other route faster.
This system will not necessarily prevent a train from being backed into a train going through the diamond (unless the approach blocks are a full train length long).
Azatrax sells IR detection circuits for model railroad applications (among others).