summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-26 13:18:15 +0900
committerdaniel <danieruru@gmail.com>2013-01-26 13:18:15 +0900
commita5092f136b26ece81ee0d2005fc86cdd802ae8ba (patch)
tree6c435ff9dc168ff550f3aad866e92f1c413f7aac
parent35b28230e17a68db48f3b5fc91d2eec0c80e048c (diff)
move locking bits around and free the lock if the link destroyed
-rw-r--r--vxi11_server.c90
1 files changed, 48 insertions, 42 deletions
diff --git a/vxi11_server.c b/vxi11_server.c
index 4185542..1bf7889 100644
--- a/vxi11_server.c
+++ b/vxi11_server.c
@@ -53,6 +53,8 @@ typedef struct {
static ActiveLink* links[MAX_SESSIONS] = { NULL };
+static void freelink(ActiveLink* link);
+
static void touchlink(int lid) {
g_get_current_time(&(links[lid]->lastactivity));
}
@@ -67,29 +69,6 @@ static bool isValidLink(int linkid) {
return links[linkid] != NULL;
}
-static void freelink(ActiveLink* link) {
- links[link->lid] = NULL;
- globals.Remote.vxi_connections--;
-#ifdef DEBUG
- printf("link %d destroyed, %d active links\n", link->lid, globals.Remote.vxi_connections);
-#endif
- g_free(link);
-}
-
-void vxi11_deadsocketcallback(int socket) {
- int linkid;
- for (linkid = 0; linkid < SIZEOFARRAY(links); linkid++) {
- if (links[linkid] != NULL) {
- if (links[linkid]->sock == socket) {
-#ifdef DEBUG
- printf("Freeing link %d, socket died\n", linkid);
-#endif
- freelink(links[linkid]);
- }
- }
- }
-}
-
// test if a link has expired, this is to avoid dead locks
static bool linkexpired(ActiveLink* link) {
GTimeVal cutoff;
@@ -106,6 +85,20 @@ static bool linkexpired(ActiveLink* link) {
return false;
}
+// locking wrappers
+
+static void lock(int lid) {
+ globals.VxiLocks.locked_network_server = lid;
+}
+
+static void unlock() {
+ globals.VxiLocks.locked_network_server = NO_SERVER_LOCKED;
+}
+
+static bool haveLock(int lid) {
+ return globals.VxiLocks.locked_network_server == lid;
+}
+
static bool isLocked() {
if (globals.VxiLocks.locked_network_server == NO_SERVER_LOCKED)
return false;
@@ -115,10 +108,6 @@ static bool isLocked() {
}
}
-static bool haveLock(int lid) {
- return globals.VxiLocks.locked_network_server == lid;
-}
-
#define FLAG_WAITLOCK 1
// todo
@@ -128,6 +117,38 @@ static bool waitForLock(Device_Flags flags, long timeout) {
return false;
}
+//
+
+static void freelink(ActiveLink* link) {
+ links[link->lid] = NULL;
+ globals.Remote.vxi_connections--;
+#ifdef DEBUG
+ printf("link %d destroyed, %d active links\n", link->lid, globals.Remote.vxi_connections);
+#endif
+
+ if (haveLock(link->lid)) {
+#ifdef DEBUG
+ printf("destroyed link was holding a lock, freeing it\n");
+#endif
+ unlock();
+ }
+ g_free(link);
+}
+
+void vxi11_deadsocketcallback(int socket) {
+ int linkid;
+ for (linkid = 0; linkid < SIZEOFARRAY(links); linkid++) {
+ if (links[linkid] != NULL) {
+ if (links[linkid]->sock == socket) {
+#ifdef DEBUG
+ printf("Freeing link %d, socket died\n", linkid);
+#endif
+ freelink(links[linkid]);
+ }
+ }
+ }
+}
+
static bool waitforio(long timeout) {
do {
if (!globals.VxiLocks.command_in_progress)
@@ -141,14 +162,6 @@ static bool waitforio(long timeout) {
return false;
}
-static void lock(int lid) {
- globals.VxiLocks.locked_network_server = lid;
-}
-
-static void unlock() {
- globals.VxiLocks.locked_network_server = NO_SERVER_LOCKED;
-}
-
Device_Error *
device_abort_1_svc(Device_Link *argp, struct svc_req *rqstp) {
static Device_Error result;
@@ -485,13 +498,6 @@ destroy_link_1_svc(Device_Link *argp, struct svc_req *rqstp) {
if (!isValidLink(lid))
result.error = ERR_INVALIDLINKINDENTIFIER;
else {
- if (haveLock(*argp)) {
-#ifdef DEBUG
- printf("Disconnecting client was holding a lock, freeing it\n");
-#endif
- unlock();
- }
-
freelink(links[lid]);
result.error = 0;
}