OSDN Git Service

Avoid opening files during execution of other Ruby script
[molby/Molby.git] / wxSources / MyThread.cpp
1 /*
2  *  MyThread.cpp
3  *  Molby
4  *
5  *  Created by Toshi Nagata on 09/10/21.
6  *  Copyright 2009 Toshi Nagata. All rights reserved.
7  *
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation version 2 of the License.
11  
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.
16  */
17
18 #include "MyThread.h"
19
20 wxThreadError
21 MyThread::DetachNewThread(int (*entry_func)(void *, int), int (*exit_func)(void *, int), void *argptr, int argnum)
22 {
23         wxThreadError err;
24         MyThread *thread = new MyThread();
25         if (thread == NULL)
26                 return wxTHREAD_NO_RESOURCE;
27         thread->m_entry_func = entry_func;
28         thread->m_exit_func = exit_func;
29         thread->m_argptr = argptr;
30         thread->m_argnum = argnum;
31         if ((err = thread->Create()) != wxTHREAD_NO_ERROR)
32                 return err;
33         return thread->Run();
34 }
35
36 MyThread::ExitCode
37 MyThread::Entry()
38 {
39         ExitCode code = (ExitCode)(intptr_t)((*m_entry_func)(m_argptr, m_argnum));
40         if (m_exit_func)
41                 (*m_exit_func)(m_argptr, m_argnum);
42 //      Exit(code);
43         return (MyThread::ExitCode)code;
44 }