File: rtl_spinlock.h

package info (click to toggle)
rtlinux 3.1pre3-3
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 4,896 kB
  • ctags: 4,228
  • sloc: ansic: 26,204; sh: 2,069; makefile: 1,414; perl: 855; tcl: 489; asm: 380; cpp: 42
file content (65 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * RTLinux POSIX spinlock implementation
 *
 * Written by Michael Barabanov
 * Copyright (C) Finite State Machine Labs Inc., 1999
 * Released under the terms of the GPL Version 2
 *
 */

#ifndef __RTL_SPINLOCK_H__
#define __RTL_SPINLOCK_H__

#include <rtl_sync.h>
#include <linux/errno.h>

typedef struct {
	spinlock_t lock;
	rtl_irqstate_t flags;
} pthread_spinlock_t;

#define PTHREAD_SPINLOCK_INITIALIZER { SPIN_LOCK_UNLOCKED, 0 }

static inline int pthread_spin_init(pthread_spinlock_t *lock, int pshared)
{
	spin_lock_init(&lock->lock);
	return 0;
}

static inline int pthread_spin_destroy(pthread_spinlock_t *lock)
{
	return 0;
}

static inline int pthread_spin_lock(pthread_spinlock_t *lock)
{
	rtl_irqstate_t flags;
	rtl_no_interrupts (flags);
	spin_lock (&lock->lock);
	lock->flags = flags;
	return 0;
}

static inline int pthread_spin_trylock(pthread_spinlock_t *lock)
{
	rtl_irqstate_t flags;
	rtl_no_interrupts (flags);
	if (rtl_spin_trylock(&lock->lock)) {
		rtl_restore_interrupts (flags);
		return EBUSY;
	} else {
		lock->flags = flags;
		return 0;
	}
}

static inline int pthread_spin_unlock(pthread_spinlock_t *lock)
{
	rtl_irqstate_t flags;
	flags = lock->flags;
	rtl_spin_unlock(&lock->lock);
	rtl_restore_interrupts (flags);
	return 0;
}

#endif