Changeset 36256
- Timestamp:
- 12/24/09 12:39:00 (3 years ago)
- Location:
- lang/objective-cplusplus/i3/trunk
- Files:
-
- 8 modified
-
Makefile.am (modified) (1 diff)
-
src/Tester.cpp (modified) (1 diff)
-
src/gui-windows/InputWindowPlatform.h (modified) (4 diffs)
-
src/mil/include/mil/StaticDataObjC.cpp (modified) (1 diff)
-
src/mil/include/mil/Thread.h (modified) (7 diffs)
-
src/mil/include/mil/gui-cocoa/CocoaThread.h (modified) (1 diff)
-
tmp/main4.cpp (modified) (1 diff)
-
tmp/nc.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/objective-cplusplus/i3/trunk/Makefile.am
r36243 r36256 111 111 endif 112 112 113 114 113 if WITH_GUI_COCOA 115 114 bin_PROGRAMS += coco 116 coco_SOURCES = tmp/ main5.cpp115 coco_SOURCES = tmp/nc.cpp 117 116 coco_CXXFLAGS = ${i3_CXXFLAGS} 118 117 coco_LDFLAGS = ${i3_LDFLAGS} -
lang/objective-cplusplus/i3/trunk/src/Tester.cpp
r36248 r36256 92 92 } 93 93 94 struct Focus {94 struct TestFocus { 95 95 }; 96 96 97 #ifdef MIL_GUI_WINDOWS98 97 template <> 99 void InputWindow::execute(Focus&) { 100 SetForegroundWindow(hLocalWnd); 101 SetFocus(hEdit); 98 void InputWindow::execute(TestFocus&) { 99 focus(); 102 100 } 103 #endif104 101 105 102 #ifdef MIL_OS_WINDOWS -
lang/objective-cplusplus/i3/trunk/src/gui-windows/InputWindowPlatform.h
r35976 r36256 13 13 public mil::GuiModule<InputWindowPlatform<Child> > { 14 14 public: 15 friend class mil::GuiModule<InputWindowPlatform<Child> >; 15 16 MIL_CRTP_CLASS_MEMBERS; 17 16 18 InputWindowPlatform(); 17 19 ~InputWindowPlatform(); … … 19 21 void createUI(); 20 22 void run(); 23 mil::atomic<HICON> hSharedIcon; 24 25 protected: 26 void focus(); 27 HWND hEdit; 28 HICON icon; 29 HMODULE riched20_dll; 30 size_t getEditVerticalMargin(); 21 31 22 32 void OnActivate(HWND hWnd, UINT state, HWND hWndActDeact, BOOL fMinimized); … … 35 45 HBRUSH OnCtlColorEdit(HWND hWnd, HDC hdc, HWND hWndChild, int type); 36 46 37 //mil::atomic<HWND> hSharedEdit;38 mil::atomic<HICON> hSharedIcon;39 40 protected:41 HWND hEdit;42 HMODULE riched20_dll;43 size_t getEditVerticalMargin();44 private:45 47 bool is_dwm_extend_frame_into_client_area; 46 48 struct { … … 64 66 #endif 65 67 } ce; 66 HICON icon; 68 67 69 }; 68 70 -
lang/objective-cplusplus/i3/trunk/src/mil/include/mil/StaticDataObjC.cpp
r36216 r36256 2 2 #import <Foundation/NSException.h> 3 3 4 #include "gui-cocoa/CocoaThread.h" 4 5 #include "Thread.h" 5 6 #include "FilterException.h" 6 7 -
lang/objective-cplusplus/i3/trunk/src/mil/include/mil/Thread.h
r36222 r36256 30 30 31 31 #ifdef __OBJC__ 32 #include "gui-cocoa/CocoaThread.h" 32 33 @interface WorkerThread : NSObject { 34 @public 35 void* (*routine)(void*); 36 void* arg; 37 } 38 - (void)start; 39 @end 40 33 41 namespace mil { 34 42 namespace thread { … … 55 63 assert(thread == nil); 56 64 57 void* (*routine_)(void*) = foo::thread_routine;58 void* arg_ = (void*)this;59 60 65 thread = [[WorkerThread alloc] init]; 61 [thread setData:routine_ arg:arg_]; 66 thread->routine = foo::thread_routine; 67 thread->arg = (void*)this; 62 68 [NSThread detachNewThreadSelector:@selector(start) toTarget:thread withObject:nil]; 63 69 … … 166 172 #endif 167 173 174 168 175 namespace mil { 169 176 template <class Child, template<class> class ThreadType = MIL_DEFAULT_THREAD> 170 177 class Thread : public ThreadType<Thread<Child, ThreadType> > { 171 178 public: 179 friend class ThreadType<Thread<Child, ThreadType> >; 172 180 MIL_CRTP_CLASS_MEMBERS; 173 181 const thread::id_t thread_id; 174 182 175 183 private: 176 atomic<bool> thread_routine_running;177 178 184 enum THREAD_ROUTINE_STATUS { 179 185 READY, 180 186 RUNNING, 181 187 STOPPING, 188 CLEANING, 182 189 }; 183 190 atomic<THREAD_ROUTINE_STATUS> thread_routine_status; 184 185 public:186 187 191 static int thread_routine_filtered(int, char** argv) { 188 192 Thread<Child, ThreadType>* obj = (Thread<Child, ThreadType>*)argv; … … 192 196 MIL_MODULE_GET_SUPER_CHILD(*obj); 193 197 198 if (o.thread_routine_status.load() != RUNNING) { 199 debug << "double run?"; 200 } 194 201 o.run(); 195 if (!o.thread_routine_running.exchange(false)) { 196 halt << "double stop"; 197 } 198 202 if (o.thread_routine_status.load() != RUNNING) { 203 debug << "double stop?"; 204 } 205 206 o.thread_routine_status.store(STOPPING); 199 207 return 0; 200 208 } … … 205 213 } 206 214 215 public: 207 216 void run() { 208 217 } 209 218 210 219 void start() { 211 if (thread_routine_running.exchange(true)) {212 debug << "double start";213 return;214 }215 220 if (!thread_routine_status.bool_compare_and_swap(READY, RUNNING)) { 216 221 debug << "thread routine is not ready"; … … 222 227 223 228 void join() { 224 if (!thread_routine_status.bool_compare_and_swap(RUNNING, STOPPING)) { 225 //debug << "thread routine is not running"; 226 return; 227 } 228 229 for (int retry = 50; this->thread_routine_running.load(); retry--) { 229 for (int retry = 50; thread_routine_status.load() == RUNNING; retry--) { 230 230 231 if (retry == 0) { 231 halt << "thread do n't exit";232 halt << "thread doesn't exit"; 232 233 break; 233 234 } 235 234 236 sleep(1); 235 237 } 236 238 239 // only one thread can clean 240 if (!thread_routine_status.bool_compare_and_swap(STOPPING, CLEANING)) { 241 return; 242 } 243 237 244 ThreadType<Thread<Child, ThreadType> >::clean(); 238 245 239 if (!thread_routine_status.bool_compare_and_swap( STOPPING, READY)) {246 if (!thread_routine_status.bool_compare_and_swap(CLEANING, READY)) { 240 247 debug << "thread routine is stopping"; 241 248 return; … … 244 251 245 252 Thread() : thread_id(thread::id_serial.retain()), 246 thread_routine_running(false),247 253 thread_routine_status(READY) { 248 254 if (!thread::is_valid_id(thread_id)) { -
lang/objective-cplusplus/i3/trunk/src/mil/include/mil/gui-cocoa/CocoaThread.h
r34815 r36256 1 #pragma once2 1 3 @interface WorkerThread :4 NSObject {5 void* (*routine)(void*);6 void* arg;7 }8 - (void)setData:9 (void* (*)(void*))routine_ arg:10 (void*)arg_;11 - (void)start;12 @end13 -
lang/objective-cplusplus/i3/trunk/tmp/main4.cpp
r36243 r36256 66 66 WorkerThread* thread = [[WorkerThread alloc] init]; 67 67 thread->thread_id = 1; 68 [NSThread detachNewThreadSelector:@selector(startThread) toTarget:thread withObject:nil]; 68 [NSThread detachNewThreadSelector:@selector(startThread) 69 toTarget:thread withObject:nil]; 69 70 70 71 sleep(2); -
lang/objective-cplusplus/i3/trunk/tmp/nc.cpp
r36226 r36256 141 141 } 142 142 143 sleep( 1);143 sleep(2); 144 144 145 145 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 146 146 NSNotification* notification3 = [NSNotification notificationWithName:@"TestNotification3" object:nil]; 147 147 [center postNotification:notification3]; 148 sleep(2); 149 148 150 NSNotification* notification2 = [NSNotification notificationWithName:@"TestNotification2" object:nil]; 149 151 [center postNotification:notification2]; 152 sleep(2); 153 150 154 NSNotification* notification1 = [NSNotification notificationWithName:@"TestNotification1" object:nil]; 151 155 [center postNotification:notification1]; 152 156 153 sleep(5);157 [[NSRunLoop currentRunLoop] run]; 154 158 155 159 [pool release];
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)