• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ LockFileEx函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中LockFileEx函数的典型用法代码示例。如果您正苦于以下问题:C++ LockFileEx函数的具体用法?C++ LockFileEx怎么用?C++ LockFileEx使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了LockFileEx函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: flock

int flock(int fd, int op)
{
	HANDLE hdl = (HANDLE) _get_osfhandle(fd);
	DWORD low = 1, high = 0;
	OVERLAPPED offset =
	{0, 0, 0, 0, NULL};
	if (hdl < 0)
		return -1;				/* error in file descriptor */
	/* bug for bug compatible with Unix */
	UnlockFileEx(hdl, 0, low, high, &offset);
	switch (op & ~LOCK_NB) {	/* translate to LockFileEx() op */
		case LOCK_EX:			/* exclusive */
			if (LockFileEx(hdl, LOCKFILE_EXCLUSIVE_LOCK +
						((op & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0),
						   0, low, high, &offset))
				return 0;
			break;
		case LOCK_SH:			/* shared */
			if (LockFileEx(hdl, ((op & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0),
						   0, low, high, &offset))
				return 0;
			break;
		case LOCK_UN:			/* unlock */
			return 0;			/* always succeeds */
		default:				/* default */
			break;
	}
	errno = EINVAL;				/* bad call */
	return -1;
}
开发者ID:AzerTyQsdF,项目名称:osx,代码行数:30,代码来源:flock.c


示例2: flock

int flock(int fd, int oper) {
    OVERLAPPED o;
    int i = -1;
    HANDLE fh;

    fh = (HANDLE)_get_osfhandle(fd);
    memset(&o, 0, sizeof(o));

    switch(oper) {
		case LOCK_SH:		/* shared lock */
			LK_ERR(LockFileEx(fh, 0, 0, LK_LEN, 0, &o),i);
		break;
		case LOCK_EX:		/* exclusive lock */
			LK_ERR(LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o),i);
		break;
		case LOCK_SH|LOCK_NB:	/* non-blocking shared lock */
			LK_ERR(LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o),i);
		break;
		case LOCK_EX|LOCK_NB:	/* non-blocking exclusive lock */
			LK_ERR(LockFileEx(fh,LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,0, LK_LEN, 0, &o),i);
		break;
		case LOCK_UN:		/* unlock lock */
			LK_ERR(UnlockFileEx(fh, 0, LK_LEN, 0, &o),i);
		break;
		default:			/* unknown */
			//errno = EINVAL; // i heard that on some versions errno is a function (win32 MT lib?)
		break;
    }
    return i;
}
开发者ID:96Levels,项目名称:roadsend-php,代码行数:30,代码来源:flock.c


示例3: acl_myflock

/* use LockFileEx/UnlockFileEx */
int acl_myflock(ACL_FILE_HANDLE fd, int lock_style acl_unused, int operation)
{
	const char *myname = "acl_myflock";
	DWORD size = 0xFFFFFFFF;
	char  ebuf[256];
	unsigned char lock_op;
	OVERLAPPED ovlp;
	DWORD flags;

	if ((operation & (ACL_FLOCK_OP_BITS)) != operation)
		acl_msg_panic("myflock: improper operation type: 0x%x", operation);

	memset(&ovlp, 0, sizeof(ovlp));

	ovlp.Offset = 0;
	lock_op = operation & ~ACL_FLOCK_OP_NOWAIT;
	if (lock_op == ACL_FLOCK_OP_NONE) {
		if(UnlockFileEx(fd, 0, 1, 0, &ovlp))
			return (0);
		acl_msg_error("%s(%d): unlock error(%s)",
			myname, __LINE__, acl_last_strerror(ebuf,sizeof(ebuf)));
		return (-1);
	} else if (lock_op == ACL_FLOCK_OP_SHARED) {
		while (1) {
			flags = 0;
			if ((operation & ACL_FLOCK_OP_NOWAIT))
				flags |= LOCKFILE_FAIL_IMMEDIATELY;

			if(LockFileEx(fd, flags, 0, 1, 0, &ovlp))
				return (0);
			if ((operation & ACL_FLOCK_OP_NOWAIT)) {
				acl_msg_error("%s(%d): lock error(%s)", myname, __LINE__,
					acl_last_strerror(ebuf,sizeof(ebuf)));
				return (-1);
			}
			sleep(1);
		}
	} else if (lock_op == ACL_FLOCK_OP_EXCLUSIVE) {
		while (1) {
			flags = LOCKFILE_EXCLUSIVE_LOCK;
			if ((operation & ACL_FLOCK_OP_NOWAIT))
				flags |= LOCKFILE_FAIL_IMMEDIATELY;

			if(LockFileEx(fd, flags, 0, 1, 0, &ovlp))
				return (0);

			if ((operation & ACL_FLOCK_OP_NOWAIT)) {
				acl_msg_error("%s(%d): lock error(%s)", myname, __LINE__,
					acl_last_strerror(ebuf,sizeof(ebuf)));
				return (-1);
			}
			sleep(1);
		}
	}

	acl_msg_error("%s(%d): invalid lock_op(%d)", myname, __LINE__, lock_op);
	return (-1);
}
开发者ID:10jschen,项目名称:acl,代码行数:59,代码来源:acl_myflock.c


示例4: lock

/* Locks a file. */
static MVMint64 lock(MVMThreadContext *tc, MVMOSHandle *h, MVMint64 flag) {
    MVMIOFileData *data = (MVMIOFileData *)h->body.data;

#ifdef _WIN32

    const DWORD len = 0xffffffff;
    const HANDLE hf = (HANDLE)_get_osfhandle(data->fd);
    OVERLAPPED offset;

    if (hf == INVALID_HANDLE_VALUE) {
        MVM_exception_throw_adhoc(tc, "Failed to lock filehandle: bad file descriptor");
    }

    flag = ((flag & MVM_FILE_FLOCK_NONBLOCK) ? LOCKFILE_FAIL_IMMEDIATELY : 0)
          + ((flag & MVM_FILE_FLOCK_TYPEMASK) == MVM_FILE_FLOCK_SHARED
                                       ? 0 : LOCKFILE_EXCLUSIVE_LOCK);

    memset (&offset, 0, sizeof(offset));
    MVM_gc_mark_thread_blocked(tc);
    if (LockFileEx(hf, flag, 0, len, len, &offset)) {
        MVM_gc_mark_thread_unblocked(tc);
        return 1;
    }
    MVM_gc_mark_thread_unblocked(tc);

    MVM_exception_throw_adhoc(tc, "Failed to lock filehandle: %d", GetLastError());

    return 0;

#else

    struct flock l;
    ssize_t r;
    int fc;
    const int fd = data->fd;

    l.l_whence = SEEK_SET;
    l.l_start = 0;
    l.l_len = 0;

    if ((flag & MVM_FILE_FLOCK_TYPEMASK) == MVM_FILE_FLOCK_SHARED)
        l.l_type = F_RDLCK;
    else
        l.l_type = F_WRLCK;

    fc = (flag & MVM_FILE_FLOCK_NONBLOCK) ? F_SETLK : F_SETLKW;

    do {
        MVM_gc_mark_thread_blocked(tc);
        r = fcntl(fd, fc, &l);
        MVM_gc_mark_thread_unblocked(tc);
    } while (r == -1 && errno == EINTR);

    if (r == -1) {
        MVM_exception_throw_adhoc(tc, "Failed to lock filehandle: %d", errno);
    }

    return 1;
#endif
}
开发者ID:chipdude,项目名称:MoarVM,代码行数:61,代码来源:syncfile.c


示例5: _VLockFd

static_inline int
_VLockFd(FD_t handle, afs_uint32 offset, int locktype, int nonblock)
{
    DWORD flags = 0;
    OVERLAPPED lap;

    if (locktype == WRITE_LOCK) {
	flags |= LOCKFILE_EXCLUSIVE_LOCK;
    }
    if (nonblock) {
	flags |= LOCKFILE_FAIL_IMMEDIATELY;
    }

    memset(&lap, 0, sizeof(lap));
    lap.Offset = offset;

    if (!LockFileEx(handle, flags, 0, 1, 0, &lap)) {
	if (GetLastError() == ERROR_LOCK_VIOLATION) {
	    return EBUSY;
	}
	return EIO;
    }

    return 0;
}
开发者ID:jblaine,项目名称:openafs,代码行数:25,代码来源:vutil.c


示例6: memset

void FileStream::lock(bool nb)
{
 if(locked)
  return;

 #ifdef WIN32
 OVERLAPPED olp;

 memset(&olp, 0, sizeof(OVERLAPPED));
 olp.Offset = ~(DWORD)0;
 olp.OffsetHigh = ~(DWORD)0;
 if(!LockFileEx((HANDLE)_get_osfhandle(fileno(fp)), LOCKFILE_EXCLUSIVE_LOCK | (nb ? LOCKFILE_FAIL_IMMEDIATELY : 0), 0, 1, 0, &olp))
 {
  const uint32 ec = GetLastError();

  throw MDFN_Error((ec == ERROR_LOCK_VIOLATION) ? EWOULDBLOCK : 0, _("Error locking opened file \"%s\": %s"), path_save.c_str(), Win32Common::ErrCodeToString(ec).c_str());
 }
 #else
 if(flock(fileno(fp), LOCK_EX | (nb ? LOCK_NB : 0)) == -1)
 {
  ErrnoHolder ene(errno);

  throw MDFN_Error(ene.Errno(), _("Error locking opened file \"%s\": %s"), path_save.c_str(), ene.StrError());
 } 
 #endif

 locked = true;
}
开发者ID:libretro,项目名称:mednafen-git,代码行数:28,代码来源:FileStream.cpp


示例7: CreateFile

AutoFileLock::AutoFileLock(const char* fileName)
{
   // Repeat createFile, if there is a sharing violation.
   do
   {
       _hFile = CreateFile (fileName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
           OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
   }while ((GetLastError() == ERROR_SHARING_VIOLATION));

   // If this conditon succeeds, There is an error opening the file. Hence
   // returning from here  as Lock can not be acquired.
   if((_hFile == INVALID_HANDLE_VALUE)
       && (GetLastError() != ERROR_ALREADY_EXISTS)
       && (GetLastError() != ERROR_SUCCESS))
   {
       PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
          "AutoFileLock: Failed to open lock file '%s', error code %d.",
          fileName, GetLastError()));
       return;
   }

   OVERLAPPED l={0,0,0,0,0};
   if(LockFileEx(_hFile,LOCKFILE_EXCLUSIVE_LOCK, 0, 0, 0, &l) == 0)
   {
       PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
           "AutoFileLock: Failed to Acquire lock on file %s, error code %d.",
           fileName, GetLastError()));
       CloseHandle(_hFile);
       _hFile = INVALID_HANDLE_VALUE;
   }
}
开发者ID:brunolauze,项目名称:pegasus,代码行数:31,代码来源:SystemWindows.cpp


示例8: time

void CJaxerLog::LogStr(eLogLevel eLevel, const char* pszStr, int len)
{
    if (eLevel < m_eDefault)
        return;

    if (!m_fp)
        return;

    time_t rawtime;
	struct tm * timeinfo;

    char szTimeBuf[0x64];

	time ( &rawtime );
	timeinfo = localtime ( &rawtime );

    sprintf(szTimeBuf,
        "%02d:%02d:%02d %02d/%02d/%04d [%s] ",
        timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec,
        timeinfo->tm_mon+1, timeinfo->tm_mday, timeinfo->tm_year+1900,
        sLogLevel[eLevel]);

    
    OVERLAPPED ovlp;
    memset(&ovlp, 0, sizeof(ovlp));
    LockFileEx(m_fp, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &ovlp);
    DWORD nBytes;
    SetFilePointer(m_fp, 0, 0, FILE_END);
    WriteFile(m_fp, szTimeBuf, (DWORD)strlen(szTimeBuf), &nBytes, NULL);
    WriteFile(m_fp, pszStr, (len==-1)? (DWORD)strlen(pszStr) : len, &nBytes, NULL);
    WriteFile(m_fp, "\r\n", 2, &nBytes, NULL);
    UnlockFileEx(m_fp, 0, 1, 0, &ovlp);
}
开发者ID:absynce,项目名称:Jaxer,代码行数:33,代码来源:jaxer_log.cpp


示例9: RTR3DECL

RTR3DECL(int)  RTFileLock(RTFILE hFile, unsigned fLock, int64_t offLock, uint64_t cbLock)
{
    Assert(offLock >= 0);

    /* Check arguments. */
    if (fLock & ~RTFILE_LOCK_MASK)
    {
        AssertMsgFailed(("Invalid fLock=%08X\n", fLock));
        return VERR_INVALID_PARAMETER;
    }

    /* Prepare flags. */
    Assert(RTFILE_LOCK_WRITE);
    DWORD dwFlags = (fLock & RTFILE_LOCK_WRITE) ? LOCKFILE_EXCLUSIVE_LOCK : 0;
    Assert(RTFILE_LOCK_WAIT);
    if (!(fLock & RTFILE_LOCK_WAIT))
        dwFlags |= LOCKFILE_FAIL_IMMEDIATELY;

    /* Windows structure. */
    OVERLAPPED Overlapped;
    memset(&Overlapped, 0, sizeof(Overlapped));
    Overlapped.Offset = LOW_DWORD(offLock);
    Overlapped.OffsetHigh = HIGH_DWORD(offLock);

    /* Note: according to Microsoft, LockFileEx API call is available starting from NT 3.5 */
    if (LockFileEx((HANDLE)RTFileToNative(hFile), dwFlags, 0, LOW_DWORD(cbLock), HIGH_DWORD(cbLock), &Overlapped))
        return VINF_SUCCESS;

    return RTErrConvertFromWin32(GetLastError());
}
开发者ID:sobomax,项目名称:virtualbox_64bit_edd,代码行数:30,代码来源:fileio-win.cpp


示例10: file_lock

static int file_lock(lua_State *L,
                     FILE *f, const char *mode, long offset, long length)
{
  static const ULARGE_INTEGER zero_len;
  static const OVERLAPPED zero_ov;
  HANDLE h = file_handle(f);
  ULARGE_INTEGER len = zero_len;
  OVERLAPPED ov = zero_ov;
  DWORD flags = 0;
  BOOL ret;
  if (length) len.LowPart = length;
  else len.LowPart = len.HighPart = -1;
  ov.Offset = offset;
  switch (*mode) {
    case 'w':
      flags = LOCKFILE_EXCLUSIVE_LOCK;
      /*FALLTHRU*/
    case 'r':
      flags |= LOCKFILE_FAIL_IMMEDIATELY;
      ret = LockFileEx(h, flags, 0, len.LowPart, len.HighPart, &ov);
      break;
    case 'u':
      ret = UnlockFileEx(h, 0, len.LowPart, len.HighPart, &ov);
      break;
    default:
      return luaL_error(L, "invalid mode");
  }
  if (!ret)
    return push_error(L);
  /* return the file */
  lua_settop(L, 1);
  return 1;
}
开发者ID:ClowReed32,项目名称:Cthugha-Engine-Demos,代码行数:33,代码来源:ex.c


示例11: lock_out

static int
lock_out(HANDLE hFile , int op)
{
	DWORD dwNumBytesWritten;
	BOOL fSuccess;
	OVERLAPPED sOverlapped;
	char buf[PBS_MAXHOSTNAME + 10];

	if (op == F_WRLCK) {
		sOverlapped.Offset = 0;
		sOverlapped.OffsetHigh = 100;
		sOverlapped.hEvent = 0;

		fSuccess = LockFileEx(hFile,
			LOCKFILE_EXCLUSIVE_LOCK |
			LOCKFILE_FAIL_IMMEDIATELY,
			0, 0, 1000, &sOverlapped);
		if (fSuccess) {
			/* if write-lock, record hostname and pid in file */
			(void) sprintf(buf, "%s:%d\n", thishost, getpid());
			fSuccess = WriteFile(hFile,
				buf,
				strlen(buf),
				&dwNumBytesWritten,
				NULL);
			return 0;
		}
	} else {
		/* unlock and return */
		fSuccess = UnlockFileEx(hFile, 0, 0, 1000, &sOverlapped);
		if (fSuccess)
			return 0;
	}
	return 1;
}
开发者ID:altair4,项目名称:pbspro,代码行数:35,代码来源:pbs_ds_monitor.c


示例12: pgut_flock

int
pgut_flock(int fd, int operation)
{
	BOOL	ret;
	HANDLE	handle = (HANDLE) _get_osfhandle(fd);
	DWORD	lo = 0;
	DWORD	hi = 0;

	if (operation & LOCK_UN)
	{
		ret = UnlockFileEx(handle, 0, lo, hi, NULL);
	}
	else
	{
		DWORD	flags = 0;
		if (operation & LOCK_EX)
			flags |= LOCKFILE_EXCLUSIVE_LOCK;
		if (operation & LOCK_NB)
			flags |= LOCKFILE_FAIL_IMMEDIATELY;
		ret = LockFileEx(handle, flags, 0, lo, hi, NULL);
	}

	if (!ret)
	{
		_dosmaperr(GetLastError());
		return -1;
	}

	return 0;
}
开发者ID:stalkerg,项目名称:pg_arman,代码行数:30,代码来源:pgut-port.c


示例13: flock

int flock (int fd,int op)
{
  HANDLE hdl = (HANDLE) _get_osfhandle (fd);
  DWORD flags = (op & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0;
  OVERLAPPED offset = {NIL,NIL,0,0,NIL};
  int ret = -1;
  blocknotify_t bn = (blocknotify_t) 
    ((op & LOCK_NB) ? NIL : mail_parameters (NIL,GET_BLOCKNOTIFY,NIL));
  if (hdl < 0) errno = EBADF;	/* error in file descriptor */
  else switch (op & ~LOCK_NB) {	/* translate to LockFileEx() op */
  case LOCK_EX:			/* exclusive */
    flags |= LOCKFILE_EXCLUSIVE_LOCK;
  case LOCK_SH:			/* shared */
    if (!check_nt ()) return 0;	/* always succeeds if not NT */
    if (bn) (*bn) (BLOCK_FILELOCK,NIL);
				/* bug for bug compatible with Unix */
    UnlockFileEx (hdl,NIL,1,0,&offset);
				/* lock the file as requested */
    if (LockFileEx (hdl,flags,NIL,1,0,&offset)) ret = 0;
    if (bn) (*bn) (BLOCK_NONE,NIL);
				/* if failed */
    if (ret) errno = (op & LOCK_NB) ? EAGAIN : EBADF;
    break;
  case LOCK_UN:			/* unlock */
    if (check_nt ()) UnlockFileEx (hdl,NIL,1,0,&offset);
    ret = 0;			/* always succeeds */
  default:			/* default */
    errno = EINVAL;		/* bad call */
    break;
  }
  return ret;
}
开发者ID:Distrotech,项目名称:pine,代码行数:32,代码来源:yunchan.c


示例14: fopen

static FILE *diskcache_openLockedFile(const char *path, int write) {
    FILE *f;
    if (!file_doesFileExist(path)) {
        // if we don't want to write, this means failure.
        if (!write) {
            return 0;
        }

        // create file.
        f = fopen(path, "wb");
        if (!f) {
            return 0;
        }
    } else {
        if (write) {
            // open up file in append mode for writing
            f = fopen(path, "ab");
        } else {
            // .. otherwise in read mode
            f = fopen(path, "rb");
        }
        if (!f) {
            return 0;
        }
    }
#ifdef UNIX
#ifndef MAC
    // for non-Mac OS X Unix (Linux/BSD), we use flock
    int operation = LOCK_SH;
    if (write) {
        operation = LOCK_EX;
    }
    if (flock(fileno(f), operation) == 0) {
        return f;
    }
    fclose(f);
    return 0;
#else
    // for Mac OS X, we currently use nothing!
    return f;
#endif
#else
    // on windows, we use LockFileEx
    HANDLE h = (HANDLE)_get_osfhandle(fileno(f));
    int flags = 0;
    if (write) {
        flags |= LOCKFILE_EXCLUSIVE_LOCK;
    }
    OVERLAPPED ov;
    memset(&ov, 0, sizeof(ov));
    if (LockFileEx(h, flags, 0, 0, 0, &ov)) {
        _close((int)h);
        return f;
    }
    _close((int)h);
    fclose(f);
    return 0;
#endif
}
开发者ID:JonasT,项目名称:Blitwizard,代码行数:59,代码来源:diskcache.c


示例15: tr_sys_file_lock

bool tr_sys_file_lock(tr_sys_file_t handle, int operation, tr_error** error)
{
    TR_ASSERT(handle != TR_BAD_SYS_FILE);
    TR_ASSERT((operation & ~(TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_EX | TR_SYS_FILE_LOCK_NB | TR_SYS_FILE_LOCK_UN)) == 0);
    TR_ASSERT(!!(operation & TR_SYS_FILE_LOCK_SH) + !!(operation & TR_SYS_FILE_LOCK_EX) +
        !!(operation & TR_SYS_FILE_LOCK_UN) == 1);

    bool ret;
    OVERLAPPED overlapped = { .Pointer = 0, .hEvent = NULL };

    if ((operation & TR_SYS_FILE_LOCK_UN) == 0)
    {
        DWORD native_flags = 0;

        if ((operation & TR_SYS_FILE_LOCK_EX) != 0)
        {
            native_flags |= LOCKFILE_EXCLUSIVE_LOCK;
        }

        if ((operation & TR_SYS_FILE_LOCK_NB) != 0)
        {
            native_flags |= LOCKFILE_FAIL_IMMEDIATELY;
        }

        ret = LockFileEx(handle, native_flags, 0, MAXDWORD, MAXDWORD, &overlapped) != FALSE;
    }
    else
    {
        ret = UnlockFileEx(handle, 0, MAXDWORD, MAXDWORD, &overlapped) != FALSE;
    }

    if (!ret)
    {
        set_system_error(error, GetLastError());
    }

    return ret;
}

char* tr_sys_dir_get_current(tr_error** error)
{
    char* ret = NULL;
    wchar_t* wide_ret = NULL;
    DWORD size;

    size = GetCurrentDirectoryW(0, NULL);

    if (size != 0)
    {
        wide_ret = tr_new(wchar_t, size);

        if (GetCurrentDirectoryW(size, wide_ret) != 0)
        {
            ret = tr_win32_native_to_utf8(wide_ret, size);
        }
    }
开发者ID:xzcvczx,项目名称:transmission,代码行数:56,代码来源:file-win32.c


示例16: memset

bool Log::LogFile::lock(void)
{
    OVERLAPPED ov;
    bool ret;

    memset(&ov, 0, sizeof (ov));
    ret = LockFileEx(fd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &ov) == TRUE;
    SetFilePointer((HANDLE)fd, 0, 0, FILE_END);
    return ret;
}
开发者ID:TaNhoSy,项目名称:zimbra-mirror,代码行数:10,代码来源:Logger.cpp


示例17: flock

static int
flock(int fd, int operation) {
  OVERLAPPED ov;
  HANDLE h = (HANDLE)_get_osfhandle(fd);
  DWORD flags;
  flags = ((operation & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0)
          | ((operation & LOCK_SH) ? LOCKFILE_EXCLUSIVE_LOCK : 0);
  memset(&ov, 0, sizeof(ov));
  return LockFileEx(h, flags, 0, 0xffffffff, 0xffffffff, &ov) ? 0 : -1;
}
开发者ID:asfluido,项目名称:mruby,代码行数:10,代码来源:file.c


示例18: tup_flock

int tup_flock(tup_lock_t fd)
{
	OVERLAPPED wtf;

	memset(&wtf, 0, sizeof(wtf));
	if(LockFileEx(fd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &wtf) == 0) {
		errno = EIO;
		return -1;
	}
	return 0;
}
开发者ID:CodeFred,项目名称:tup,代码行数:11,代码来源:lock_file.c


示例19: dotlock_take_w32

/* Windows specific code of make_dotlock.  Returns 0 on success and -1 on
   error.  */
static int
dotlock_take_w32 (dotlock_t h, long timeout)
{
  int wtime = 0;
  int w32err;
  OVERLAPPED ovl;

 again:
  /* Lock one byte at offset 0.  The offset is given by OVL.  */
  memset (&ovl, 0, sizeof ovl);
  if (LockFileEx (h->lockhd, (LOCKFILE_EXCLUSIVE_LOCK
                              | LOCKFILE_FAIL_IMMEDIATELY), 0, 1, 0, &ovl))
    {
      h->locked = 1;
      return 0; /* okay */
    }

  w32err = GetLastError ();
  if (w32err != ERROR_LOCK_VIOLATION)
    {
      my_error_2 (_("lock `%s' not made: %s\n"),
                  h->lockname, w32_strerror (w32err));
      return -1;
    }

  if (timeout)
    {
      /* Wait until lock has been released.  We use retry intervals of
         50ms, 100ms, 200ms, 400ms, 800ms, 2s, 4s and 8s.  */
      if (!wtime)
        wtime = 50;
      else if (wtime < 800)
        wtime *= 2;
      else if (wtime == 800)
        wtime = 2000;
      else if (wtime < 8000)
        wtime *= 2;

      if (timeout > 0)
        {
          if (wtime > timeout)
            wtime = timeout;
          timeout -= wtime;
        }

      if (wtime >= 800)
        my_info_1 (_("waiting for lock %s...\n"), h->lockname);

      Sleep (wtime);
      goto again;
    }

  return -1;
}
开发者ID:Distrotech,项目名称:gnome-keyring,代码行数:56,代码来源:dotlock.c


示例20: dolock

static inline int dolock(xc_fcntl_mutex_t *fcntl_mutex, int type)
{
	static OVERLAPPED offset = {0, 0, 0, 0, NULL};

	if (type == LCK_UN) {
		return UnlockFileEx(fcntl_mutex->fd, 0, 1, 0, &offset);
	}
	else {
		return LockFileEx(fcntl_mutex->fd, type, 0, 1, 0, &offset);
	}
}
开发者ID:lighttpd,项目名称:xcache,代码行数:11,代码来源:xc_mutex.c



注:本文中的LockFileEx函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ LockList函数代码示例发布时间:2022-05-30
下一篇:
C++ LockBuffer函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap