aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpollney <pollney@a491c6a4-70bf-4b89-8b36-d6c0cb1f094e>2003-04-08 11:58:13 +0000
committerpollney <pollney@a491c6a4-70bf-4b89-8b36-d6c0cb1f094e>2003-04-08 11:58:13 +0000
commit7f8aa4a2475a5975add181dc9cf418cf6ac02258 (patch)
tree6e751bafc3f2799529e76152c613c4852b5681be
parent9ca83c20f7cae7602264c4e02fc2ae95457c369e (diff)
Added some error return codes.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusNumerical/SpaceMask/trunk@28 a491c6a4-70bf-4b89-8b36-d6c0cb1f094e
-rw-r--r--doc/documentation.tex20
-rw-r--r--schedule.ccl5
-rw-r--r--src/MaskUtils.c22
3 files changed, 41 insertions, 6 deletions
diff --git a/doc/documentation.tex b/doc/documentation.tex
index 28df841..349de9b 100644
--- a/doc/documentation.tex
+++ b/doc/documentation.tex
@@ -91,8 +91,13 @@ int SpaceMask\_RegisterType(const char* \emph{type\_name},
\noindent An appropriate number of bits of the mask are allocated to
hold a unique value for the $n$ states specified by the \emph{nstates}
argument. The registration must take place before the type can be
-used, so for instance, this could be scheduled at CCTK\_STARTUP. New
-states can be added to an already allocated type using the function:
+used, so for instance, this could be scheduled at CCTK\_STARTUP. The
+function returns a $-1$ if the required states cannot be allocated
+(for example, if there are not enough free bits remaining in the
+mask), otherwise it returns $0$.
+
+New states can be added to an already allocated type using the
+function:
\indent\parbox{\linewidth}{
\vspace{\baselineskip}\noindent\texttt{
@@ -112,6 +117,9 @@ int SpaceMask\_AppendStatesToType(const char* \emph{type\_name},
\noindent A number of new bits will be added to the specified type
appropriate to hold the number of existing states plus the extra
states. The allocated bits need not be contiguous within the mask.
+The function returns $0$ if successful, otherwise a $-1$ if the new
+states could not be allocated.
+
\subsubsection{Setting and checking mask states}
@@ -189,9 +197,11 @@ CCTK\_INT SpaceMask\_GetStateBits(const char* \emph{type\_name},
\noindent Each of these functions returns a CCTK\_INT8 which holds the
bitmask corresponding to the given type or state. For example, if a
given type uses three bits of the mask, the returned value could be
-the integer corresponding to the bitfield 001110000\ldots, where the
-location of 1s indicates the bits which have been allocated to the
-given type.
+the integer corresponding to the bitfield $001110000$\ldots, where the
+location of $1$s indicates the bits which have been allocated to the
+given type. A return value of $0$ indicates that the bitmask could
+not be determined for some reason (for example, the requested state
+was not previously registered).
The following macros have been defined for fast setting and checking
of the mask by direct bitwise operations:
diff --git a/schedule.ccl b/schedule.ccl
index 68492fb..1e6d236 100644
--- a/schedule.ccl
+++ b/schedule.ccl
@@ -5,6 +5,11 @@ if (use_mask)
{
STORAGE: space_mask_group
+ schedule SetupSpaceMaskRegistry at CCTK_STARTUP
+ {
+ LANG: C
+ } "Initialise spacemask registry"
+
schedule MaskZero at CCTK_INITIAL
{
LANG: C
diff --git a/src/MaskUtils.c b/src/MaskUtils.c
index 29a280a..0f51d4b 100644
--- a/src/MaskUtils.c
+++ b/src/MaskUtils.c
@@ -120,7 +120,10 @@ SpaceMask_get_free_bits(int nbits)
}
if (j<nbits)
- CCTK_WARN (0, "Cannot allocate mask: Not enough free bits.");
+ {
+ CCTK_WARN (1, "Cannot allocate mask: Not enough free bits.");
+ return 0;
+ }
return new_bits;
}
@@ -216,6 +219,10 @@ SpaceMask_setup_new_type(CCTK_INT new_bits, const char* type_name,
int j;
new_type = (SpaceMask_Type*) malloc (sizeof(SpaceMask_Type));
+
+ if (new_type == NULL)
+ return NULL;
+
new_type->bitmask = new_bits;
new_type->nstates = nstates;
new_type->name = type_name;
@@ -288,10 +295,16 @@ SpaceMask_RegisterType(const char* type_name, int nstates,
bit_nbr = SpaceMask_get_bit_nbr(nstates);
new_bits = SpaceMask_get_free_bits(bit_nbr);
+
+ if (new_bits == 0)
+ return -1;
+
state_mask = SpaceMask_determine_state_mask(new_bits, nstates);
new_type = SpaceMask_setup_new_type(new_bits, type_name, nstates,
state_list, state_mask);
+ if (new_type == NULL)
+ return -1;
SpaceMask_append_type_to_registry (new_type);
@@ -348,6 +361,10 @@ SpaceMask_AppendStatesToType(const char* type_name, int nstates,
SpaceMask_get_bit_nbr(old_type->nstates);
new_bits = SpaceMask_get_free_bits(new_bit_nbr);
+
+ if (new_bits == 0)
+ return -1;
+
allocated_bits = old_type->bitmask | new_bits;
state_mask = SpaceMask_determine_state_mask(allocated_bits, total_nstates);
@@ -362,6 +379,9 @@ SpaceMask_AppendStatesToType(const char* type_name, int nstates,
new_type = SpaceMask_setup_new_type(allocated_bits, type_name, total_nstates,
new_state_list, state_mask);
+ if (new_type == NULL)
+ return -1;
+
free(old_type);
spacemask_registry->type_list[old_type_idx] = new_type;