GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
ck_swlock(3) FreeBSD Library Functions Manual ck_swlock(3)

ck_swlock_init, ck_swlock_write_latch, ck_swlock_write_unlatch, ck_swlock_write_lock, ck_swlock_write_unlock, ck_swlock_write_trylock, ck_swlock_write_downgrade, ck_swlock_locked_writer, ck_swlock_read_lock, ck_swlock_read_trylock, ck_swlock_read_unlock, ck_swlock_locked_reader
centralized copy-safe write-biased single-writer read-write locks

Concurrency Kit (libck, -lck)

#include <ck_swlock.h>

ck_swlock_t lock = CK_SWLOCK_INITIALIZER;


void
ck_swlock_init(ck_swlock_t *lock);

void
ck_swlock_write_lock(ck_swlock_t *lock);

void
ck_swlock_write_unlock(ck_swlock_t *lock);

void
ck_swlatch_write_latch(ck_swlatch_t *latch);

void
ck_swlatch_write_unlatch(ck_swlatch_t *latch);

bool
ck_swlock_write_trylock(ck_swlock_t *lock);

bool
ck_swlock_write_downgrade(ck_swlock_t *lock);

bool
ck_swlock_locked_writer(ck_swlock_t *lock);

void
ck_swlock_read_lock(ck_swlock_t *lock);

bool
ck_swlock_read_trylock(ck_swlock_t *lock);

void
ck_swlock_read_unlock(ck_swlock_t *lock);

bool
ck_swlock_locked_reader(ck_swlock_t *lock);

This is a centralized write-biased single-writer reader-writer lock. It requires half the space that ck_rwlock does and has a low latency fast path. The lock supports latch and unlatch operations that allow it to be used in a copy-safe manner (reader-bits may be over-written safely).

#include <ck_swlock.h>

static ck_swlock_t lock = CK_SWLOCK_INITIALIZER;

static void
reader(void)
{

	for (;;) {
		ck_swlock_read_lock(&lock);
		/* Read-side critical section. */
		ck_swlock_read_unlock(&lock);

		if (ck_swlock_read_trylock(&lock) == true) {
			/* Read-side critical section. */
			ck_swlock_read_unlock(&lock);
		}
	}

	return;
}

static void
writer(void)
{
	ck_swlock_t contrived;

	for (;;) {
		ck_swlock_write_lock(&lock);
		/* Write-side critical section. */
		ck_swlock_write_unlock(&lock);

		if (ck_swlock_write_trylock(&lock) == true) {
			/* Write-side critical section. */
			ck_swlock_write_unlock(&lock);
		}

		ck_swlock_write_latch(&lock);
		/* Write-side critical section. */

		/* This is safe to do with-in a latch. */
		contrived = lock;
		lock = contrived;
		ck_swlock_write_unlatch(&lock);
	}

	return;
}

ck_brlock(3), ck_elide(3), ck_pflock(3), ck_rwlock(3), ck_tflock(3)

Additional information available at http://concurrencykit.org/

April 22, 2014.

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.