Revision 6613266b
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/EffectMessageSender.java | ||
---|---|---|
50 | 50 |
|
51 | 51 |
private static Vector<Message> mList =null; |
52 | 52 |
private static EffectMessageSender mThis=null; |
53 |
private static volatile boolean mPaused;
|
|
54 |
|
|
53 |
private static volatile boolean mNotify = false;
|
|
54 |
|
|
55 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 56 |
|
57 | 57 |
private EffectMessageSender() |
... | ... | |
62 | 62 |
|
63 | 63 |
static void startSending() |
64 | 64 |
{ |
65 |
mPaused = false; |
|
66 |
|
|
67 | 65 |
if( mThis==null ) |
68 | 66 |
{ |
69 | 67 |
mList = new Vector<>(); |
... | ... | |
83 | 81 |
|
84 | 82 |
static void stopSending() |
85 | 83 |
{ |
86 |
mPaused = true; |
|
84 |
|
|
87 | 85 |
} |
88 | 86 |
|
89 | 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
94 | 92 |
|
95 | 93 |
while(true) |
96 | 94 |
{ |
97 |
if( mList.size()>0 ) |
|
95 |
//android.util.Log.d("SENDER", "running..."); |
|
96 |
|
|
97 |
while( mList.size()>0 ) |
|
98 | 98 |
{ |
99 |
tmp = mList.get(0);
|
|
99 |
tmp = mList.remove(0);
|
|
100 | 100 |
tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, tmp.mEffectName, tmp.mBitmapID, tmp.mStr); |
101 |
mList.remove(0); |
|
102 | 101 |
} |
103 |
|
|
104 |
if( mPaused )
|
|
102 |
|
|
103 |
synchronized(mThis)
|
|
105 | 104 |
{ |
106 |
synchronized(mThis)
|
|
105 |
if (!mNotify)
|
|
107 | 106 |
{ |
108 | 107 |
try { mThis.wait(); } |
109 | 108 |
catch(InterruptedException ex) { } |
110 | 109 |
} |
110 |
mNotify = false; |
|
111 | 111 |
} |
112 | 112 |
} |
113 | 113 |
} |
... | ... | |
116 | 116 |
|
117 | 117 |
static void newMessage(EffectListener l, EffectMessage m, long id, int name, long bmpID, String str) |
118 | 118 |
{ |
119 |
if( mThis!=null ) |
|
119 |
Message msg = mThis.new Message(l,m,id,name,bmpID,str); |
|
120 |
mList.add(msg); |
|
121 |
|
|
122 |
synchronized(mThis) |
|
120 | 123 |
{ |
121 |
Message msg = mThis.new Message(l,m,id,name,bmpID,str);
|
|
122 |
mList.add(msg);
|
|
124 |
mNotify = true;
|
|
125 |
mThis.notify();
|
|
123 | 126 |
} |
124 | 127 |
} |
125 | 128 |
} |
Also available in: Unified diff
Major: the MessageSender thread used to be running all the time in a tight loop!!