// AddWriteLock takes write lock on the table.
485080
func (s *lockStatementImpl) AddWriteLock(t *Table) LockStatement {
	s.locks = append(s.locks, tableLock{t: t, w: true})
	return s
}
853402
func (c *RemoteClient) writeLockInfo(info *state.LockInfo) error {
	containerReference := c.blobClient.GetContainerReference(c.containerName)
	blobReference := containerReference.GetBlobReference(c.keyName)
	err := blobReference.GetMetadata(&storage.GetBlobMetadataOptions{
		LeaseID: c.leaseID,
	})
	if err != nil {
		return err
	}

	if info == nil {
		delete(blobReference.Metadata, lockInfoMetaKey)
	} else {
		value := base64.StdEncoding.EncodeToString(info.Marshal())
		blobReference.Metadata[lockInfoMetaKey] = value
	}

	opts := &storage.SetBlobMetadataOptions{
		LeaseID: c.leaseID,
	}
	return blobReference.SetMetadata(opts)
}
643436
func FSTryWriteLock(f *os.File) error {
	err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB)
	if err != nil {
		if err == syscall.EWOULDBLOCK {
			return trace.CompareFailed("lock %v is acquired by another process", f.Name())
		}
		return trace.ConvertSystemError(err)
	}
	return nil
}
1162733
func (c *Conn) SetWriteDeadline(t time.Time) error {
	if !c.ok() {
		return syscall.EINVAL
	}
	c.deadlineMutex.Lock()
	defer c.deadlineMutex.Unlock()
	c.wdeadline = t
	return nil
}
152199
func (jl *jsonLedger) writeBlock(block *cb.Block) {
	name := jl.blockFilename(block.Header.Number)

	fileLock.Lock()
	defer fileLock.Unlock()

	file, err := os.Create(name)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	err = jl.marshaler.Marshal(file, block)
	logger.Debugf("Wrote block %d", block.Header.Number)
	if err != nil {
		logger.Panicf("Error marshalling with block number [%d]: %s", block.Header.Number, err)
	}
}
474748
func funlock(db *DB) error {
	return syscall.Flock(int(db.file.Fd()), syscall.LOCK_UN)
}
253989
func (w *syncWriter) Write(p []byte) (n int, err error) {
	w.Lock()
	n, err = w.Writer.Write(p)
	w.Unlock()
	return n, err
}
1043349
func (con *Connection) SetWriteDeadline(t time.Time) error {
	return con.connection.SetWriteDeadline(t)
}
640159
func (file *LockFile) WritePid() (err error) {
	if _, err = file.Seek(0, os.SEEK_SET); err != nil {
		return
	}
	var fileLen int
	if fileLen, err = fmt.Fprint(file, os.Getpid()); err != nil {
		return
	}
	if err = file.Truncate(int64(fileLen)); err != nil {
		return
	}
	err = file.Sync()
	return
}
245162
func (o *ClientOptions) SetWriteTimeout(t time.Duration) *ClientOptions {
	o.WriteTimeout = t
	return o
}
1123841
func (g *Generator) AddLinuxResourcesBlockIOThrottleWriteIOPSDevice(major int64, minor int64, rate uint64) {
	g.initConfigLinuxResourcesBlockIO()
	throttleDevices := addOrReplaceBlockIOThrottleDevice(g.Config.Linux.Resources.BlockIO.ThrottleWriteIOPSDevice, major, minor, rate)
	g.Config.Linux.Resources.BlockIO.ThrottleWriteIOPSDevice = throttleDevices
}
282441
func (f *File) Lock() (err error) {
	done := make(chan struct{})
	f.fs.sendEvents(FSEvent{
		EventType: FSEventLock,
		File:      f,
		Done:      done,
	})
	defer close(done)
	f.lockedLock.Lock()
	defer f.lockedLock.Unlock()
	if f.locked {
		return nil
	}
	defer func() {
		if err == nil {
			f.locked = true
		}
	}()

	// First, sync all and ask journal to flush all existing writes.
	err = f.fs.SyncAll()
	if err != nil {
		return err
	}
	jManager, err := libkbfs.GetJournalManager(f.fs.config)
	if err != nil {
		return err
	}
	if err = jManager.FinishSingleOp(f.fs.ctx,
		f.fs.root.GetFolderBranch().Tlf, nil, f.fs.priority); err != nil {
		return err
	}

	// Now, sync up with the server, while making sure a lock is held by us. If
	// lock taking fails, RPC layer retries automatically.
	lockID := f.getLockID()
	return f.fs.config.KBFSOps().SyncFromServer(f.fs.ctx,
		f.fs.root.GetFolderBranch(), &lockID)
}
812628
func (m *RWMutex) Unlock() {
	m.mutex.Unlock()
	atomic.AddInt64(&m.writers, -1)
}
1303079
func (w *Writer) Write(p []byte) (int, error) {
	w.Lock()
	defer w.Unlock()
	return w.w.Write(p)
}
802483
func (dm *DRWMutex) Lock(id, source string) {

	isReadLock := false
	dm.lockBlocking(drwMutexInfinite, id, source, isReadLock)
}
99181
func (c UIDConnection) SetWriteDeadline(t time.Time) error {
	return c.nc.SetWriteDeadline(t)
}
153112
func (p *IOThrottlerPool) AddWriter(writer io.WriteCloser) (io.WriteCloser, error) {
	// Register with the pool
	err := twiddleClientCount(p, 1)
	if err != nil {
		return nil, err
	}

	return &throttledWriteCloser{writer, p}, nil
}