version 1.15, 2001/12/27 21:20:53
|
version 1.16, 2001/12/28 17:15:37
|
|
|
static QueueTable _queueTable(128); | static QueueTable _queueTable(128); |
static Mutex q_table_mut = Mutex(); | static Mutex q_table_mut = Mutex(); |
| |
static Uint32 _GetNextQueueId() throw(IPCException) |
Uint32 MessageQueue::getNextQueueId() throw(IPCException) |
{ | { |
|
static Uint32 _nextQueueId = 1; |
| |
static Uint32 _queueId = 2; |
// |
static Mutex _id_mut = Mutex(); |
// Lock mutex: |
|
// |
| |
|
static Mutex _id_mut = Mutex(); |
_id_mut.lock(pegasus_thread_self()); | _id_mut.lock(pegasus_thread_self()); |
| |
// Handle wrap-around! |
// Assign next queue id. Handle wrap around and never assign zero as |
if (_queueId == 0) |
// a queue id: |
_queueId = MessageQueue::_CIMOM_Q_ID; |
|
Uint32 ret = _queueId++; |
|
_id_mut.unlock(); |
|
| |
return ret; |
if (_nextQueueId == 0) |
} |
_nextQueueId = 1; |
| |
Uint32 MessageQueue::_CIMOM_Q_ID = 1; |
Uint32 queueId = _nextQueueId++; |
| |
MessageQueue::MessageQueue(const char * name, Boolean async) |
// |
: _mut( ), _count(0), _front(0), _back(0), |
// Unlock mutex: |
_async(async), |
// |
_workThread(MessageQueue::workThread, this, false), |
|
_workSemaphore(0) |
|
| |
|
_id_mut.unlock(); |
| |
{ |
return queueId; |
if(name != NULL) |
|
{ |
|
strncpy(_name, name, 25); |
|
_name[25] = 0x00; |
|
} | } |
else |
|
memset(_name, 0x00,25); |
MessageQueue::MessageQueue( |
|
const char* name, |
|
Boolean async, |
|
Uint32 queueId) |
|
: |
|
_queueId(queueId), _count(0), _front(0), _back(0), _async(async), |
|
_workThread(MessageQueue::workThread, this, false), _workSemaphore(0) |
|
{ |
|
// |
|
// Copy the name: |
|
// |
|
|
|
if (!name) |
|
name = ""; |
|
|
|
_name = new char[strlen(name) + 1]; |
|
strcpy(_name, name); |
|
|
|
// |
|
// Insert into queue table: |
|
// |
| |
q_table_mut.lock(pegasus_thread_self()); | q_table_mut.lock(pegasus_thread_self()); |
| |
while (!_queueTable.insert(_queueId = _GetNextQueueId(), this)) |
while (!_queueTable.insert(_queueId, this)) |
; | ; |
|
|
q_table_mut.unlock(); | q_table_mut.unlock(); |
| |
| |
if(_async == true) | if(_async == true) |
{ |
|
_workThread.run(); | _workThread.run(); |
} | } |
| |
} |
|
|
|
MessageQueue::~MessageQueue() | MessageQueue::~MessageQueue() |
{ | { |
// ATTN-A: thread safety! | // ATTN-A: thread safety! |
|
|
_workThread.join(); // wait for thread to complete | _workThread.join(); // wait for thread to complete |
} | } |
| |
|
// Free the name: |
|
|
|
delete [] _name; |
} | } |
| |
| |