Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
b78d06da
Commit
b78d06da
authored
23 years ago
by
Jean-Damien Durand
Committed by
Steven Murray
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Added Cglobals_get() test suite source code in the man page
parent
ca1264dd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mediachanger/castorrmc/common/Cglobals.man
+105
-2
105 additions, 2 deletions
mediachanger/castorrmc/common/Cglobals.man
with
105 additions
and
2 deletions
mediachanger/castorrmc/common/Cglobals.man
+
105
−
2
View file @
b78d06da
.\"
.\" $Id: Cglobals.man,v 1.
2
2001/06/12 07:
49:53
jdurand Exp $
.\" $Id: Cglobals.man,v 1.
3
2001/06/12 07:
51:38
jdurand Exp $
.\"
.TH CGLOBALS "3" "$Date: 2001/06/12 07:
49:53
$" "CASTOR" "Common Library Functions"
.TH CGLOBALS "3" "$Date: 2001/06/12 07:
51:38
$" "CASTOR" "Common Library Functions"
.SH NAME
\fBCglobals\fP \- \fBC\fPASTOR thread-safe \fBglobal\fP variable\fBs\fP interface
.SH SYNOPSIS
...
...
@@ -184,7 +184,110 @@ int main()
}
.ft
.LP
The following example is the source of the test suite for Cglobals_get():
.ft CW
.nf
.sp
#include <Cthread_api.h>
#include <stdlib.h>
#include <stdio.h>
#include <Cglobals.h> /* Get Cglobals_get prototype */
#include <serrno.h>
static int my_key = -1; /* Our static key, integer, init value -1 */
#define my_var (*C__my_var())
static int my_var_static; /* If Cglobals_get error in order not to crash */
void *doit _PROTO((void *));
int doit_v = 0;
#define NTHREAD 100
int *C__my_var()
{
int *var;
/* Call Cglobals_get */
switch (Cglobals_get(&my_key,
(void **) &var,
sizeof(int)
)) {
case -1:
fprintf(stderr,"[%d] Cglobals_get error\n", Cthread_self());
break;
case 0:
fprintf(stderr,"[%d] Cglobals_get OK\n", Cthread_self());
break;
case 1:
fprintf(stderr,"[%d] Cglobals_get OK and first call\n", Cthread_self());
break;
default:
fprintf(stderr,"[%d] Cglobals_get unknown return code\n", Cthread_self());
break;
}
/* If error, var will be NULL */
if (var == NULL) {
fprintf(stderr,"[%d] Cglobals_get error : RETURN static ADDRESS!!!!!!!!!!!!\n", Cthread_self());
return(&my_var_static);
}
return(var);
}
int main()
{
int i;
fprintf(stdout, "[%d] ---> Before any Cthread call\n", -1);
fprintf(stdout, "[%d] Current my_var value is: %d\n", -1, my_var);
fprintf(stdout, "[%d] Set my_var value to: %d\n", -1, 12);
my_var = 12;
fprintf(stdout, "[%d] Current my_var value is: %d\n", -1, my_var);
fprintf(stdout, "[%d] Testing consistency\n", -1);
if (my_var != 12) {
fprintf(stdout, "[%d] Cglobals_get worked ok\n", -1);
exit(1);
}
sleep(1);
for (i = 0; i < NTHREAD; i++) {
Cthread_create(&doit, &doit_v);
doit_v++;
}
fprintf(stdout, "[%d] ---> After all Cthread_create calls\n", -1);
fprintf(stdout, "[%d] Current my_var value is: %d\n", -1, my_var);
fprintf(stdout, "[%d] Set my_var value to: %d\n", -1, NTHREAD * 10000 + 12);
my_var = NTHREAD * 10000 + 12;
fprintf(stdout, "[%d] Current my_var value is: %d\n", -1, my_var);
fprintf(stdout, "[%d] Testing consistency\n", -1);
if (my_var != (NTHREAD * 10000 + 12)) {
fprintf(stdout, "[%d] Cglobals_get worked ok\n", -1);
exit(1);
}
sleep(1);
exit(0);
}
void *doit(arg)
void *arg;
{
int Tid;
int doit = * (int *) arg;
Cglobals_getTid(&Tid);
my_var = (Tid + 1) * 100 + 12;
fprintf(stdout, "[%d] my_var value is: %d (should be %d)\n", Cthread_self(), my_var, (Tid + 1) * 100 + 12);
fprintf(stdout, "[%d] second call -- my_var value is: %d (should be %d)\n", Cthread_self(), my_var, (Tid + 1) * 100 + 12);
fprintf(stdout, "[%d] Testing consistency\n", Cthread_self());
if (my_var != ((Tid + 1) * 100 + 12)) {
fprintf(stdout, "[%d] !!!!!!!!! ERROR !!!!!!!!!\n", Cthread_self());
exit(1);
} else {
fprintf(stdout, "[%d] Cglobals_get worked ok\n", Cthread_self());
}
return(0);
}
.ft
.LP
.SH SEE ALSO
\fBCthread\fP(3), \fBserrno\fP(3), \fBCgetopt\fP(3)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment