コード例 #1
0
ファイル: THAllocator.c プロジェクト: Northrend/pytorch
static void THRefcountedMapAllocator_free(void* ctx_, void* data) {
  THMapAllocatorContext *ctx = ctx_;

#ifdef _WIN32
  THMapInfo *info = (THMapInfo*)(((char*)data) - TH_ALLOC_ALIGNMENT);
  if (THAtomicDecrementRef(&info->refcount)) {
    CloseHandle(ctx->handle);
  }
  if(UnmapViewOfFile(data) == 0)
    THError("could not unmap the shared memory file");
#else /* _WIN32 */

  THMapInfo *info = (THMapInfo*)(((char*)data) - TH_ALLOC_ALIGNMENT);
  if (THAtomicDecrementRef(&info->refcount)) {
#ifdef HAVE_SHM_UNLINK
    if (shm_unlink(ctx->filename) == -1)
      THError("could not unlink the shared memory file %s", ctx->filename);
#else
    THError("could not unlink the shared memory file %s, shm_unlink not available on platform", ctx->filename);
#endif /* HAVE_SHM_UNLINK */
  }
  if (munmap(info, ctx->size))
    THError("could not unmap the shared memory file %s", ctx->filename);
#endif /* _WIN32 */

  THMapAllocatorContext_free(ctx);
}
コード例 #2
0
ファイル: THCStream.cpp プロジェクト: Jsmilemsj/pytorch
void THCStream_free(THCStream* self)
{
  if (!self || !self->stream) {
    return;
  }
  if (THAtomicDecrementRef(&self->refcount)) {
    THCudaCheckWarn(cudaStreamDestroy(self->stream));
    free(self);
  }
}
コード例 #3
0
ファイル: tds_vec.c プロジェクト: elikosan/tds
void tds_vec_free(tds_vec* vec)
{
  size_t k;
#if HAS_TORCH
  if(THAtomicDecrementRef(&vec->refcount))
#else
  vec->refcount--;
  if(vec->refcount == 0)
#endif
  {
    for(k = 0; k < vec->n; k++)
      tds_elem_free_content(&vec->data[k]);
    tds_free(vec->data);
    tds_free(vec);
  }
}
コード例 #4
0
ファイル: THCTensor.c プロジェクト: cc272309126/cutorch
void THCudaTensor_free(THCState *state, THCudaTensor *self)
{
  if(!self)
    return;

  if(self->flag & TH_TENSOR_REFCOUNTED)
  {
    if(THAtomicDecrementRef(&self->refcount))
    {
      THFree(self->size);
      THFree(self->stride);
      if(self->storage)
        THCudaStorage_free(state, self->storage);
      THFree(self);
    }
  }
}
コード例 #5
0
ファイル: queue.c プロジェクト: liyonglion/threads
static int queue_free(lua_State *L)
{
  THQueue *queue = luaTHRD_checkudata(L, 1, "threads.Queue");
  if(THAtomicDecrementRef(&queue->refcount))
  {
    int i;
    THMutex_free(queue->mutex);
    THCondition_free(queue->notfull);
    THCondition_free(queue->notempty);
    for(i = 0; i < queue->size; i++) {
      if(queue->callbacks[i])
        THCharStorage_free(queue->callbacks[i]);
      if(queue->args[i])
        THCharStorage_free(queue->args[i]);
    }
    free(queue->serialize);
    free(queue->callbacks);
    free(queue->args);
    free(queue);
  }
  return 0;
}
コード例 #6
0
ファイル: THAllocator.c プロジェクト: Northrend/pytorch
int THRefcountedMapAllocator_decref(THMapAllocatorContext *ctx, void *data)
{
  THMapInfo *map_info = (THMapInfo*)(((char*)data) - TH_ALLOC_ALIGNMENT);
  return THAtomicDecrementRef(&map_info->refcount);
}