Code example for Semaphore

Methods: release

0
 
	private class RecordingThread extends Thread
	{ 
		private boolean stopped = true;
		byte[] mRecordBuffer;
		private Semaphore waitStarted = new Semaphore(0);
		private boolean sleep = false;
 
		RecordingThread() 
		{ 
			super(); 
		} 
 
		void init(int bufsize)
		{ 
			if( mRecordBuffer == null || mRecordBuffer.length != bufsize )
				mRecordBuffer = new byte[bufsize];
		} 
 
		public void run() 
		{ 
			while( true ) 
			{ 
				waitStarted.acquireUninterruptibly();
				waitStarted.drainPermits();
				stopped = false;
				sleep = false;
 
				while( !sleep )
				{ 
					int got = mRecorder.read(mRecordBuffer, 0, mRecordBuffer.length);
					if( got != mRecordBuffer.length )
					{ 
						// Audio is stopped here, sleep a bit. 
						try{ 
							Thread.sleep(1000);
						} catch (InterruptedException e) {}
					} 
					else 
					{ 
						//Log.i("SDL", "SDL: nativeAudioRecordCallback with len " + mRecordBuffer.length); 
						nativeAudioRecordCallback(); 
						//Log.i("SDL", "SDL: nativeAudioRecordCallback returned"); 
					} 
				} 
 
				stopped = true;
				mRecorder.stop();
			} 
		} 
 
		public void startRecording() 
		{ 
			mRecorder.startRecording();
			waitStarted.release();
		} 
		public void stopRecording() 
		{ 
			sleep = true;
			while( !stopped )