github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/ppapi/resource_nacl.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ppapi
     6  
     7  // Resource represents a generic NaCl reference of some kind.  You won't normally
     8  // use Resource directly, you will use one of the specific resources, like FileIO,
     9  // InputEvent, or others.
    10  //
    11  // The Resource type is defined to support generic operations on all Resources,
    12  // including manipulating the reference counts.
    13  type Resource struct {
    14  	id pp_Resource
    15  }
    16  
    17  func makeResource(id pp_Resource) Resource {
    18  	return Resource{id: id}
    19  }
    20  
    21  // IsNull returns true iff the resource is NULL.
    22  func (r Resource) IsNull() bool {
    23  	return r.id == 0
    24  }
    25  
    26  // IsValid returns true iff the resource is not NULL.
    27  func (r Resource) IsValid() bool {
    28  	return r.id != 0
    29  }
    30  
    31  // AddRef increments the Resource's reference count.
    32  func (r Resource) AddRef() {
    33  	ppb_core_add_ref_resource(r.id)
    34  }
    35  
    36  // Release decrements the Resource's reference count.  Deletes the Resource if
    37  // the resulting count is zero.
    38  func (r *Resource) Release() {
    39  	if r.id != 0 {
    40  		ppb_core_release_resource(r.id)
    41  		r.id = 0
    42  	}
    43  }