github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/lock.h (about)

     1  /*
     2   * Copyright (c) 2013 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *     http://www.apache.org/licenses/LICENSE-2.0
     8   * Unless required by applicable law or agreed to in writing, software
     9   * distributed under the License is distributed on an "AS IS" BASIS,
    10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11   * See the License for the specific language governing permissions and
    12   * limitations under the License.
    13   */
    14  
    15  #ifndef _UVMM_LOCK_H_
    16  #define _UVMM_LOCK_H_
    17  
    18  #include "vmm_defs.h"
    19  #include "hw_interlocked.h"
    20  #include "vmm_dbg.h"
    21  
    22  
    23  typedef struct _VMM_LOCK {
    24      volatile UINT32 uint32_lock;
    25      volatile CPU_ID owner_cpu_id;
    26      char padding[2];
    27  } VMM_LOCK;
    28  
    29  #define LOCK_INIT_STATE     {(UINT32) 0, (CPU_ID) -1, {0}}
    30  
    31  
    32  // Read/Write lock
    33  //
    34  // multiple readers can read the data in parallel but an exclusive lock is
    35  // needed while writing the data. When a writer is writing the data, readers
    36  // will be blocked until the writer has finished writing
    37  
    38  typedef struct _VMM_READ_WRITE_LOCK {
    39      VMM_LOCK        lock;
    40      UINT32          padding;
    41      volatile INT32  readers;
    42  } VMM_READ_WRITE_LOCK;
    43  
    44  
    45  //
    46  // Various locking routines
    47  void
    48  lock_acquire(    VMM_LOCK* lock );
    49  
    50  void
    51  interruptible_lock_acquire(    VMM_LOCK* lock );
    52  
    53  void
    54  lock_release(    VMM_LOCK* lock );
    55  
    56  void
    57  lock_initialize(  VMM_LOCK* lock );
    58  
    59  #ifdef DEBUG
    60  void
    61  lock_print(    VMM_LOCK* lock );
    62  #endif
    63  
    64  void
    65  lock_initialize_read_write_lock( VMM_READ_WRITE_LOCK * lock );
    66  
    67  void
    68  lock_acquire_readlock( VMM_READ_WRITE_LOCK * lock );
    69  
    70  void
    71  interruptible_lock_acquire_readlock( VMM_READ_WRITE_LOCK * lock );
    72  
    73  void
    74  lock_release_readlock( VMM_READ_WRITE_LOCK * lock );
    75  
    76  void
    77  lock_acquire_writelock( VMM_READ_WRITE_LOCK * lock );
    78  
    79  void
    80  interruptible_lock_acquire_writelock( VMM_READ_WRITE_LOCK * lock );
    81  
    82  void
    83  lock_release_writelock( VMM_READ_WRITE_LOCK * lock );
    84  
    85  
    86  #endif // _UVMM_LOCK_H_
    87  
    88