From 7b83e8b24c942f98a6ae285ecd6772afe21cae12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 4 Mar 2004 20:43:13 +0000 Subject: [PATCH] Made find_port() less heavy; it no longer disables interrupts for the whole run. Also create_port() now changes the port ID only when the port lock is grabbed, so that we don't need to acquire the port list lock in find_port(). Removed setting lock to "0" in create_port() because if it's not 0 in the first place, there is something seriously wrong (should add an assert there). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6897 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/port.c | 47 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/kernel/core/port.c b/src/kernel/core/port.c index e99ff7dbd3..e78c90fdd9 100644 --- a/src/kernel/core/port.c +++ b/src/kernel/core/port.c @@ -237,16 +237,15 @@ create_port(int32 queue_length, const char *name) // find the first empty spot for (i = 0; i < MAX_PORTS; i++) { - if(gPorts[i].id == -1) { + if (gPorts[i].id == -1) { // make the port_id be a multiple of the slot it's in - if(i >= gNextPort % MAX_PORTS) { + if (i >= gNextPort % MAX_PORTS) gNextPort += i - gNextPort % MAX_PORTS; - } else { + else gNextPort += MAX_PORTS - (gNextPort % MAX_PORTS - i); - } - gPorts[i].id = gNextPort++; - gPorts[i].lock = 0; + GRAB_PORT_LOCK(gPorts[i]); + gPorts[i].id = gNextPort++; RELEASE_PORT_LIST_LOCK(); gPorts[i].capacity = queue_length; @@ -376,37 +375,35 @@ delete_port(port_id id) port_id -find_port(const char *port_name) +find_port(const char *name) { + port_id portFound = B_BAD_PORT_ID; + cpu_status state; int i; - int state; - int ret_val = B_BAD_PORT_ID; if (ports_active == false) return B_BAD_PORT_ID; - if (port_name == NULL) + if (name == NULL) return B_BAD_PORT_ID; - // lock list of gPorts - state = disable_interrupts(); - GRAB_PORT_LIST_LOCK(); + // Since we have to check every single port, and we don't + // care if it goes away at any point, we're only grabbing + // the port lock in question, not the port list lock // loop over list - for (i = 0; i < MAX_PORTS; i++) { + for (i = 0; i < MAX_PORTS && portFound < B_OK; i++) { // lock every individual port before comparing + state = disable_interrupts(); GRAB_PORT_LOCK(gPorts[i]); - if(strcmp(port_name, gPorts[i].name) == 0) { - ret_val = gPorts[i].id; - RELEASE_PORT_LOCK(gPorts[i]); - break; - } - RELEASE_PORT_LOCK(gPorts[i]); - } - - RELEASE_PORT_LIST_LOCK(); - restore_interrupts(state); - return ret_val; + if (gPorts[i].id >= 0 && !strcmp(name, gPorts[i].name)) + portFound = gPorts[i].id; + + RELEASE_PORT_LOCK(gPorts[i]); + restore_interrupts(state); + } + + return portFound; }