/kernel/trunk/test/atomic/atomic1/test.c |
---|
0,0 → 1,56 |
/* |
* Copyright (C) 2006 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <test.h> |
#include <print.h> |
#include <arch/atomic.h> |
#include <debug.h> |
void test(void) |
{ |
atomic_t a; |
atomic_set(&a, 10); |
printf("Testing atomic_set() and atomic_get().\n"); |
ASSERT(atomic_get(&a) == 10); |
printf("Testing atomic_postinc()\n"); |
ASSERT(atomic_postinc(&a) == 10); |
ASSERT(atomic_get(&a) == 11); |
printf("Testing atomic_postdec()\n"); |
ASSERT(atomic_postdec(&a) == 11); |
ASSERT(atomic_get(&a) == 10); |
printf("Testing atomic_preinc()\n"); |
ASSERT(atomic_preinc(&a) == 11); |
ASSERT(atomic_get(&a) == 11); |
printf("Testing atomic_predec()\n"); |
ASSERT(atomic_postdec(&a) == 11); |
ASSERT(atomic_get(&a) == 10); |
printf("Test passed.\n"); |
return; |
} |
/kernel/trunk/kernel.config |
---|
74,6 → 74,7 |
# Kernel test type |
@ "" No test |
@ "atomic/atomic1" Test of atomic operations. |
@ "synch/rwlock1" Read write test 1 |
@ "synch/rwlock2" Read write test 2 |
@ "synch/rwlock3" Read write test 3 |
/kernel/trunk/generic/src/syscall/syscall.c |
---|
124,7 → 124,7 |
*/ |
static int check_call_limit(void) |
{ |
if (atomic_inc_post(&TASK->active_calls) > IPC_MAX_ASYNC_CALLS) { |
if (atomic_preinc(&TASK->active_calls) > IPC_MAX_ASYNC_CALLS) { |
atomic_dec(&TASK->active_calls); |
return -1; |
} |
/kernel/trunk/arch/sparc64/include/atomic.h |
---|
62,6 → 62,26 |
return a; |
} |
static inline count_t atomic_preinc(atomic_t *val) |
{ |
return atomic_add(val, 1) + 1; |
} |
static inline count_t atomic_postinc(atomic_t *val) |
{ |
return atomic_add(val, 1); |
} |
static inline count_t atomic_predec(atomic_t *val) |
{ |
return atomic_add(val, -1) - 1; |
} |
static inline count_t atomic_postdec(atomic_t *val) |
{ |
return atomic_add(val, 1); |
} |
static inline void atomic_inc(atomic_t *val) |
{ |
(void) atomic_add(val, 1); |
/kernel/trunk/arch/ia64/include/atomic.h |
---|
38,7 → 38,7 |
* @param val Atomic value. |
* @param imm Value to add. |
* |
* @return Value after addition. |
* @return Value before addition. |
*/ |
static inline count_t atomic_add(atomic_t *val, int imm) |
{ |
62,10 → 62,10 |
static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); } |
static inline void atomic_dec(atomic_t *val) { atomic_add(val, -1); } |
static inline count_t atomic_inc_pre(atomic_t *val) { return atomic_add(val, 1); } |
static inline count_t atomic_dec_pre(atomic_t *val) { return atomic_add(val, -1); } |
static inline count_t atomic_preinc(atomic_t *val) { return atomic_add(val, 1) + 1; } |
static inline count_t atomic_predec(atomic_t *val) { return atomic_add(val, -1) - 1; } |
static inline count_t atomic_inc_post(atomic_t *val) { return atomic_add(val, 1) + 1; } |
static inline count_t atomic_dec_post(atomic_t *val) { return atomic_add(val, -1) - 1; } |
static inline count_t atomic_postinc(atomic_t *val) { return atomic_add(val, 1); } |
static inline count_t atomic_postdec(atomic_t *val) { return atomic_add(val, -1); } |
#endif |
/kernel/trunk/arch/ppc32/include/atomic.h |
---|
63,25 → 63,25 |
: "cc"); |
} |
static inline __u32 atomic_inc_pre(atomic_t *val) |
static inline __u32 atomic_postinc(atomic_t *val) |
{ |
atomic_inc(val); |
return val->count - 1; |
} |
static inline __u32 atomic_dec_pre(atomic_t *val) |
static inline __u32 atomic_postdec(atomic_t *val) |
{ |
atomic_dec(val); |
return val->count + 1; |
} |
static inline __u32 atomic_inc_post(atomic_t *val) |
static inline __u32 atomic_preinc(atomic_t *val) |
{ |
atomic_inc(val); |
return val->count; |
} |
static inline __u32 atomic_dec_post(atomic_t *val) |
static inline __u32 atomic_predec(atomic_t *val) |
{ |
atomic_dec(val); |
return val->count; |
/kernel/trunk/arch/amd64/include/atomic.h |
---|
59,7 → 59,7 |
#endif /* CONFIG_SMP */ |
} |
static inline count_t atomic_inc_pre(atomic_t *val) |
static inline count_t atomic_postinc(atomic_t *val) |
{ |
count_t r; |
72,7 → 72,7 |
return r; |
} |
static inline count_t atomic_dec_pre(atomic_t *val) |
static inline count_t atomic_postdec(atomic_t *val) |
{ |
count_t r; |
85,8 → 85,8 |
return r; |
} |
#define atomic_inc_post(val) (atomic_inc_pre(val)+1) |
#define atomic_dec_post(val) (atomic_dec_pre(val)-1) |
#define atomic_preinc(val) (atomic_postinc(val)+1) |
#define atomic_predec(val) (atomic_postdec(val)-1) |
static inline __u64 test_and_set(atomic_t *val) { |
__u64 v; |
/kernel/trunk/arch/mips32/include/atomic.h |
---|
34,13 → 34,12 |
#define atomic_inc(x) ((void) atomic_add(x, 1)) |
#define atomic_dec(x) ((void) atomic_add(x, -1)) |
#define atomic_inc_pre(x) (atomic_add(x, 1) - 1) |
#define atomic_dec_pre(x) (atomic_add(x, -1) + 1) |
#define atomic_postinc(x) (atomic_add(x, 1) - 1) |
#define atomic_postdec(x) (atomic_add(x, -1) + 1) |
#define atomic_inc_post(x) atomic_add(x, 1) |
#define atomic_dec_post(x) atomic_add(x, -1) |
#define atomic_preinc(x) atomic_add(x, 1) |
#define atomic_predec(x) atomic_add(x, -1) |
typedef struct { volatile __u32 count; } atomic_t; |
/* Atomic addition of immediate value. |
/kernel/trunk/arch/ia32/include/atomic.h |
---|
59,7 → 59,7 |
#endif /* CONFIG_SMP */ |
} |
static inline count_t atomic_inc_pre(atomic_t *val) |
static inline count_t atomic_postinc(atomic_t *val) |
{ |
count_t r; |
72,7 → 72,7 |
return r; |
} |
static inline count_t atomic_dec_pre(atomic_t *val) |
static inline count_t atomic_postdec(atomic_t *val) |
{ |
count_t r; |
85,8 → 85,8 |
return r; |
} |
#define atomic_inc_post(val) (atomic_inc_pre(val)+1) |
#define atomic_dec_post(val) (atomic_dec_pre(val)-1) |
#define atomic_preinc(val) (atomic_postinc(val)+1) |
#define atomic_predec(val) (atomic_postdec(val)-1) |
static inline __u32 test_and_set(atomic_t *val) { |
__u32 v; |