VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/tests/atomic.c@ 22683

最後變更 在這個檔案從22683是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 4.7 KB
 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#include "prio.h"
39#include "prprf.h"
40#include "pratom.h"
41
42PRIntn main(PRIntn argc, char **argv)
43{
44 PRInt32 rv, oldval, test, result = 0;
45 PRFileDesc *output = PR_GetSpecialFD(PR_StandardOutput);
46
47 oldval = test = -2;
48 rv = PR_AtomicIncrement(&test);
49 result = result | ((rv == -1) ? 0 : 1);
50 PR_fprintf(
51 output, "PR_AtomicIncrement(%d) == %d: %s\n",
52 oldval, rv, (rv == -1) ? "PASSED" : "FAILED");
53 oldval = test;
54 rv = PR_AtomicIncrement(&test);
55 result = result | ((rv == 0) ? 0 : 1);
56 PR_fprintf(
57 output, "PR_AtomicIncrement(%d) == %d: %s\n",
58 oldval, rv, (rv == 0) ? "PASSED" : "FAILED");
59 oldval = test;
60 rv = PR_AtomicIncrement(&test);
61 result = result | ((rv == 1) ? 0 : 1);
62 PR_fprintf(
63 output, "PR_AtomicIncrement(%d) == %d: %s\n",
64 oldval, rv, (rv == 1) ? "PASSED" : "FAILED");
65
66 oldval = test = -2;
67 rv = PR_AtomicAdd(&test,1);
68 result = result | ((rv == -1) ? 0 : 1);
69 PR_fprintf(
70 output, "PR_AtomicAdd(%d,%d) == %d: %s\n",
71 oldval, 1, rv, (rv == -1) ? "PASSED" : "FAILED");
72 oldval = test;
73 rv = PR_AtomicAdd(&test, 4);
74 result = result | ((rv == 3) ? 0 : 1);
75 PR_fprintf(
76 output, "PR_AtomicAdd(%d,%d) == %d: %s\n",
77 oldval, 4, rv, (rv == 3) ? "PASSED" : "FAILED");
78 oldval = test;
79 rv = PR_AtomicAdd(&test, -6);
80 result = result | ((rv == -3) ? 0 : 1);
81 PR_fprintf(
82 output, "PR_AtomicAdd(%d,%d) == %d: %s\n",
83 oldval, -6, rv, (rv == -3) ? "PASSED" : "FAILED");
84
85 oldval = test = 2;
86 rv = PR_AtomicDecrement(&test);
87 result = result | ((rv == 1) ? 0 : 1);
88 PR_fprintf(
89 output, "PR_AtomicDecrement(%d) == %d: %s\n",
90 oldval, rv, (rv == 1) ? "PASSED" : "FAILED");
91 oldval = test;
92 rv = PR_AtomicDecrement(&test);
93 result = result | ((rv == 0) ? 0 : 1);
94 PR_fprintf(
95 output, "PR_AtomicDecrement(%d) == %d: %s\n",
96 oldval, rv, (rv == 0) ? "PASSED" : "FAILED");
97 oldval = test;
98 rv = PR_AtomicDecrement(&test);
99 result = result | ((rv == -1) ? 0 : 1);
100 PR_fprintf(
101 output, "PR_AtomicDecrement(%d) == %d: %s\n",
102 oldval, rv, (rv == -1) ? "PASSED" : "FAILED");
103
104 /* set to a different value */
105 oldval = test = -2;
106 rv = PR_AtomicSet(&test, 2);
107 result = result | (((rv == -2) && (test == 2)) ? 0 : 1);
108 PR_fprintf(
109 output, "PR_AtomicSet(%d, %d) == %d: %s\n",
110 oldval, 2, rv, ((rv == -2) && (test == 2)) ? "PASSED" : "FAILED");
111
112 /* set to the same value */
113 oldval = test = -2;
114 rv = PR_AtomicSet(&test, -2);
115 result = result | (((rv == -2) && (test == -2)) ? 0 : 1);
116 PR_fprintf(
117 output, "PR_AtomicSet(%d, %d) == %d: %s\n",
118 oldval, -2, rv, ((rv == -2) && (test == -2)) ? "PASSED" : "FAILED");
119
120 PR_fprintf(
121 output, "Atomic operations test %s\n",
122 (result == 0) ? "PASSED" : "FAILED");
123 return result;
124} /* main */
125
126/* atomic.c */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette