No surgery, no, no, no. Almost all have too high of a failure rate. I have not heard of one person that any tmj surgery helped.
But don't panic. You are apparently grinding and/or clenching while sleeping, which is causing one or both tmj discs to go out of joint and that causes the locking. Whatever you do, do not ***pop*** the joint open. Put moist heat on the joints first (at least 5 to 15 minutes) and then gently massage the mouth open.
Your next step is to see a good tmj dentist. You probably will need a bite splint. There are many different kinds and a splint is as good as the splint maker, so be patient and educated. Research all you can before actually seeing the "specialist" you see. You might want to consider an nti splint first since they are the cheaper ones and made specifically for grinders and clenchers. Some love them and others hate them. You have to make your own decision as to how everything seems to be working.
Depending on where you live, if you have health insurance, it might pay for the splint and any x-rays you have taken for tmj even if a dentists does the work. Check into that.
If you do not know of any tmj specialists in your area, check out the following two websites:
i would also suggest contacting the nearest dental teaching university to you for some names in your area.
To help yourself now at home before seeing the tmj specialist, change your diet for a few weeks to only soft foods. Don't open your mouth wide for anything (including the dentist and yawning) and do not chew gum or eat ice. Use lots of moist heat especially just before bedtime or even ice. Look at your posture and the way you hold your head and shoulders. Go to the website - nismat.Org/ptcor/tmj/ - to see what your posture should be and other information. Get a good cervical or tmj support pillow and don't sleep on your stomach.
I hope I have helped. If you have any further questions, please post them here or you can even send me a private message. Take care and work on relaxing yourself, especially before bedtime.