jmuehlner commented on code in PR #455:
URL: https://github.com/apache/guacamole-server/pull/455#discussion_r1303541251


##########
src/libguac/local-lock.h:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __GUAC_LOCAL_LOCK_H
+#define __GUAC_LOCAL_LOCK_H
+
+#include <pthread.h>
+
+/**
+ * This file implements reentrant read-write locks using thread-local storage
+ * to keep track of how locks are held and released by the current thread,
+ * since the pthread locks do not support reentrant behavior.
+ *
+ * A thread will attempt to acquire the requested lock on the first acquire
+ * function call, and will release it once the number of unlock requests
+ * matches the number of lock requests. Therefore, it is safe to aquire a lock
+ * and then call a function that also acquires the same lock, provided that
+ * the caller and the callee request to unlock the lock when done with it.
+ *
+ * Any lock that's locked using one of the functions defined in this file
+ * must _only_ be unlocked using the unlock function defined here to avoid
+ * unexpected behavior.
+ */
+
+/**
+ * A structure packaging together a pthread rwlock along with a key to a
+ * thread-local property to keep track of the current status of the lock,
+ * allowing the functions defined in this header to provide reentrant behavior.
+ * Note that both the lock and key must be initialized before being provided
+ * to any of these functions.
+ */
+typedef struct guac_local_lock {

Review Comment:
   Yeah, the name definitely needs cleanup. Will do.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to