* Small optimization for set_timer(): now only removes the timer from the list
if it won't be added anymore. * Small fix for set_timer(): now set the timer->due field back to 0 when a timer is removed - this prevented a timer from being correctly readded later (possible crash)! * net_buffer's append_cloned_data() now does some more checks to prevent unnecessary work and detect wrong arguments. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19375 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
8449c78396
commit
fc8c0ec946
@ -845,12 +845,15 @@ status_t
|
|||||||
append_cloned_data(net_buffer *_buffer, net_buffer *_source, uint32 offset,
|
append_cloned_data(net_buffer *_buffer, net_buffer *_source, uint32 offset,
|
||||||
size_t bytes)
|
size_t bytes)
|
||||||
{
|
{
|
||||||
|
if (bytes == 0)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
net_buffer_private *buffer = (net_buffer_private *)_buffer;
|
net_buffer_private *buffer = (net_buffer_private *)_buffer;
|
||||||
net_buffer_private *source = (net_buffer_private *)_source;
|
net_buffer_private *source = (net_buffer_private *)_source;
|
||||||
TRACE(("append_cloned_data(buffer %p, source %p, offset = %ld, bytes = %ld)\n",
|
TRACE(("append_cloned_data(buffer %p, source %p, offset = %ld, bytes = %ld)\n",
|
||||||
buffer, source, offset, bytes));
|
buffer, source, offset, bytes));
|
||||||
|
|
||||||
if (source->size < offset + bytes)
|
if (source->size < offset + bytes || source->size < offset)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
// find data_node to start with from the source buffer
|
// find data_node to start with from the source buffer
|
||||||
|
@ -300,16 +300,19 @@ set_timer(net_timer *timer, bigtime_t delay)
|
|||||||
{
|
{
|
||||||
BenaphoreLocker locker(sTimerLock);
|
BenaphoreLocker locker(sTimerLock);
|
||||||
|
|
||||||
if (timer->due > 0) {
|
if (timer->due > 0 && delay < 0) {
|
||||||
// this timer is already scheduled, cancel it
|
// this timer is scheduled, cancel it
|
||||||
list_remove_item(&sTimers, timer);
|
list_remove_item(&sTimers, timer);
|
||||||
|
timer->due = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delay >= 0) {
|
if (delay >= 0) {
|
||||||
// add this timer
|
// reschedule or add this timer
|
||||||
timer->due = system_time() + delay;
|
if (timer->due <= 0)
|
||||||
list_add_item(&sTimers, timer);
|
list_add_item(&sTimers, timer);
|
||||||
|
|
||||||
|
timer->due = system_time() + delay;
|
||||||
|
|
||||||
// notify timer about the change if necessary
|
// notify timer about the change if necessary
|
||||||
if (sTimerTimeout > timer->due)
|
if (sTimerTimeout > timer->due)
|
||||||
release_sem(sTimerWaitSem);
|
release_sem(sTimerWaitSem);
|
||||||
|
Loading…
Reference in New Issue
Block a user