]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/devlock.c
First cut of bat rerun a Job from Jobs Run
[bacula/bacula] / bacula / src / lib / devlock.c
index 2d36c6b86f4d99ae06dcb9274948bdfbbf7aa988..c2e1291e5bda5958aa187576103d39d1c7f71016 100644 (file)
@@ -6,7 +6,7 @@
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -240,7 +240,7 @@ int devlock::readunlock()
  * Lock for write access, wait until locked (or error).
  *   Multiple nested write locking is permitted.
  */
-int devlock::writelock(int areason, bool acan_steal)
+int devlock::writelock(int areason, bool acan_take)
 {
    devlock *rwl = this;
    int stat;
@@ -275,7 +275,7 @@ int devlock::writelock(int areason, bool acan_steal)
       lmgr_post_lock();
    } 
    rwl->reason = areason;
-   rwl->can_steal = acan_steal;
+   rwl->can_take = acan_take;
    pthread_mutex_unlock(&rwl->mutex);
    return stat;
 }
@@ -349,6 +349,47 @@ int devlock::writeunlock()
    return (stat == 0 ? stat2 : stat);
 }
 
+int devlock::take_lock(take_lock_t *hold, int areason)
+{
+   int stat;
+
+   if (valid != DEVLOCK_VALID) {
+      return EINVAL;
+   }
+   if ((stat = pthread_mutex_lock(&mutex)) != 0) {
+      return stat;
+   }
+   hold->reason = reason;
+   hold->prev_reason = prev_reason;
+   hold->writer_id = writer_id;
+   reason = areason;
+   writer_id = pthread_self();
+   stat = pthread_mutex_unlock(&mutex);
+   return stat;
+}
+
+int devlock::return_lock(take_lock_t *hold)
+{
+   int stat, stat2;
+
+   if (valid != DEVLOCK_VALID) {
+      return EINVAL;
+   }
+   if ((stat = pthread_mutex_lock(&mutex)) != 0) {
+      return stat;
+   }
+   reason = hold->reason;
+   prev_reason = hold->prev_reason;
+   writer_id = hold->writer_id;
+   writer_id = pthread_self();
+   stat2 = pthread_mutex_unlock(&mutex);
+   if (w_active || w_wait) {
+      stat = pthread_cond_broadcast(&write);
+   }
+   return (stat == 0 ? stat2 : stat);
+
+}
+
 #ifdef TEST_RWLOCK
 
 #define THREADS     300