Changeset 34448

Show
Ignore:
Timestamp:
07/16/09 22:32:46 (4 years ago)
Author:
saturday06
Message:

developm

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

Legend:

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

    r34440 r34448  
    77src/mil/src/TestMain.cpp \ 
    88src/mil/src/StaticData.cpp \ 
    9 src/mil/src/Test1.cpp \ 
    109src/mil/src/Test2.cpp \ 
    1110src/mil/src/Test3.cpp \ 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/Debug.h

    r34447 r34448  
    3737        if (will_abort) { 
    3838            abort(); 
     39            throw std::runtime_error("halt"); 
    3940        } 
    4041    } 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/ModuleCommon.h

    r34447 r34448  
    216216    } 
    217217    void flush() { 
    218         for (int i = 0; i < _countof(data); i++) { 
     218        for (size_t i = 0; i < _countof(data); i++) { 
    219219#ifdef MIL_GUI_WINDOWS 
    220220            data[i].hWndCache = NULL; 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/Serial.h

    r34447 r34448  
    11#pragma once 
    22#include "Mil.h" 
     3#include "Mutex.h" 
    34 
    45/** 
     
    1213    }; 
    1314private: 
    14     Mutex& mutex; 
     15    Mutex mutex; 
    1516    int max; 
    1617    int serial; 
     
    4142    } 
    4243 
    43     void release(int v) { 
     44    bool release(int v) { 
    4445        synchronized (mutex) { 
    4546            try { 
    4647                list.push_back(v); 
    4748            } catch (std::exception&) { 
     49                return false; 
    4850            } 
    4951        } 
     52        return true; 
    5053    } 
    5154}; 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/Thread.h

    r34447 r34448  
    203203    Thread() : thread_id(thread_id_serial.retain()), is_exited(true) { 
    204204        if (thread_id == Serial::INVALID_VALUE) { 
    205             throw runtime_error("Can't retain thread_id"); 
     205            halt << "can't retain thread id"; 
    206206        } 
    207207        threads[thread_id].store(reinterpret_cast<void*>(this)); 
     
    211211        this->join(); 
    212212        threads[thread_id].store(NULL); 
    213         try { 
    214             thread_id_serial.release(thread_id); 
    215         } catch (std::exception&) { 
     213        if (!thread_id_serial.release(thread_id)) { 
    216214            halt << "can't release thread id"; 
    217215        } 
    218216    } 
    219217}; 
    220  
    221 class SynchronizeHelper : public boost::noncopyable { 
    222     Mutex& mutex; 
    223     bool once; 
    224 public: 
    225     bool evaluation() { 
    226         if (once) { 
    227             return false; 
    228         } 
    229         once = true; 
    230         return true; 
    231     } 
    232  
    233     SynchronizeHelper(Mutex& mutex) : mutex(mutex), once(false) { 
    234         mutex.lock(); 
    235     } 
    236  
    237     ~SynchronizeHelper() { 
    238         mutex.unlock(); 
    239     } 
    240 }; 
    241  
    242 #define synchronized(mutex) \ 
    243     for(mil::SynchronizeHelper synchronize_helper_instance__##mutex (mutex); (synchronize_helper_instance__##mutex ).evaluation();) 
    244218} 
    245219 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/gui-windows/WindowProcedureRedirector.h

    r34447 r34448  
    114114#endif 
    115115 
    116 #define MIL_STATIC_WINDOWPROCEDURE_MAX 5 
     116#define MIL_STATIC_WINDOWPROCEDURE_MAX 10 
    117117namespace mil { 
    118118template <typename T, LRESULT (T::* WindowProcedure)(HWND, UINT, WPARAM, LPARAM)> 
     
    120120public: 
    121121    static Serial serial; 
    122     WindowProcedureRedirector(T& receiver) : error(false), index(0), hWnd(NULL) { //, dynamic(false), dynamic_redirector(NULL) 
    123         try { 
    124             index = serial.get(); 
    125         } catch (std::exception&) { 
     122    WindowProcedureRedirector(T& receiver) : error(false), index(serial.retain()), hWnd(NULL) { //, dynamic(false), dynamic_redirector(NULL) 
     123        if (index == Serial::INVALID_VALUE) { 
    126124            DebugBreak(); 
    127125            error = true; 
     
    129127        } 
    130128        targets[index] = &receiver; 
    131     } 
    132  
    133     WNDPROC get() { 
     129        BOOST_STATIC_ASSERT(_countof(dispatchTable) == MIL_STATIC_WINDOWPROCEDURE_MAX); 
     130    } 
     131 
     132    WNDPROC get() const { 
    134133        if (error) { 
    135134            DebugBreak(); 
     
    139138    } 
    140139 
    141     bool set(HWND hWnd_) { 
     140    bool set(const HWND hWnd_) { 
    142141        if (error) { 
    143142            DebugBreak(); 
     
    170169        BOOST_STATIC_ASSERT(sizeof(LONG_PTR) == sizeof(targets[index])); 
    171170 
    172         try { 
    173             serial.release(index); 
    174         } catch (std::exception&) { 
     171        if (!serial.release(index)) { 
    175172            return; 
    176173        } 
     
    178175private: 
    179176    bool error; 
    180     unsigned int index; 
     177    const int index; 
    181178    HWND hWnd; 
    182  
    183     static unsigned int index_seq; 
    184     static LONG_PTR index_stack_mutex; 
    185     static std::stack<unsigned int> index_stack; 
    186179    static T* targets[MIL_STATIC_WINDOWPROCEDURE_MAX]; 
    187180    const static WNDPROC dispatchTable[MIL_STATIC_WINDOWPROCEDURE_MAX]; 
    188  
    189     struct Guard { 
    190         LONG_PTR* mutex; 
    191         Guard(LONG_PTR* mutex) : mutex(mutex) { 
    192             while (InterlockedExchangePointer(mutex, 0)) { 
    193                 Sleep(10); 
    194             } 
    195         } 
    196         ~Guard() { 
    197             InterlockedExchangePointer(mutex, 1); 
    198         } 
    199     }; 
    200181 
    201182    template <int Index> 
     
    214195// dispatchTable 
    215196template <typename T, LRESULT (T::* WindowProcedure)(HWND, UINT, WPARAM, LPARAM)> 
    216 const WNDPROC WindowProcedureRedirector<T, WindowProcedure>::dispatchTable[MIL_STATIC_WINDOWPROCEDURE_MAX] = { 
     197const WNDPROC WindowProcedureRedirector<T, WindowProcedure>::dispatchTable[] = { 
    217198    WindowProcedureRedirector<T, WindowProcedure>::template dispatch<0>, 
    218199    WindowProcedureRedirector<T, WindowProcedure>::template dispatch<1>, 
     
    220201    WindowProcedureRedirector<T, WindowProcedure>::template dispatch<3>, 
    221202    WindowProcedureRedirector<T, WindowProcedure>::template dispatch<4>, 
     203    WindowProcedureRedirector<T, WindowProcedure>::template dispatch<5>, 
     204    WindowProcedureRedirector<T, WindowProcedure>::template dispatch<6>, 
     205    WindowProcedureRedirector<T, WindowProcedure>::template dispatch<7>, 
     206    WindowProcedureRedirector<T, WindowProcedure>::template dispatch<8>, 
     207    WindowProcedureRedirector<T, WindowProcedure>::template dispatch<9>, 
    222208//#define WPR_TARGET_CLASS_ WindowProcedureRedirector<T, WindowProcedure>::template dispatch 
    223209//#define WPR_MAKE_TEMPLATE_(MAX,INDEX,TEMPLATE) TEMPLATE<INDEX>, 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/os-unix/Debug.h

    r34447 r34448  
    3131            *((volatile int*)0) = -1; 
    3232            cerr << "SEGV suppressed !" << endl; 
    33             //abort(); 
     33            abort(); 
     34            throw std::runtime_error("halt"); 
    3435        } 
    3536    } 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/os-unix/Thread.h

    r34447 r34448  
    1 #pragma once 
    2 #include "../Atomic.h" 
    3 #include "../Mil.h" 
    4 #include <pthread.h> 
    5 #include <unistd.h> 
    6 #include <sched.h> 
    7  
    8 /** 
    9  * POSIX 
    10  */ 
    11  
    12 namespace mil { 
    13  
    14 class Mutex : public boost::noncopyable { 
    15     pthread_mutex_t mutex; 
    16 public: 
    17     Mutex() { 
    18         pthread_mutex_init(&mutex, NULL); 
    19     } 
    20  
    21     void lock() { 
    22         pthread_mutex_lock(&mutex); 
    23     } 
    24  
    25     void unlock() { 
    26         pthread_mutex_unlock(&mutex); 
    27     } 
    28  
    29     ~Mutex() { 
    30         pthread_mutex_destroy(&mutex); 
    31     } 
    32 }; 
    33  
    34 class Conditional { 
    35     pthread_cond_t cond; 
    36     pthread_mutex_t mutex; 
    37 public: 
    38     Conditional() { 
    39         pthread_mutex_init(&mutex, NULL); 
    40         pthread_mutex_lock(&mutex); 
    41         pthread_cond_init(&cond, NULL); 
    42     } 
    43  
    44     ~Conditional() { 
    45         signal(); 
    46         pthread_cond_destroy(&cond); 
    47         pthread_mutex_destroy(&mutex); 
    48     } 
    49  
    50     void wait() { 
    51         pthread_cond_wait(&cond, &mutex); 
    52     } 
    53  
    54     void signal() { 
    55         pthread_cond_signal(&cond); 
    56     } 
    57 }; 
    58 } 
    59  
    60  
    61  
    62  
    63  
    64  
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/os-windows/Debug.h

    r34447 r34448  
    185185            abort(); 
    186186#endif 
     187            throw std::runtime_error("halt"); 
    187188        } 
    188189    } 
  • lang/objective-cplusplus/i3/trunk/src/mil/include/mil/os-windows/Thread.h

    r34447 r34448  
    1 #pragma once 
    2  
    3 #include "../Mil.h" 
    4  
    5 namespace mil { 
    6 class Mutex { 
    7     CRITICAL_SECTION cs; 
    8 public: 
    9     Mutex() { 
    10         InitializeCriticalSection(&cs); 
    11     } 
    12  
    13     void lock() { 
    14         EnterCriticalSection(&cs); 
    15     } 
    16  
    17     void unlock() { 
    18         LeaveCriticalSection(&cs); 
    19     } 
    20  
    21     ~Mutex() { 
    22         DeleteCriticalSection(&cs); 
    23     } 
    24 }; 
    25 class Conditional { 
    26     HANDLE event; 
    27 public: 
    28     Conditional() { 
    29         event = CreateEvent(NULL, TRUE, FALSE, NULL); 
    30     } 
    31  
    32     ~Conditional() { 
    33         signal(); 
    34         CloseHandle(event); 
    35     } 
    36  
    37     void wait() { 
    38         WaitForSingleObject(event, INFINITE); 
    39     } 
    40  
    41     void signal() { 
    42         SetEvent(event); 
    43     } 
    44 }; 
    45 } 
  • lang/objective-cplusplus/i3/trunk/src/mil/src/Test8.cpp

    r34447 r34448  
    2424struct FooThread : Thread<FooThread, DefaultThread> { 
    2525    void run() { 
    26         while (spin.load()); 
     26        while (spin.load()) { 
     27        } 
    2728 
    2829        for (int i = 0; i < 30000; i++) { 
     
    3637struct BarThread : Thread<BarThread, DefaultThread> { 
    3738    void run() { 
    38         while (spin.load()); 
     39        while (spin.load()) { 
     40        } 
    3941 
    4042        for (int i = 0; i < 50000; i++) { 
     
    4850struct FooThread2 : Thread<FooThread2, DefaultThread> { 
    4951    void run() { 
    50         while (spin.load()); 
     52        while (spin.load()) { 
     53        } 
    5154 
    5255        for (int i = 0; i < 23456; i++) { 
    53             while (!spin2.exchange(false)); 
     56            while (!spin2.exchange(false)) { 
     57            } 
    5458            global++; 
    5559            spin2.store(true); 
     
    6064struct BarThread2 : Thread<BarThread2, DefaultThread> { 
    6165    void run() { 
    62         while (spin.load()); 
     66        while (spin.load()) { 
     67        } 
    6368 
    6469        for (int i = 0; i < 100000; i++) { 
    65             while (!spin2.exchange(false)); 
     70            while (!spin2.exchange(false)) { 
     71            } 
    6672            global++; 
    6773            spin2.store(true); 
  • lang/objective-cplusplus/i3/trunk/src/mil/src/Test9.cpp

    r34447 r34448  
    2727    void createUI() { 
    2828        setWindow(create_window()); 
    29         while (spin.load()); 
     29        while (spin.load()) { 
     30        } 
    3031    } 
    3132 
     
    4546    void run() { 
    4647        setWindow(create_window()); 
    47         while (spin.load()); 
     48        while (spin.load()) { 
     49        } 
    4850 
    4951        for (int i = 0; i < 500; i++) { 
     
    6264    void run() { 
    6365        setWindow(create_window()); 
    64         while (spin.load()); 
     66        while (spin.load()) { 
     67        } 
    6568 
    6669        for (int i = 0; i < 500; i++) { 
     
    7881    void run() { 
    7982        setWindow(create_window()); 
    80         while (spin.load()); 
     83        while (spin.load()) { 
     84        } 
    8185 
    8286        for (int i = 0; i < 500; i++) {