Changeset 36256

Show
Ignore:
Timestamp:
12/24/09 12:39:00 (3 years ago)
Author:
saturday06
Message:

sdf

Location:
lang/objective-cplusplus/i3/trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • lang/objective-cplusplus/i3/trunk/Makefile.am

    r36243 r36256  
    111111endif 
    112112 
    113  
    114113if WITH_GUI_COCOA 
    115114bin_PROGRAMS  += coco 
    116 coco_SOURCES = tmp/main5.cpp 
     115coco_SOURCES = tmp/nc.cpp 
    117116coco_CXXFLAGS = ${i3_CXXFLAGS} 
    118117coco_LDFLAGS = ${i3_LDFLAGS} 
  • lang/objective-cplusplus/i3/trunk/src/Tester.cpp

    r36248 r36256  
    9292} 
    9393 
    94 struct Focus { 
     94struct TestFocus { 
    9595}; 
    9696 
    97 #ifdef MIL_GUI_WINDOWS 
    9897template <> 
    99 void InputWindow::execute(Focus&) { 
    100         SetForegroundWindow(hLocalWnd); 
    101         SetFocus(hEdit); 
     98void InputWindow::execute(TestFocus&) { 
     99        focus(); 
    102100} 
    103 #endif 
    104101 
    105102#ifdef MIL_OS_WINDOWS 
  • lang/objective-cplusplus/i3/trunk/src/gui-windows/InputWindowPlatform.h

    r35976 r36256  
    1313            public mil::GuiModule<InputWindowPlatform<Child> > { 
    1414public: 
     15        friend class mil::GuiModule<InputWindowPlatform<Child> >; 
    1516    MIL_CRTP_CLASS_MEMBERS; 
     17 
    1618    InputWindowPlatform(); 
    1719    ~InputWindowPlatform(); 
     
    1921    void createUI(); 
    2022    void run(); 
     23    mil::atomic<HICON> hSharedIcon; 
     24 
     25protected: 
     26        void focus(); 
     27    HWND hEdit; 
     28    HICON icon; 
     29    HMODULE riched20_dll; 
     30    size_t getEditVerticalMargin(); 
    2131 
    2232    void OnActivate(HWND hWnd, UINT state, HWND hWndActDeact, BOOL fMinimized); 
     
    3545    HBRUSH OnCtlColorEdit(HWND hWnd, HDC hdc, HWND hWndChild, int type); 
    3646 
    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: 
    4547    bool is_dwm_extend_frame_into_client_area; 
    4648    struct { 
     
    6466#endif 
    6567    } ce; 
    66     HICON icon; 
     68 
    6769}; 
    6870 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/StaticDataObjC.cpp

    r36216 r36256  
    22#import <Foundation/NSException.h> 
    33 
    4 #include "gui-cocoa/CocoaThread.h" 
     4 
     5#include "Thread.h" 
    56#include "FilterException.h" 
    67 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/Thread.h

    r36222 r36256  
    3030 
    3131#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 
    3341namespace mil { 
    3442namespace thread { 
     
    5563        assert(thread == nil); 
    5664 
    57         void* (*routine_)(void*) = foo::thread_routine; 
    58         void* arg_ = (void*)this; 
    59  
    6065        thread = [[WorkerThread alloc] init]; 
    61         [thread setData:routine_ arg:arg_]; 
     66                thread->routine = foo::thread_routine; 
     67                thread->arg = (void*)this; 
    6268        [NSThread detachNewThreadSelector:@selector(start) toTarget:thread withObject:nil]; 
    6369         
     
    166172#endif 
    167173 
     174 
    168175namespace mil { 
    169176template <class Child, template<class> class ThreadType = MIL_DEFAULT_THREAD> 
    170177class Thread : public ThreadType<Thread<Child, ThreadType> > { 
    171178public: 
     179        friend class ThreadType<Thread<Child, ThreadType> >; 
    172180    MIL_CRTP_CLASS_MEMBERS; 
    173181    const thread::id_t thread_id; 
    174182 
    175183private: 
    176     atomic<bool> thread_routine_running; 
    177  
    178184    enum THREAD_ROUTINE_STATUS { 
    179185        READY, 
    180186        RUNNING, 
    181187        STOPPING, 
     188                CLEANING, 
    182189    }; 
    183190    atomic<THREAD_ROUTINE_STATUS> thread_routine_status; 
    184  
    185 public: 
    186  
    187191    static int thread_routine_filtered(int, char** argv) { 
    188192        Thread<Child, ThreadType>* obj = (Thread<Child, ThreadType>*)argv; 
     
    192196            MIL_MODULE_GET_SUPER_CHILD(*obj); 
    193197 
     198        if (o.thread_routine_status.load() != RUNNING) { 
     199                        debug << "double run?"; 
     200                } 
    194201        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); 
    199207        return 0; 
    200208    } 
     
    205213    } 
    206214 
     215public: 
    207216    void run() { 
    208217    } 
    209218 
    210219    void start() { 
    211         if (thread_routine_running.exchange(true)) { 
    212             debug << "double start"; 
    213             return; 
    214         } 
    215220        if (!thread_routine_status.bool_compare_and_swap(READY, RUNNING)) { 
    216221            debug << "thread routine is not ready"; 
     
    222227 
    223228    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 
    230231            if (retry == 0) { 
    231                 halt << "thread don't exit"; 
     232                halt << "thread doesn't exit"; 
    232233                break; 
    233234            } 
     235 
    234236            sleep(1); 
    235237        } 
    236238 
     239                // only one thread can clean 
     240                if (!thread_routine_status.bool_compare_and_swap(STOPPING, CLEANING)) { 
     241                        return; 
     242                } 
     243 
    237244        ThreadType<Thread<Child, ThreadType> >::clean(); 
    238245 
    239         if (!thread_routine_status.bool_compare_and_swap(STOPPING, READY)) { 
     246        if (!thread_routine_status.bool_compare_and_swap(CLEANING, READY)) { 
    240247            debug << "thread routine is stopping"; 
    241248            return; 
     
    244251 
    245252    Thread() : thread_id(thread::id_serial.retain()), 
    246                thread_routine_running(false), 
    247253               thread_routine_status(READY) { 
    248254        if (!thread::is_valid_id(thread_id)) { 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/gui-cocoa/CocoaThread.h

    r34815 r36256  
    1 #pragma once 
    21 
    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 @end 
    13  
  • lang/objective-cplusplus/i3/trunk/tmp/main4.cpp

    r36243 r36256  
    6666    WorkerThread* thread = [[WorkerThread alloc] init]; 
    6767    thread->thread_id = 1; 
    68     [NSThread detachNewThreadSelector:@selector(startThread) toTarget:thread withObject:nil]; 
     68    [NSThread detachNewThreadSelector:@selector(startThread) 
     69              toTarget:thread withObject:nil]; 
    6970 
    7071    sleep(2); 
  • lang/objective-cplusplus/i3/trunk/tmp/nc.cpp

    r36226 r36256  
    141141    } 
    142142 
    143     sleep(1); 
     143    sleep(2); 
    144144 
    145145    NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 
    146146    NSNotification* notification3 = [NSNotification notificationWithName:@"TestNotification3" object:nil]; 
    147147    [center postNotification:notification3]; 
     148    sleep(2); 
     149 
    148150    NSNotification* notification2 = [NSNotification notificationWithName:@"TestNotification2" object:nil]; 
    149151    [center postNotification:notification2]; 
     152    sleep(2); 
     153 
    150154    NSNotification* notification1 = [NSNotification notificationWithName:@"TestNotification1" object:nil]; 
    151155    [center postNotification:notification1]; 
    152156 
    153     sleep(5); 
     157    [[NSRunLoop currentRunLoop] run]; 
    154158 
    155159    [pool release];