2
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3
* http://www.gnu.org/licenses/gpl-3.0.html
17
#define WIN32_LEAN_AND_MEAN
20
typedef HANDLE shm_handle_t;
21
typedef HANDLE semaphore_t;
27
#include <sys/types.h>
32
#if defined(__APPLE__) && defined(__MACH__)
33
typedef int shm_handle_t;
34
typedef mach_port_t semaphore_t;
36
typedef int shm_handle_t;
37
typedef int semaphore_t;
42
static const int ipc_buf_size = 1024*64;
62
enum rw_t{ reader, writer };
67
bool OK() const { return ok; };
69
void* BasePointer() const { return shared; };
70
size_t Size() const { return ipc_buf_size; };
72
bool Server() const { return server; };
73
bool Client() const { return !server; };
77
* Lock(reader) locks "as reader", not "the reader semaphore", i.e. it
78
* 1. locks the reader semaphore
79
* 2. locks the writer mutex, so the shared memory cannot be written while we read it
81
* Lock(writer) locks "as writer", this is equivalent to locking "the writer mutex"
83
* Unlock(reader) unlocks "as reader", i.e. it actually unlocks the writer mutex
84
* which the caller is still holding, so another process can write to the shared memory area again.
85
* It does not release the reader semaphore, since it should block on it on the next iteration.
87
* Unlock(writer) locks "as writer", i.e. it
88
* 1. unlocks the reader semaphore, waking up the Server thread
89
* 2. unlocks the writer mutex, so the Server thread can acquire it and prevent other processes from writing
99
class IPC : public wxThread
101
volatile bool is_shutdown;
105
IPC() : is_shutdown(false) {};
107
virtual ExitCode Entry();
109
bool Server() const { return shm.Server(); };
113
void Send(const wxString& value);
125
* expemplary code for app.cpp, specifically CodeBlocksApp::ParseCmdLine >>>>>>>>>>>>>>>
128
IPC *ipc = new IPC; // don't delete
136
// parser is the wxCmdLineParser
140
static const unsigned int max_size = ipc_buf_size / sizeof(wxChar);
144
int count = parser.GetParamCount();
146
for (int i = 0; i < count; ++i)
148
item = parser.GetParam(i);
149
item.append(_T('\n'));
151
if(buf.length() + item.length() + 1) >= max_size)
153
buf.append(_T('\0'));
162
buf.append(_T('\0'));
168
* <<<<<<<<<<<<<<< expemplary code