Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions
semaphore.h File Reference
#include <linux/list.h>
#include <linux/spinlock.h>

Go to the source code of this file.

Data Structures

struct  semaphore
 

Macros

#define __SEMAPHORE_INITIALIZER(name, n)
 
#define DEFINE_SEMAPHORE(name)   struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
 

Functions

void down (struct semaphore *sem)
 
int __must_check down_interruptible (struct semaphore *sem)
 
int __must_check down_killable (struct semaphore *sem)
 
int __must_check down_trylock (struct semaphore *sem)
 
int __must_check down_timeout (struct semaphore *sem, long jiffies)
 
void up (struct semaphore *sem)
 

Macro Definition Documentation

#define __SEMAPHORE_INITIALIZER (   name,
  n 
)
Value:
{ \
.lock = __RAW_SPIN_LOCK_UNLOCKED((name).lock), \
.count = n, \
.wait_list = LIST_HEAD_INIT((name).wait_list), \
}

Definition at line 22 of file semaphore.h.

#define DEFINE_SEMAPHORE (   name)    struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)

Definition at line 29 of file semaphore.h.

Function Documentation

void down ( struct semaphore sem)

down - acquire the semaphore : the semaphore to be acquired

Acquires the semaphore. If no more tasks are allowed to acquire the semaphore, calling this function will put the task to sleep until the semaphore is released.

Use of this function is deprecated, please use down_interruptible() or down_killable() instead.

Definition at line 53 of file semaphore.c.

int __must_check down_interruptible ( struct semaphore sem)

down_interruptible - acquire the semaphore unless interrupted : the semaphore to be acquired

Attempts to acquire the semaphore. If no more tasks are allowed to acquire the semaphore, calling this function will put the task to sleep. If the sleep is interrupted by a signal, this function will return -EINTR. If the semaphore is successfully acquired, this function returns 0.

Definition at line 75 of file semaphore.c.

int __must_check down_killable ( struct semaphore sem)

down_killable - acquire the semaphore unless killed : the semaphore to be acquired

Attempts to acquire the semaphore. If no more tasks are allowed to acquire the semaphore, calling this function will put the task to sleep. If the sleep is interrupted by a fatal signal, this function will return -EINTR. If the semaphore is successfully acquired, this function returns 0.

Definition at line 101 of file semaphore.c.

int __must_check down_timeout ( struct semaphore sem,
long  jiffies 
)

down_timeout - acquire the semaphore within a specified time : the semaphore to be acquired : how long to wait before failing

Attempts to acquire the semaphore. If no more tasks are allowed to acquire the semaphore, calling this function will put the task to sleep. If the semaphore is not released within the specified number of jiffies, this function returns -ETIME. It returns 0 if the semaphore was acquired.

Definition at line 155 of file semaphore.c.

int __must_check down_trylock ( struct semaphore sem)

down_trylock - try to acquire the semaphore, without waiting : the semaphore to be acquired

Try to acquire the semaphore atomically. Returns 0 if the semaphore has been acquired successfully or 1 if it it cannot be acquired.

NOTE: This return value is inverted from both spin_trylock and mutex_trylock! Be careful about this when converting code.

Unlike mutex_trylock, this function can be used from interrupt context, and the semaphore can be released by any task or interrupt.

Definition at line 130 of file semaphore.c.

void up ( struct semaphore sem)

up - release the semaphore : the semaphore to release

Release the semaphore. Unlike mutexes, up() may be called from any context and even by tasks which have never called down().

Definition at line 178 of file semaphore.c.