iperf: add patch from [http://lkml.org/lkml/2007/9/26/132 LKML] to fix locking bugs...
[openwrt/svn-archive/archive.git] / net / iperf / patches / 001-locking_fixes.patch
1 ===================================================================
2 --- iperf-2.0.2.orig/compat/Thread.c
3 +++ iperf-2.0.2/compat/Thread.c
4 @@ -405,9 +405,6 @@ int thread_numuserthreads( void ) {
5 void thread_rest ( void ) {
6 #if defined( HAVE_THREAD )
7 #if defined( HAVE_POSIX_THREAD )
8 - // TODO add checks for sched_yield or pthread_yield and call that
9 - // if available
10 - usleep( 0 );
11 #else // Win32
12 SwitchToThread( );
13 #endif
14 Index: iperf-2.0.2/src/Reporter.c
15 ===================================================================
16 --- iperf-2.0.2.orig/src/Reporter.c
17 +++ iperf-2.0.2/src/Reporter.c
18 @@ -111,6 +111,7 @@ report_statistics multiple_reports[kRepo
19 char buffer[64]; // Buffer for printing
20 ReportHeader *ReportRoot = NULL;
21 extern Condition ReportCond;
22 +extern Condition ReportDoneCond;
23 int reporter_process_report ( ReportHeader *report );
24 void process_report ( ReportHeader *report );
25 int reporter_handle_packet( ReportHeader *report );
26 @@ -338,7 +339,7 @@ void ReportPacket( ReportHeader* agent,
27 // item
28 while ( index == 0 ) {
29 Condition_Signal( &ReportCond );
30 - thread_rest();
31 + Condition_Wait( &ReportDoneCond );
32 index = agent->reporterindex;
33 }
34 agent->agentindex = 0;
35 @@ -346,7 +347,7 @@ void ReportPacket( ReportHeader* agent,
36 // Need to make sure that reporter is not about to be "lapped"
37 while ( index - 1 == agent->agentindex ) {
38 Condition_Signal( &ReportCond );
39 - thread_rest();
40 + Condition_Wait( &ReportDoneCond );
41 index = agent->reporterindex;
42 }
43
44 @@ -553,6 +554,7 @@ void reporter_spawn( thread_Settings *th
45 }
46 Condition_Unlock ( ReportCond );
47
48 +again:
49 if ( ReportRoot != NULL ) {
50 ReportHeader *temp = ReportRoot;
51 //Condition_Unlock ( ReportCond );
52 @@ -575,9 +577,12 @@ void reporter_spawn( thread_Settings *th
53 // finished with report so free it
54 free( temp );
55 Condition_Unlock ( ReportCond );
56 + Condition_Signal( &ReportDoneCond );
57 + if (ReportRoot)
58 + goto again;
59 }
60 - // yield control of CPU is another thread is waiting
61 - thread_rest();
62 + Condition_Signal( &ReportDoneCond );
63 + usleep(10000);
64 } else {
65 //Condition_Unlock ( ReportCond );
66 }
67 Index: iperf-2.0.2/src/main.cpp
68 ===================================================================
69 --- iperf-2.0.2.orig/src/main.cpp
70 +++ iperf-2.0.2/src/main.cpp
71 @@ -96,6 +96,7 @@ extern "C" {
72 // records being accessed in a report and also to
73 // serialize modification of the report list
74 Condition ReportCond;
75 + Condition ReportDoneCond;
76 }
77
78 // global variables only accessed within this file
79 @@ -141,6 +142,7 @@ int main( int argc, char **argv ) {
80
81 // Initialize global mutexes and conditions
82 Condition_Initialize ( &ReportCond );
83 + Condition_Initialize ( &ReportDoneCond );
84 Mutex_Initialize( &groupCond );
85 Mutex_Initialize( &clients_mutex );
86
87 -
88 To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
89 the body of a message to majordomo@vger.kernel.org
90 More majordomo info at http://vger.kernel.org/majordomo-info.html
91 Please read the FAQ at http://www.tux.org/lkml/
92