Thank you for asking. I can understand the distress you are through. It appears likely that you are having a problem of excessive masturbation. It is important to understand that masturbation per se is not harmful, but if the habit becomes difficult to control and if it takes priority over other important things of life, if not masturbating causes irritability, difficulty in concentration, etc it is a problem. Masturbation can be addictive like any other addiction and therfore needs to be treated by an expert. The management would consist of managing the withdrawal symptoms and rehabilitation. There cannot be a specific medication or instructions, but a comprehensive management plan that is tailored made suiting to individual. Most importantly, it is treatable.
Next Steps
I would strongly recommend you to meet with a psychiatrist.
Health Tips
Don't worry. It is completely treatable.