⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vm_semaphore_win32.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
字号:
/*////                  INTEL CORPORATION PROPRIETARY INFORMATION//     This software is supplied under the terms of a license agreement or//     nondisclosure agreement with Intel Corporation and may not be copied//     or disclosed except in accordance with the terms of that agreement.//       Copyright(c) 2003-2005 Intel Corporation. All Rights Reserved.//*/#if defined(_WIN32) || defined(_WIN64) || defined(_WIN32_WCE)#include "vm_semaphore.h"/* Invalidate a semaphore */void vm_semaphore_set_invalid(vm_semaphore *sem){    /* check error(s) */    if (NULL == sem)        return;    sem->handle = NULL;} /* void vm_semaphore_set_invalid(vm_semaphore *sem) *//* Verify if a semaphore is valid */int vm_semaphore_is_valid(vm_semaphore *sem){    /* check error(s) */    if (NULL == sem)        return 0;    return (int)(0 != sem->handle);} /* int vm_semaphore_is_valid(vm_semaphore *sem) *//* Init a semaphore with value */vm_status vm_semaphore_init(vm_semaphore *sem, int init_count){    /* check error(s) */    if (NULL == sem)        return VM_NULL_PTR;    sem->handle = CreateSemaphore(NULL, init_count, 2147483647L, 0);    return (0 != sem->handle) ? VM_OK : VM_OPERATION_FAILED;} /* vm_status vm_semaphore_init(vm_semaphore *sem, int init_count) *//* Decrease the semaphore value with blocking. */vm_status vm_semaphore_timedwait(vm_semaphore *sem, unsigned int msec){    vm_status umcRes = VM_NOT_INITIALIZED;    /* check error(s) */    if (NULL == sem)        return VM_NULL_PTR;    if (sem->handle)    {        DWORD dwRes = WaitForSingleObject(sem->handle, msec);        umcRes = VM_OK;        if (WAIT_TIMEOUT == dwRes)            umcRes = VM_TIMEOUT;        else if (WAIT_OBJECT_0 != dwRes)            umcRes = VM_OPERATION_FAILED;    }    return umcRes;} /* vm_status vm_semaphore_timedwait(vm_semaphore *sem, unsigned int msec) *//* Decrease the semaphore value with blocking. */vm_status vm_semaphore_wait(vm_semaphore *sem){    vm_status umcRes = VM_NOT_INITIALIZED;    /* check error(s) */    if (NULL == sem)        return VM_NULL_PTR;    if (sem->handle)    {        DWORD dwRes = WaitForSingleObject(sem->handle, INFINITE);        umcRes = VM_OK;        if (WAIT_OBJECT_0 != dwRes)            umcRes = VM_OPERATION_FAILED;    }    return umcRes;} /* vm_status vm_semaphore_wait(vm_semaphore *sem) *//* Decrease the semaphore value without blocking, return 1 if success */vm_status vm_semaphore_try_wait(vm_semaphore *sem){    /* check error(s) */    if (NULL == sem)        return VM_NULL_PTR;    return vm_semaphore_timedwait(sem, 0);} /* vm_status vm_semaphore_try_wait(vm_semaphore *sem) *//* Increase the semaphore value */vm_status vm_semaphore_post(vm_semaphore *sem){    vm_status umcRes = VM_NOT_INITIALIZED;    /* check error(s) */    if (NULL == sem)        return VM_NULL_PTR;    if (sem->handle)    {        if (ReleaseSemaphore(sem->handle, 1, 0))            umcRes = VM_OK;        else            umcRes = VM_OPERATION_FAILED;    }    return umcRes;} /* vm_status vm_semaphore_post(vm_semaphore *sem) *//* Destory a semaphore */void vm_semaphore_destroy(vm_semaphore *sem){    /* check error(s) */    if (NULL == sem)        return;    if (sem->handle)    {        CloseHandle(sem->handle);        sem->handle = NULL;    }} /* void vm_semaphore_destroy(vm_semaphore *sem) */#endif /* defined(_WIN32) || defined(_WIN64) || defined(_WIN32_WCE) */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -