Fix for ticket #3961:

The previous code used kill_thread() and then destroyed the common RingBuffer.
This wasn't working, and as Axel notes it's not really working on kernel side.
* Added RingBuffer::DestroyLock
* Changed the thread to exit gracefully on RingBuffer semaphore destruction.
* Changed close function to destroy RingBuffer sem, wait_for_thread and then destroy resources.
* Minor code style fixes.
(And also my first commit.)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33795 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Fredrik Holmqvist
2009-10-27 20:03:50 +00:00
parent 173b5560a2
commit 6fde258427
@@ -25,6 +25,7 @@ public:
bool Lock(); bool Lock();
void Unlock(); void Unlock();
void DestroyLock();
private: private:
ring_buffer *fBuffer; ring_buffer *fBuffer;
sem_id fLock; sem_id fLock;
@@ -141,24 +142,23 @@ dump_acpi_namespace(acpi_ns_device_info *device, char *root, int indenting)
written = 0; written = 0;
RingBuffer &ringBuffer = *device->buffer; RingBuffer &ringBuffer = *device->buffer;
size_t toWrite = strlen(output); size_t toWrite = strlen(output);
if (toWrite > 0) {
if (toWrite <= 0)
break;
strlcat(output, "\n", sizeof(output)); strlcat(output, "\n", sizeof(output));
toWrite++; toWrite++;
if (ringBuffer.Lock()) { if (!ringBuffer.Lock())
if (ringBuffer.WritableAmount() < toWrite) { break;
if (!make_space(device, toWrite)) {
panic("couldn't make space"); if (ringBuffer.WritableAmount() < toWrite &&
exit_thread(0); !make_space(device, toWrite))
} break;
}
written = ringBuffer.Write(output, toWrite); written = ringBuffer.Write(output, toWrite);
ringBuffer.Unlock(); ringBuffer.Unlock();
}
dump_acpi_namespace(device, result, indenting + 1); dump_acpi_namespace(device, result, indenting + 1);
} }
}
} }
@@ -288,14 +288,15 @@ acpi_namespace_control(void* cookie, uint32 op, void* arg, size_t len)
static status_t static status_t
acpi_namespace_close(void* cookie) acpi_namespace_close(void* cookie)
{ {
status_t status;
acpi_ns_device_info *device = (acpi_ns_device_info *)cookie; acpi_ns_device_info *device = (acpi_ns_device_info *)cookie;
dprintf("acpi_ns_dump: device_close\n"); dprintf("acpi_ns_dump: device_close\n");
if (device->read_sem >= 0) if (device->read_sem >= 0)
delete_sem(device->read_sem); delete_sem(device->read_sem);
kill_thread(device->thread); device->buffer->DestroyLock();
wait_for_thread(device->thread, &status);
delete device->buffer; delete device->buffer;
return B_OK; return B_OK;
@@ -383,7 +384,6 @@ RingBuffer::RingBuffer(size_t size)
RingBuffer::~RingBuffer() RingBuffer::~RingBuffer()
{ {
delete_sem(fLock);
delete_ring_buffer(fBuffer); delete_ring_buffer(fBuffer);
} }
@@ -432,4 +432,9 @@ RingBuffer::Unlock()
} }
void
RingBuffer::DestroyLock()
{
delete_sem(fLock);
}