@@ -90,26 +90,26 @@ static inline void rendezvous_meet(rendezvous_handle hRv)
9090 DASSERT (hRv ,return );
9191
9292
93-
93+
9494 pthread_mutex_lock (& hRv -> mutex );
95-
95+
9696 if (!hRv -> force ) {
97-
97+
9898 if (hRv -> count > 0 ) {
9999 hRv -> count -- ;
100100 }
101-
101+
102102 if (hRv -> count > 0 ) {
103103 pthread_cond_wait (& hRv -> cond , & hRv -> mutex );
104- }
104+ }
105105 else {
106106 pthread_cond_broadcast (& hRv -> cond );
107107 hRv -> count = hRv -> orig ;
108108 }
109-
109+
110110 }
111111 pthread_mutex_unlock (& hRv -> mutex );
112-
112+
113113}
114114
115115/******************************************************************************
@@ -289,7 +289,7 @@ fifo_flush(fifo_handle hfifo)
289289 pthread_mutex_unlock (& hfifo -> mutex );
290290
291291 /*
292- * Make sure any fifo_get() calls are unblocked
292+ * Make sure any fifo_get() calls are unblocked
293293 */
294294 if (write (hfifo -> pipes [1 ], & ch , 1 ) != 1 ) {
295295 return FAILURE ;
@@ -363,7 +363,7 @@ typedef struct thread_job {
363363} thread_job ;
364364
365365typedef thread_job * thread_handle ;
366-
366+
367367typedef struct threadpool {
368368 thread_job * threads [MAX_NUMTHREAD ];
369369 shared_interface * sharedp ;
@@ -426,28 +426,27 @@ static inline int _fifo_connect(fifo_handle *lhs, fifo_handle *rhs);
426426
427427static inline void threadpool_delete (threadpool_handle h )
428428{
429- int i ;
430- if (h ){
431- if (h -> sharedp ){
432- if (h -> sharedp -> rv_init ){
433- rendezvous_delete (h -> sharedp -> rv_init );
434- }
435- if (h -> sharedp -> rv_cleanup ){
436- rendezvous_delete (h -> sharedp -> rv_cleanup );
437- }
438-
439- gbl_delete (h -> sharedp -> gbl );
429+ if (!h ) return ;
440430
441- FREE (h -> sharedp );
431+ if (h -> sharedp ){
432+ if (h -> sharedp -> rv_init ){
433+ rendezvous_delete (h -> sharedp -> rv_init );
442434 }
443-
444- for (i = 0 ;i < h -> cnt ;i ++ ){
445- thread_delete (h -> threads [i ]);
435+ if (h -> sharedp -> rv_cleanup ){
436+ rendezvous_delete (h -> sharedp -> rv_cleanup );
446437 }
447438
439+ gbl_delete (h -> sharedp -> gbl );
448440
449- FREE (h );
441+ FREE (h -> sharedp );
450442 }
443+
444+ for (int i = 0 ;i < h -> cnt ;i ++ ){
445+ thread_delete (h -> threads [i ]);
446+ }
447+
448+
449+ FREE (h );
451450}
452451
453452static inline threadpool_handle threadpool_create (void * argsp )
@@ -486,7 +485,7 @@ static inline int threadpool_add(threadpool_handle h,thread_handle threadp)
486485
487486 for (i = 0 ;i < h -> cnt ;i ++ ){
488487 DASSERT (h -> threads [i ] != threadp ,return FAILURE );
489-
488+
490489 }
491490
492491 memcpy (tmp ,threadp -> name ,MAX_THREADNAME );
@@ -553,7 +552,7 @@ static inline thread_handle create_base_thread(threadpool_handle h_pool, const c
553552 nh -> param_priv = params ;
554553
555554 strncpy (nh -> name , name ,MAX_THREADNAME );
556-
555+
557556 ASSERT (threadpool_add (h_pool ,nh ) == SUCCESS ,goto error );
558557
559558 return nh ;
@@ -647,27 +646,27 @@ static inline void thread_sync_cleanup(thread_handle h)
647646 if (h -> hOutPut != NULL ) fifo_flush (h -> hOutPut );
648647 if (h -> hInPut != NULL ) fifo_flush (h -> hInPut );
649648
650-
649+
651650 /* Make sure the other threads aren't waiting for us */
652651 rendezvous_force (sharedp -> rv_init );
653-
652+
654653 /* Meet up with other threads before cleaning up */
655654 rendezvous_meet (sharedp -> rv_cleanup );
656-
655+
657656 DBG ("%s thread died\n" ,h -> name );
658657}
659658
660659static inline void thread_delete (thread_handle h )
661660{
662- if (h ){
663- if (h -> started ){
664- ERR ("BUG: deleting uninitialized thread %s\n" ,h -> name );
665- }
661+ if (!h ) return ;
666662
667- FREE (h -> param_priv );
668-
669- FREE (h );
663+ if (h -> started ){
664+ ERR ("BUG: deleting uninitialized thread %s\n" ,h -> name );
670665 }
666+
667+ FREE (h -> param_priv );
668+
669+ FREE (h );
671670}
672671
673672static inline int _fifo_connect (fifo_handle * lhs , fifo_handle * rhs )
@@ -689,7 +688,7 @@ static inline int _fifo_connect(fifo_handle *lhs, fifo_handle *rhs)
689688}
690689
691690
692- static inline int thread_joint (thread_handle lhs , thread_handle rhs )
691+ static inline int thread_joint (thread_handle lhs , thread_handle rhs )
693692{
694693 ASSERT (lhs ,return FAILURE );
695694 ASSERT (rhs ,return FAILURE );
@@ -700,7 +699,7 @@ static inline int thread_joint(thread_handle lhs, thread_handle rhs)
700699 return SUCCESS ;
701700}
702701
703- static inline int thread_chain (thread_handle lhs , thread_handle rhs )
702+ static inline int thread_chain (thread_handle lhs , thread_handle rhs )
704703{
705704 ASSERT (lhs ,return FAILURE );
706705 ASSERT (rhs ,return FAILURE );
@@ -710,7 +709,7 @@ static inline int thread_chain(thread_handle lhs, thread_handle rhs)
710709 return SUCCESS ;
711710}
712711
713- static inline int thread_extend (thread_handle lhs , thread_handle rhs )
712+ static inline int thread_extend (thread_handle lhs , thread_handle rhs )
714713{
715714 ASSERT (lhs ,return FAILURE );
716715 ASSERT (rhs ,return FAILURE );
@@ -720,7 +719,7 @@ static inline int thread_extend(thread_handle lhs, thread_handle rhs)
720719 return SUCCESS ;
721720}
722721
723- static inline int thread_close (thread_handle lhs , thread_handle rhs )
722+ static inline int thread_close (thread_handle lhs , thread_handle rhs )
724723{
725724 ASSERT (lhs ,return FAILURE );
726725 ASSERT (rhs ,return FAILURE );
@@ -743,4 +742,4 @@ static inline int thread_close(thread_handle lhs, thread_handle rhs)
743742#define getpwnam __NEVER_EVER_USE_THREAD_UNSAFE_FUNCTION_IN_MULTI_THREADED_PROGRAM_YOU_SUCKER__
744743
745744
746- #endif /* _IPC_H */
745+ #endif /* _IPC_H */
0 commit comments