root/lang/objective-cplusplus/i3/trunk/src/mil/include/mil/StaticData.cpp @ 34827

Revision 34827, 3.5 kB (checked in by saturday06, 5 years ago)

iiouxdfgvsogjsoghsodhjdohjsdohjdophsdfpoisdfophj

Line 
1#include "PrecompiledHeaders.h"
2#include "Mil.h"
3#include "Thread.h"
4#include "ModuleCommon.h"
5
6//#include <fecti/Utility/FBlockMemoryAllocator/FAllocatorImpl_Block.cpp>
7//#include <fecti/Utility/FThread.cpp>
8
9//#ifndef ENABLE_NLS
10#ifndef _
11#if defined(_UNICODE) || defined(UNICODE)
12#define _(x) L##x
13#else
14#define _(x) x
15#endif
16#endif
17
18namespace mil {
19namespace thread {
20Serial id_serial(MIL_MAX_THREADS);
21static atomic<void*> threads[MIL_MAX_THREADS];
22
23void* get(id_t thread_id) {
24    if (!is_valid_id(thread_id)) {
25        halt << "thread_id is out of range";
26        return NULL;
27    }
28    return threads[thread_id].load();
29}
30
31void set(id_t thread_id, void* object) {
32    if (!is_valid_id(thread_id)) {
33        halt << "thread_id is out of range";
34        return;
35    }
36    threads[thread_id].store(object);
37}
38
39bool is_valid_id(id_t thread_id) {
40    if (thread_id < 0 || thread_id >= static_cast<id_t>(_countof(threads)) || thread_id == Serial::INVALID_VALUE) {
41        return false;
42    }
43    return true;
44}
45}
46
47ExitNotifier exitNotifier /* XXX depends on id_serial */;
48int auto_joiner_index = 0;
49AutoJoiner auto_joiners[MIL_MAX_THREADS];
50}
51
52#undef filter_exception_and_start
53extern "C" int filter_exception_and_start(int argc, char** argv, int (*start)(int, char**)) {
54    try {
55        return start(argc, argv);
56    }
57    //catch (boost::exception& e)
58    //{
59    //    debug << "c++ boost::exception [" << boost::diagnostic_information(e) << "]";
60    //}
61    catch (std::exception& e) {
62        //debug << "c++ std::exception [" << e.what() << "]";
63        //_ftprintf(stderr, gettext("c++ std::exception [%s]\n"), e.what());
64        //fprintf(stderr, gettext("c++ std::exception [%s]\n"), e.what()); // e.what() -> char
65    }
66    return 1;
67}
68
69#ifdef __OBJC__
70namespace mil {
71class CocoaThreadManager : boost::noncopyable {
72    Mutex mutex;
73    NSPort* port_matrix[MIL_MAX_THREADS][MIL_MAX_THREADS];
74    NSConnection* send_connection_matrix[MIL_MAX_THREADS][MIL_MAX_THREADS];
75    NSConnection* receive_connection_matrix[MIL_MAX_THREADS][MIL_MAX_THREADS];
76    id proxies[MIL_MAX_THREADS][MIL_MAX_THREADS];
77public:
78    CocoaThreadManager() {
79        synchronized (mutex) {
80        }
81    }
82
83    ~CocoaThreadManager() {
84        synchronized (mutex) {
85        }
86    }
87
88    id getProxy(int sender, int receiver) {
89        synchronized (mutex) {
90            if (proxies[sender][receiver]) {
91                return proxies[sender][receiver];
92            }
93            port_matrix[sender][receiver] = [NSPort port];
94            port_matrix[receiver][sender] = [NSPort port];
95            send_connection_matrix[sender][receiver] =
96    [NSConnection connectionWithReceivePort:port_matrix[sender][receiver] sendPort:port_matrix[receiver][sender]];
97
98            proxies[sender][receiver] = [send_connection_matrix[sender][receiver] rootProxy];
99            return proxies[sender][receiver];
100        }
101    }
102
103    void setProxy(int receiver, id object) {
104        synchronized (mutex) {
105            for (unsigned int sender = 0; sender < _countof(send_connection_matrix[0]); sender++) {
106                if (send_connection_matrix[sender][receiver] && !receive_connection_matrix[sender][receiver]) {
107                    receive_connection_matrix[sender][receiver] =
108    [NSConnection connectionWithReceivePort:port_matrix[receiver][sender] sendPort:port_matrix[sender][receiver]];
109[receive_connection_matrix[sender][receiver] setRootObject: object];
110                }
111            }
112        }
113    }
114};
115
116}
117#endif
Note: See TracBrowser for help on using the browser.