Subversion Repositories HelenOS

Rev

Rev 2541 | Rev 2681 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2541 Rev 2680
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2006 Jakub Jermar
2
 * Copyright (c) 2008 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
Line 27... Line 27...
27
 */
27
 */
28
 
28
 
29
/** @addtogroup libc
29
/** @addtogroup libc
30
 * @{
30
 * @{
31
 */
31
 */
-
 
32
/**
32
/** @file
33
 * @file
-
 
34
 * @brief   This file contains rwlock API and provides its fake
-
 
35
 *      implementation based on futexes.
33
 */
36
 */
34
 
37
 
35
#ifndef LIBC_FUTEX_H_
38
#ifndef LIBC_RWLOCK_H_
36
#define LIBC_FUTEX_H_
39
#define LIBC_RWLOCK_H_
37
 
40
 
38
#include <atomic.h>
41
#include <atomic.h>
39
#include <sys/types.h>
42
#include <sys/types.h>
-
 
43
#include <futex.h>
40
 
44
 
41
#define FUTEX_INITIALIZER     {1}
45
typedef atomic_t rwlock_t;
42
 
46
 
43
extern void futex_initialize(atomic_t *futex, int value);
47
#define rwlock_initialize(rwlock)   futex_initialize((rwlock), 1)
44
extern int futex_down(atomic_t *futex);
48
#define rwlock_reader_lock(rwlock)  futex_down((rwlock))
45
extern int futex_trydown(atomic_t *futex);
49
#define rwlock_writer_lock(rwlock)  futex_down((rwlock))
46
extern int futex_down_timeout(atomic_t *futex, uint32_t usec, int flags);
50
#define rwlock_reader_unlock(rwlock)    futex_up((rwlock))
47
extern int futex_up(atomic_t *futex);
51
#define rwlock_writer_unlock(rwlock)    futex_up((rwlock))
48
 
52
 
49
#endif
53
#endif
50
 
54
 
51
/** @}
55
/** @}
52
 */
56
 */