@@ -397,6 +397,10 @@ class CCaptureStream : CSourceStream, IKsPropertySet, IAMStreamConfig, IAMStream
397
397
{
398
398
WorkersRunning = 0 ;
399
399
for (size_t i = 0 ; i != WORKERCOUNT; i++) NewJobSemaphore.Post (); // wake up all threads
400
+ for (size_t i = 0 ; i != WORKERCOUNT; i++)
401
+ {
402
+ Threads[i].Stop ();
403
+ }
400
404
}
401
405
402
406
void StartNewJob (ProcessJob NewJob)
@@ -423,9 +427,80 @@ class CCaptureStream : CSourceStream, IKsPropertySet, IAMStreamConfig, IAMStream
423
427
424
428
private:
425
429
// Wrapper objects for Windows concurrency objects (thread, mutex, semaphore)
426
- struct sThread { typedef DWORD (WINAPI *FUNC_t)(LPVOID); sThread () : h(0 ) {} sThread (FUNC_t f, void * p = NULL ) : h(0 ) { Start (f, p); } void Start (FUNC_t f, void * p = NULL ) { if (h) this ->~sThread (); h = CreateThread (0 ,0 ,f,p,0 ,0 ); } ~sThread () { if (h) { WaitForSingleObject (h, INFINITE); CloseHandle (h); } } private: HANDLE h;sThread (const sThread &);sThread & operator =(const sThread &);};
427
- struct sMutex { sMutex () : h(CreateMutexA(0 ,0 ,0 )) {} ~sMutex () { CloseHandle (h); } __inline void Lock () { WaitForSingleObject (h,INFINITE); } __inline void Unlock () { ReleaseMutex (h); } private: HANDLE h;sMutex (const sMutex &);sMutex & operator =(const sMutex &);};
428
- struct sSemaphore { sSemaphore () : h(CreateSemaphoreA(0 ,0 ,32768 ,0 )) {} ~sSemaphore () { CloseHandle (h); } __inline void Post () { ReleaseSemaphore (h, 1 , 0 ); } __inline bool WaitForPost () { return WaitForSingleObject (h,INFINITE) == WAIT_OBJECT_0; } private: HANDLE h;sSemaphore (const sSemaphore &);sSemaphore & operator =(const sSemaphore &);};
430
+ struct sThread
431
+ {
432
+ typedef DWORD (WINAPI* FUNC_t)(LPVOID);
433
+ sThread () : h(0 )
434
+ {
435
+ }
436
+ sThread (FUNC_t f, void * p = NULL ) : h(0 )
437
+ {
438
+ Start (f, p);
439
+ }
440
+ void Start (FUNC_t f, void * p = NULL )
441
+ {
442
+ if (h)
443
+ this ->~sThread ();
444
+ h = CreateThread (0 , 0 , f, p, 0 , 0 );
445
+ }
446
+ void Stop ()
447
+ {
448
+ if (h)
449
+ {
450
+ WaitForSingleObject (h, INFINITE);
451
+ CloseHandle (h);
452
+ h = 0 ;
453
+ }
454
+ }
455
+ ~sThread ()
456
+ {
457
+ if (h)
458
+ {
459
+ WaitForSingleObject (h, INFINITE);
460
+ CloseHandle (h);
461
+ }
462
+ }
463
+ private:
464
+ HANDLE h;
465
+ sThread (const sThread &);
466
+ sThread & operator =(const sThread &);
467
+ };
468
+
469
+ struct sMutex
470
+ {
471
+ sMutex () : h(CreateMutexA(0 , 0 , 0 )) {}
472
+ ~sMutex () { CloseHandle (h); }
473
+ __inline void Lock ()
474
+ {
475
+ WaitForSingleObject (h, INFINITE);
476
+ }
477
+ __inline void Unlock ()
478
+ {
479
+ ReleaseMutex (h);
480
+ }
481
+ private:
482
+ HANDLE h;
483
+ sMutex (const sMutex &);
484
+ sMutex & operator =(const sMutex &);
485
+ };
486
+
487
+ struct sSemaphore
488
+ {
489
+ sSemaphore () : h(CreateSemaphoreA(0 , 0 , 32768 , 0 )) {}
490
+ ~sSemaphore () { CloseHandle (h); }
491
+ __inline void Post ()
492
+ {
493
+ ReleaseSemaphore (h, 1 , 0 );
494
+ }
495
+ __inline bool WaitForPost ()
496
+ {
497
+ return WaitForSingleObject (h, INFINITE) == WAIT_OBJECT_0;
498
+ }
499
+ private:
500
+ HANDLE h;
501
+ sSemaphore (const sSemaphore &);
502
+ sSemaphore & operator =(const sSemaphore &);
503
+ };
429
504
430
505
enum { WORKERCOUNT = 3 };
431
506
sMutex JobsMutex;
0 commit comments