Lines Matching refs:interface

44 /*!	A service thread for each device interface. It just reads as many packets
46 device interface.
51 net_device_interface* interface = (net_device_interface*)_interface;
52 net_device* device = interface->device;
60 if (atomic_get(&interface->monitor_count) > 0)
61 device_interface_monitor_receive(interface, buffer);
65 if (interface->deframe_func(interface->device, buffer) != B_OK) {
72 status = fifo_enqueue_buffer(&interface->receive_queue, buffer);
99 net_device_interface* interface = (net_device_interface*)_interface;
100 net_device* device = interface->device;
103 while (atomic_get(&interface->ref_count) > 0) {
104 ssize_t status = fifo_dequeue_buffer(&interface->receive_queue, 0,
113 // If the interface is already specified, this buffer was
124 buffer->index = interface->device->index;
128 RecursiveLocker locker(interface->receive_lock);
131 = interface->receive_funcs.GetIterator();
170 while (net_device_interface* interface = iterator.Next()) {
171 if (!strcmp(interface->device->name, name))
172 return interface;
182 net_device_interface* interface = new(std::nothrow) net_device_interface;
183 if (interface == NULL)
186 recursive_lock_init(&interface->receive_lock, "device interface receive");
187 recursive_lock_init(&interface->monitor_lock, "device interface monitors");
192 if (init_fifo(&interface->receive_queue, name, 16 * 1024 * 1024) < B_OK)
195 interface->device = device;
196 interface->up_count = 0;
197 interface->ref_count = 1;
198 interface->busy = false;
199 interface->monitor_count = 0;
200 interface->deframe_func = NULL;
201 interface->deframe_ref_count = 0;
205 interface->reader_thread = -1;
206 interface->consumer_thread = spawn_kernel_thread(device_consumer_thread,
207 name, B_DISPLAY_PRIORITY, interface);
208 if (interface->consumer_thread < B_OK)
210 resume_thread(interface->consumer_thread);
212 // TODO: proper interface index allocation
216 sInterfaces.Add(interface);
217 return interface;
220 uninit_fifo(&interface->receive_queue);
222 recursive_lock_destroy(&interface->receive_lock);
223 recursive_lock_destroy(&interface->monitor_lock);
224 delete interface;
231 notify_device_monitors(net_device_interface* interface, int32 event)
233 RecursiveLocker locker(interface->monitor_lock);
236 = interface->monitor_funcs.GetIterator();
255 net_device_interface* interface
258 kprintf("device: %p\n", interface->device);
259 kprintf("reader_thread: %" B_PRId32 "\n", interface->reader_thread);
260 kprintf("up_count: %" B_PRIu32 "\n", interface->up_count);
261 kprintf("ref_count: %" B_PRId32 "\n", interface->ref_count);
262 kprintf("deframe_func: %p\n", interface->deframe_func);
263 kprintf("deframe_ref_count: %" B_PRId32 "\n", interface->ref_count);
264 kprintf("consumer_thread: %" B_PRId32 "\n", interface->consumer_thread);
266 kprintf("monitor_count: %" B_PRId32 "\n", interface->monitor_count);
267 kprintf("monitor_lock: %p\n", &interface->monitor_lock);
270 = interface->monitor_funcs.GetIterator();
274 kprintf("receive_lock: %p\n", &interface->receive_lock);
275 kprintf("receive_queue: %p\n", &interface->receive_queue);
278 = interface->receive_funcs.GetIterator();
290 while (net_device_interface* interface = iterator.Next()) {
291 kprintf(" %p %s\n", interface, interface->device->name);
305 acquire_device_interface(net_device_interface* interface)
307 if (interface == NULL || atomic_add(&interface->ref_count, 1) == 0)
310 return interface;
315 get_device_interface_address(net_device_interface* interface,
321 address.sdl_index = interface->device->index;
322 address.sdl_type = interface->device->type;
323 address.sdl_nlen = strlen(interface->device->name);
325 memcpy(address.sdl_data, interface->device->name, address.sdl_nlen);
327 address.sdl_alen = interface->device->address.length;
328 memcpy(LLADDR(&address), interface->device->address.data, address.sdl_alen);
364 while (net_device_interface* interface = iterator.Next()) {
365 buffer.Push(interface->device->name, IF_NAMESIZE);
368 get_device_interface_address(interface, (sockaddr*)&address);
383 /*! Releases the reference for the interface. When all references are
384 released, the interface is removed.
387 put_device_interface(struct net_device_interface* interface)
389 if (interface == NULL)
392 if (atomic_add(&interface->ref_count, -1) != 1)
395 // Indicate we are in the process of destroying this interface
397 interface->ref_count = 0;
400 sInterfaces.Remove(interface);
403 uninit_fifo(&interface->receive_queue);
404 wait_for_thread(interface->consumer_thread, NULL);
406 net_device* device = interface->device;
412 recursive_lock_destroy(&interface->monitor_lock);
413 recursive_lock_destroy(&interface->receive_lock);
414 delete interface;
418 /*! Finds an interface by the specified index and acquires a reference to it.
427 while (net_device_interface* interface = iterator.Next()) {
428 if (interface->device->index == index) {
429 if (interface->busy)
432 if (atomic_add(&interface->ref_count, 1) != 0)
433 return interface;
441 /*! Finds an interface by the specified name and grabs a reference to it.
442 If the interface does not yet exist, a new one is created.
449 net_device_interface* interface = find_device_interface(name);
450 if (interface != NULL) {
451 if (interface->busy)
454 if (atomic_add(&interface->ref_count, 1) != 0)
455 return interface;
457 // try to recreate interface - it just got removed
480 interface = allocate_device_interface(device, module);
481 if (interface != NULL) {
483 return interface;
498 /*! Feeds the device monitors of the \a interface with the specified \a buffer.
499 You might want to check interface::monitor_count before calling this
503 device_interface_monitor_receive(net_device_interface* interface,
506 RecursiveLocker locker(interface->monitor_lock);
509 = interface->monitor_funcs.GetIterator();
518 up_device_interface(net_device_interface* interface)
520 net_device* device = interface->device;
522 RecursiveLocker locker(interface->receive_lock);
524 if (interface->up_count != 0) {
525 interface->up_count++;
538 interface->reader_thread = spawn_kernel_thread(device_reader_thread,
539 name, B_REAL_TIME_DISPLAY_PRIORITY - 10, interface);
540 if (interface->reader_thread < B_OK)
541 return interface->reader_thread;
547 resume_thread(interface->reader_thread);
549 interface->up_count = 1;
555 down_device_interface(net_device_interface* interface)
573 net_device* device = interface->device;
578 notify_device_monitors(interface, B_DEVICE_GOING_DOWN);
581 thread_id readerThread = interface->reader_thread;
583 // make sure the reader thread is gone before shutting down the interface
600 // find device interface for this device
601 net_device_interface* interface = find_device_interface(device->name);
602 if (interface == NULL)
605 RecursiveLocker _(interface->receive_lock);
607 if (--interface->deframe_ref_count == 0)
608 interface->deframe_func = NULL;
626 // find device interface for this device
627 net_device_interface* interface = find_device_interface(device->name);
628 if (interface == NULL)
631 RecursiveLocker _(interface->receive_lock);
633 if (interface->deframe_func != NULL
634 && interface->deframe_func != deframeFunc)
637 interface->deframe_func = deframeFunc;
638 interface->deframe_ref_count++;
664 // find device interface for this device
665 net_device_interface* interface = find_device_interface(device->name);
666 if (interface == NULL)
669 RecursiveLocker _(interface->receive_lock);
674 = interface->receive_funcs.GetIterator();
689 interface->receive_funcs.Add(handler);
700 // find device interface for this device
701 net_device_interface* interface = find_device_interface(device->name);
702 if (interface == NULL)
705 RecursiveLocker _(interface->receive_lock);
710 = interface->receive_funcs.GetIterator();
733 // find device interface for this device
734 net_device_interface* interface = find_device_interface(device->name);
735 if (interface == NULL)
738 RecursiveLocker monitorLocker(interface->monitor_lock);
739 interface->monitor_funcs.Add(monitor);
740 atomic_add(&interface->monitor_count, 1);
752 // find device interface for this device
753 net_device_interface* interface = find_device_interface(device->name);
754 if (interface == NULL)
757 RecursiveLocker monitorLocker(interface->monitor_lock);
762 = interface->monitor_funcs.GetIterator();
766 atomic_add(&interface->monitor_count, -1);
795 net_device_interface* interface = find_device_interface(device->name);
796 if (interface == NULL)
798 if (interface->busy)
801 // Acquire a reference to the device interface being removed
803 atomic_add(&interface->ref_count, 1);
804 interface->busy = true;
809 interface_removed_device_interface(interface);
810 notify_device_monitors(interface, B_DEVICE_BEING_REMOVED);
814 RecursiveLocker monitorLocker(interface->monitor_lock);
815 interface->monitor_funcs.RemoveAll();
822 put_device_interface(interface);
831 net_device_interface* interface = get_device_interface(device->index);
832 if (interface == NULL)
835 status_t status = interface->deframe_func(interface->device, buffer);
841 status = fifo_enqueue_buffer(&interface->receive_queue, buffer);
843 put_device_interface(interface);
861 "Dump the given network device interface");