| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2008, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bvbi_lcop.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/1 $ |
|---|
| 12 | * $brcm_Date: 12/3/08 7:47p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * See Module Overview below |
|---|
| 16 | * |
|---|
| 17 | * Revision History: |
|---|
| 18 | * |
|---|
| 19 | * $brcm_Log: /magnum/portinginterface/vbi/7400/bvbi_lcop.h $ |
|---|
| 20 | * |
|---|
| 21 | * Hydra_Software_Devel/1 12/3/08 7:47p darnstein |
|---|
| 22 | * PR45819: Source files for 7400 are no longer symbolic links. |
|---|
| 23 | * |
|---|
| 24 | * Hydra_Software_Devel/6 8/5/08 2:04p darnstein |
|---|
| 25 | * PR45420: Eliminate float and double. These were never used in |
|---|
| 26 | * production software anyway. |
|---|
| 27 | * |
|---|
| 28 | * Hydra_Software_Devel/5 1/17/07 5:31p darnstein |
|---|
| 29 | * PR26464: correctly handle teletext output to multiple VECs |
|---|
| 30 | * |
|---|
| 31 | * Hydra_Software_Devel/4 12/14/06 4:51p darnstein |
|---|
| 32 | * PR26464: Add a few comments. Add the complete test program, disabled by |
|---|
| 33 | * a preprocessor symbol. |
|---|
| 34 | * |
|---|
| 35 | * Hydra_Software_Devel/3 12/14/06 3:42p darnstein |
|---|
| 36 | * Pr26464: Use pointers to structs, rather than structs. Fix several |
|---|
| 37 | * logic errors. |
|---|
| 38 | * |
|---|
| 39 | * Hydra_Software_Devel/2 12/14/06 12:48p darnstein |
|---|
| 40 | * PR26464: Fix logic error in "copy" method. Change "transfer" method to |
|---|
| 41 | * a sequence. |
|---|
| 42 | * |
|---|
| 43 | * Hydra_Software_Devel/1 12/14/06 11:54a darnstein |
|---|
| 44 | * PR26464: Limited Counted Object Paradigm |
|---|
| 45 | * |
|---|
| 46 | ***************************************************************************/ |
|---|
| 47 | |
|---|
| 48 | #ifndef BVBI_LCOP_H__ |
|---|
| 49 | #define BVBI_LCOP_H__ |
|---|
| 50 | |
|---|
| 51 | /* Limited Counted Object Paradigm |
|---|
| 52 | * ------------------------------- |
|---|
| 53 | * Implements a simplified letter/envelope or "smart pointer" pattern. For |
|---|
| 54 | * details, see the paper |
|---|
| 55 | * .../DVTSJ/portinginterface/vbi/7400/teletext_problem.txt. It is in a |
|---|
| 56 | * ClearCase VOB. |
|---|
| 57 | * |
|---|
| 58 | * Note: the bottom of this header contains a complete test program. It is |
|---|
| 59 | * only compiled if BVBI_P_LCOP_TEST_PROGRAM is defined. |
|---|
| 60 | */ |
|---|
| 61 | |
|---|
| 62 | /* |
|---|
| 63 | * Summary: |
|---|
| 64 | * ------- |
|---|
| 65 | * Defines a data type such that any struct that has this data type as a |
|---|
| 66 | * member becomes suitable for use as a counted object. Also used to define |
|---|
| 67 | * the free list. |
|---|
| 68 | * |
|---|
| 69 | * Example: |
|---|
| 70 | * ------- |
|---|
| 71 | * struct My_counted_object { |
|---|
| 72 | * ... |
|---|
| 73 | * BVBI_P_LCOP_COUNTEDPROP(My_counted_object) link; |
|---|
| 74 | * }; |
|---|
| 75 | * ... |
|---|
| 76 | * BVBI_P_LCOP_COUNTEDPROP(My_counted_object) freelist; |
|---|
| 77 | */ |
|---|
| 78 | #define BVBI_P_LCOP_COUNTEDPROP(co_type) \ |
|---|
| 79 | union { struct co_type* l_co; unsigned int i_count; } |
|---|
| 80 | |
|---|
| 81 | /* |
|---|
| 82 | * Summary: |
|---|
| 83 | * ------- |
|---|
| 84 | * For a given counted object type, creates a new data type such that any |
|---|
| 85 | * struct that has the new data type as a member becomes suitable for use as |
|---|
| 86 | * an owner object. |
|---|
| 87 | * |
|---|
| 88 | * Example: |
|---|
| 89 | * ------- |
|---|
| 90 | * struct My_counted_object { |
|---|
| 91 | * ... |
|---|
| 92 | * }; |
|---|
| 93 | * ... |
|---|
| 94 | * struct My_owner_object { |
|---|
| 95 | * ... |
|---|
| 96 | * BVBI_P_LCOP_OWNERPROP(My_counted_object) link; |
|---|
| 97 | * }; |
|---|
| 98 | */ |
|---|
| 99 | #define BVBI_P_LCOP_OWNERPROP(co_type) \ |
|---|
| 100 | struct { struct co_type* l_co; } |
|---|
| 101 | |
|---|
| 102 | /* |
|---|
| 103 | * Summary: |
|---|
| 104 | * ------- |
|---|
| 105 | * Initialize the free list (to empty state). |
|---|
| 106 | * |
|---|
| 107 | * Example: |
|---|
| 108 | * ------- |
|---|
| 109 | * struct My_counted_object { |
|---|
| 110 | * ... |
|---|
| 111 | * }; |
|---|
| 112 | * BVBI_P_LCOP_COUNTEDPROP(My_counted_object) freelist; |
|---|
| 113 | * ... |
|---|
| 114 | * BVBI_P_LCOP_INITFREELIST_isr (&freelist); |
|---|
| 115 | */ |
|---|
| 116 | #define BVBI_P_LCOP_INITFREELIST_isr(freelist) \ |
|---|
| 117 | ((freelist)->l_co = NULL) |
|---|
| 118 | #define BVBI_P_LCOP_INITFREELIST(freelist) \ |
|---|
| 119 | do { \ |
|---|
| 120 | BKNI_EnterCriticalSection(); \ |
|---|
| 121 | (BVBI_P_LCOP_INITFREELIST_isr(freelist)); \ |
|---|
| 122 | BKNI_LeaveCriticalSection(); \ |
|---|
| 123 | } while (0) |
|---|
| 124 | |
|---|
| 125 | /* |
|---|
| 126 | * Summary: |
|---|
| 127 | * ------- |
|---|
| 128 | * Obtain address of counted object owned by an owner. |
|---|
| 129 | * |
|---|
| 130 | * Example: |
|---|
| 131 | * ------- |
|---|
| 132 | * struct My_counted_object { |
|---|
| 133 | * ... |
|---|
| 134 | * }; |
|---|
| 135 | * struct My_owner_object { |
|---|
| 136 | * ... |
|---|
| 137 | * BVBI_P_LCOP_OWNERPROP(My_counted_object) link; |
|---|
| 138 | * }; |
|---|
| 139 | * struct My_owner_object owner; |
|---|
| 140 | * ... |
|---|
| 141 | * struct My_counted_object* counted = BVBI_P_LCOP_GET_isr (&owner, link); |
|---|
| 142 | */ |
|---|
| 143 | #define BVBI_P_LCOP_GET_isr(owner,owner_link) \ |
|---|
| 144 | ((owner)->owner_link.l_co) |
|---|
| 145 | #define BVBI_P_LCOP_GET(owner,owner_link) \ |
|---|
| 146 | (BVBI_P_LCOP_GET_isr((owner),owner_link)) |
|---|
| 147 | |
|---|
| 148 | /* |
|---|
| 149 | * Summary: |
|---|
| 150 | * ------- |
|---|
| 151 | * Operation: create. |
|---|
| 152 | * |
|---|
| 153 | * Example: |
|---|
| 154 | * ------- |
|---|
| 155 | * struct My_counted_object { |
|---|
| 156 | * ... |
|---|
| 157 | * BVBI_P_LCOP_COUNTED_OBJECT(linkc); |
|---|
| 158 | * }; |
|---|
| 159 | * struct My_owner_object { |
|---|
| 160 | * ... |
|---|
| 161 | * BVBI_P_LCOP_OWNERPROP(My_counted_object) linko; |
|---|
| 162 | * }; |
|---|
| 163 | * struct My_owner_object owner; |
|---|
| 164 | * struct My_counted_object counted; |
|---|
| 165 | * ... |
|---|
| 166 | * BVBI_P_LCOP_CREATE_isr (&owner, linko, &counted, linkc); |
|---|
| 167 | */ |
|---|
| 168 | #define \ |
|---|
| 169 | BVBI_P_LCOP_CREATE_isr(owner_object,owner_link,counted_object,counted_link) \ |
|---|
| 170 | do { \ |
|---|
| 171 | (owner_object)->owner_link.l_co = (counted_object); \ |
|---|
| 172 | (counted_object)->counted_link.i_count = 1; \ |
|---|
| 173 | } \ |
|---|
| 174 | while (0) |
|---|
| 175 | #define \ |
|---|
| 176 | BVBI_P_LCOP_CREATE(owner_object,owner_link,counted_object,counted_link) \ |
|---|
| 177 | do { \ |
|---|
| 178 | BKNI_EnterCriticalSection(); \ |
|---|
| 179 | BVBI_P_LCOP_CREATE_isr(\ |
|---|
| 180 | (owner_object),owner_link,(counted_object),counted_link); \ |
|---|
| 181 | BKNI_LeaveCriticalSection(); \ |
|---|
| 182 | } while (0) |
|---|
| 183 | |
|---|
| 184 | /* |
|---|
| 185 | * Summary: |
|---|
| 186 | * ------- |
|---|
| 187 | * Operation: destroy. After calling, the user should recycle both the |
|---|
| 188 | * owner object and its pointed-to counted object. This function |
|---|
| 189 | * should be paired with calls to BVBI_P_LCOP_CREATE_isr(), for the |
|---|
| 190 | * same pair of objects. |
|---|
| 191 | * |
|---|
| 192 | * Example: |
|---|
| 193 | * ------- |
|---|
| 194 | * struct My_counted_object { |
|---|
| 195 | * ... |
|---|
| 196 | * BVBI_P_LCOP_COUNTEDPROP(My_counted_object) linkc; |
|---|
| 197 | * }; |
|---|
| 198 | * struct My_owner_object { |
|---|
| 199 | * ... |
|---|
| 200 | * BVBI_P_LCOP_OWNERPROP(My_counted_object) linko; |
|---|
| 201 | * }; |
|---|
| 202 | * BVBI_P_LCOP_COUNTEDPROP(My_counted_object) freelist; |
|---|
| 203 | * struct My_owner_object* pOwner; |
|---|
| 204 | * ... |
|---|
| 205 | * BVBI_P_LCOP_DESTROY_isr (pOwner, linko, &freelist, linkc); |
|---|
| 206 | * free (BVBI_P_LCOP_GET_isr(pOwner,linko)); |
|---|
| 207 | * free (pOwner); |
|---|
| 208 | */ |
|---|
| 209 | #define BVBI_P_LCOP_DESTROY_isr(owner,owner_link,freelist,counted_link) \ |
|---|
| 210 | do { \ |
|---|
| 211 | BDBG_ASSERT ((owner)->owner_link.l_co->counted_link.i_count); \ |
|---|
| 212 | if ((owner)->owner_link.l_co->counted_link.i_count > 1) \ |
|---|
| 213 | { \ |
|---|
| 214 | BDBG_ASSERT ((freelist)->l_co); \ |
|---|
| 215 | --((owner)->owner_link.l_co->counted_link.i_count); \ |
|---|
| 216 | (owner)->owner_link.l_co = (freelist)->l_co; \ |
|---|
| 217 | (freelist)->l_co = (freelist)->l_co->counted_link.l_co; \ |
|---|
| 218 | (owner)->owner_link.l_co->counted_link.i_count = 1; \ |
|---|
| 219 | } \ |
|---|
| 220 | } while (0) |
|---|
| 221 | #define BVBI_P_LCOP_DESTROY(owner,owner_link,freelist,counted_link) \ |
|---|
| 222 | do { \ |
|---|
| 223 | BKNI_EnterCriticalSection(); \ |
|---|
| 224 | BVBI_P_LCOP_DESTROY_isr((owner),owner_link,(freelist),counted_link); \ |
|---|
| 225 | BKNI_LeaveCriticalSection(); \ |
|---|
| 226 | } while (0) |
|---|
| 227 | |
|---|
| 228 | /* |
|---|
| 229 | * Summary: |
|---|
| 230 | * ------- |
|---|
| 231 | * Operation: write. |
|---|
| 232 | * |
|---|
| 233 | * Example: |
|---|
| 234 | * ------- |
|---|
| 235 | * struct My_counted_object { |
|---|
| 236 | * ... |
|---|
| 237 | * BVBI_P_LCOP_COUNTED_OBJECT(My_counted_object) linkc; |
|---|
| 238 | * }; |
|---|
| 239 | * struct My_owner_object { |
|---|
| 240 | * ... |
|---|
| 241 | * BVBI_P_LCOP_OWNERPROP(My_counted_object) linko; |
|---|
| 242 | * }; |
|---|
| 243 | * BVBI_P_LCOP_COUNTEDPROP(My_counted_object) freelist; |
|---|
| 244 | * struct My_owner_object owner; |
|---|
| 245 | * ... |
|---|
| 246 | * BVBI_P_LCOP_WRITE_isr (&owner, linko, &freelist, linkc); |
|---|
| 247 | */ |
|---|
| 248 | #define BVBI_P_LCOP_WRITE_isr(owner,owner_link,freelist,counted_link) \ |
|---|
| 249 | BVBI_P_LCOP_DESTROY_isr((owner),owner_link,(freelist),counted_link) |
|---|
| 250 | #define BVBI_P_LCOP_WRITE(owner,owner_link,freelist,counted_link) \ |
|---|
| 251 | do { \ |
|---|
| 252 | BKNI_EnterCriticalSection(); \ |
|---|
| 253 | BVBI_P_LCOP_WRITE_isr((owner),owner_link,(freelist),counted_link); \ |
|---|
| 254 | BKNI_LeaveCriticalSection(); \ |
|---|
| 255 | } while (0) |
|---|
| 256 | |
|---|
| 257 | /* |
|---|
| 258 | * Summary: |
|---|
| 259 | * ------- |
|---|
| 260 | * Operation: Copy |
|---|
| 261 | * |
|---|
| 262 | * Example: |
|---|
| 263 | * ------- |
|---|
| 264 | * struct My_counted_object_from { |
|---|
| 265 | * ... |
|---|
| 266 | * BVBI_P_LCOP_COUNTED_OBJECT(My_counted_object) fromlink; |
|---|
| 267 | * }; |
|---|
| 268 | * struct My_counted_object_to { |
|---|
| 269 | * ... |
|---|
| 270 | * BVBI_P_LCOP_COUNTED_OBJECT(My_counted_object) tolink; |
|---|
| 271 | * }; |
|---|
| 272 | * struct My_owner_object { |
|---|
| 273 | * ... |
|---|
| 274 | * BVBI_P_LCOP_OWNERPROP(My_counted_object) linko; |
|---|
| 275 | * }; |
|---|
| 276 | * BVBI_P_LCOP_COUNTEDPROP(My_counted_object) freelist; |
|---|
| 277 | * struct My_owner_object_from from_owner; |
|---|
| 278 | * struct My_owner_object_to to_owner; |
|---|
| 279 | * ... |
|---|
| 280 | * BVBI_P_LCOP_COPY_isr ( |
|---|
| 281 | * &from_owner, fromlink, &to_owner, tolink, &freelist, linkc); |
|---|
| 282 | */ |
|---|
| 283 | #define \ |
|---|
| 284 | BVBI_P_LCOP_COPY_isr(\ |
|---|
| 285 | from_owner,from_link,to_owner,to_link,freelist,counted_link) \ |
|---|
| 286 | do { \ |
|---|
| 287 | if (((to_owner)->to_link.l_co) != ((from_owner)->from_link.l_co)) \ |
|---|
| 288 | { \ |
|---|
| 289 | BDBG_ASSERT ((from_owner)->from_link.l_co->counted_link.i_count); \ |
|---|
| 290 | BDBG_ASSERT ((to_owner)->to_link.l_co->counted_link.i_count); \ |
|---|
| 291 | if (--((to_owner)->to_link.l_co->counted_link.i_count) == 0) \ |
|---|
| 292 | { \ |
|---|
| 293 | (to_owner)->to_link.l_co->counted_link.l_co = (freelist)->l_co; \ |
|---|
| 294 | (freelist)->l_co = (to_owner)->to_link.l_co; \ |
|---|
| 295 | } \ |
|---|
| 296 | (to_owner)->to_link.l_co = (from_owner)->from_link.l_co; \ |
|---|
| 297 | ++((from_owner)->from_link.l_co->counted_link.i_count); \ |
|---|
| 298 | } \ |
|---|
| 299 | } while (0) |
|---|
| 300 | #define \ |
|---|
| 301 | BVBI_P_LCOP_COPY(\ |
|---|
| 302 | from_owner,from_link,to_owner,to_link,freelist,counted_link) \ |
|---|
| 303 | do { \ |
|---|
| 304 | BKNI_EnterCriticalSection(); \ |
|---|
| 305 | BVBI_P_LCOP_COPY_isr(\ |
|---|
| 306 | (from_owner),from_link,(to_owner),to_link,(freelist),counted_link); \ |
|---|
| 307 | BKNI_LeaveCriticalSection(); \ |
|---|
| 308 | } while (0) |
|---|
| 309 | |
|---|
| 310 | /* |
|---|
| 311 | * Summary: |
|---|
| 312 | * ------- |
|---|
| 313 | * Operation: The transfer sequence. Operations copy, then write. |
|---|
| 314 | * |
|---|
| 315 | * Example: |
|---|
| 316 | * ------- |
|---|
| 317 | * struct My_counted_object_from { |
|---|
| 318 | * ... |
|---|
| 319 | * BVBI_P_LCOP_COUNTED_OBJECT(My_counted_object) fromlink; |
|---|
| 320 | * }; |
|---|
| 321 | * struct My_counted_object_to { |
|---|
| 322 | * ... |
|---|
| 323 | * BVBI_P_LCOP_COUNTED_OBJECT(My_counted_object) tolink; |
|---|
| 324 | * struct My_owner_object { |
|---|
| 325 | * ... |
|---|
| 326 | * BVBI_P_LCOP_OWNERPROP(My_counted_object) linko; |
|---|
| 327 | * }; |
|---|
| 328 | * BVBI_P_LCOP_COUNTEDPROP(My_counted_object) freelist; |
|---|
| 329 | * struct My_owner_object_from from_owner; |
|---|
| 330 | * struct My_owner_object_to to_owner; |
|---|
| 331 | * ... |
|---|
| 332 | * BVBI_P_LCOP_TRANSFER ( |
|---|
| 333 | * &from_owner, fromlink, &to_owner, tolink, &freelist, linkc); |
|---|
| 334 | */ |
|---|
| 335 | #define \ |
|---|
| 336 | BVBI_P_LCOP_TRANSFER_isr(\ |
|---|
| 337 | from_owner,from_link,to_owner,to_link,freelist,counted_link) \ |
|---|
| 338 | do { \ |
|---|
| 339 | BVBI_P_LCOP_COPY_isr(\ |
|---|
| 340 | (from_owner),from_link,(to_owner),to_link,(freelist),counted_link); \ |
|---|
| 341 | BVBI_P_LCOP_WRITE_isr(\ |
|---|
| 342 | (from_owner),from_link,(freelist),counted_link); \ |
|---|
| 343 | } while (0) |
|---|
| 344 | #define \ |
|---|
| 345 | BVBI_P_LCOP_TRANSFER(\ |
|---|
| 346 | from_owner,from_link,to_owner,to_link,freelist,counted_link) \ |
|---|
| 347 | do { \ |
|---|
| 348 | BKNI_EnterCriticalSection(); \ |
|---|
| 349 | BVBI_P_LCOP_TRANSFER_isr(\ |
|---|
| 350 | (from_owner),from_link,(to_owner),to_link,(freelist),counted_link); \ |
|---|
| 351 | BKNI_LeaveCriticalSection(); \ |
|---|
| 352 | } while (0) |
|---|
| 353 | |
|---|
| 354 | /* |
|---|
| 355 | * Here is the test program for this set of tools. The following preprocessor |
|---|
| 356 | * symbol BVBI_P_LCOP_TEST_PROGRAM should never be defined. |
|---|
| 357 | */ |
|---|
| 358 | #ifdef BVBI_P_LCOP_TEST_PROGRAM /** { **/ |
|---|
| 359 | |
|---|
| 360 | #include <stdlib.h> |
|---|
| 361 | #include <stdio.h> |
|---|
| 362 | #include <assert.h> |
|---|
| 363 | #define NULL (0x0) |
|---|
| 364 | #include "bvbi_lcop.h" |
|---|
| 365 | |
|---|
| 366 | #define MALLOC(struct_tag) \ |
|---|
| 367 | ((struct struct_tag*)malloc (sizeof(struct struct_tag))) |
|---|
| 368 | #define FREE(object) (free ((void*)object)); |
|---|
| 369 | #define BDBG_ASSERT(cond) (assert(cond)) |
|---|
| 370 | |
|---|
| 371 | /* |
|---|
| 372 | * NOTE: these two typedefs replace use of float and double, which cause |
|---|
| 373 | * problems for automatic software checkers. |
|---|
| 374 | */ |
|---|
| 375 | typedef struct |
|---|
| 376 | { |
|---|
| 377 | int whatever[10]; |
|---|
| 378 | } Wongo; |
|---|
| 379 | typedef struct |
|---|
| 380 | { |
|---|
| 381 | char whomever[20]; |
|---|
| 382 | } Tongo; |
|---|
| 383 | |
|---|
| 384 | struct My_counted |
|---|
| 385 | { |
|---|
| 386 | int sn; |
|---|
| 387 | int version; |
|---|
| 388 | Wongo fff[1024]; |
|---|
| 389 | BVBI_P_LCOP_COUNTEDPROP(My_counted) linkc; |
|---|
| 390 | int iii[88]; |
|---|
| 391 | }; |
|---|
| 392 | |
|---|
| 393 | struct My_owner |
|---|
| 394 | { |
|---|
| 395 | Tongo ggg[99]; |
|---|
| 396 | BVBI_P_LCOP_OWNERPROP(My_counted) linko; |
|---|
| 397 | long jjj[24]; |
|---|
| 398 | }; |
|---|
| 399 | |
|---|
| 400 | static BVBI_P_LCOP_OWNERPROP(My_counted) fl; |
|---|
| 401 | |
|---|
| 402 | int main (int argc, char* argv[]) |
|---|
| 403 | { |
|---|
| 404 | struct My_counted* c1; |
|---|
| 405 | struct My_counted* c2; |
|---|
| 406 | struct My_counted* c3; |
|---|
| 407 | struct My_owner* o1; |
|---|
| 408 | struct My_owner* o2; |
|---|
| 409 | struct My_owner* o3; |
|---|
| 410 | struct My_counted* cn; |
|---|
| 411 | int version = 0; |
|---|
| 412 | int sn = 0; |
|---|
| 413 | |
|---|
| 414 | BVBI_P_LCOP_INITFREELIST_isr (&fl); |
|---|
| 415 | |
|---|
| 416 | /* Create object 1 */ |
|---|
| 417 | o1 = MALLOC (My_owner); |
|---|
| 418 | c1 = MALLOC (My_counted); |
|---|
| 419 | c1->sn = ++sn; |
|---|
| 420 | c1->version = ++version; |
|---|
| 421 | BVBI_P_LCOP_CREATE_isr (o1, linko, c1, linkc); |
|---|
| 422 | cn = BVBI_P_LCOP_GET_isr (o1, linko); |
|---|
| 423 | printf ("After create, object 1 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 424 | |
|---|
| 425 | /* Create object 2 */ |
|---|
| 426 | o2 = MALLOC (My_owner); |
|---|
| 427 | c2 = MALLOC (My_counted); |
|---|
| 428 | c2->sn = ++sn; |
|---|
| 429 | c2->version = ++version; |
|---|
| 430 | BVBI_P_LCOP_CREATE_isr (o2, linko, c2, linkc); |
|---|
| 431 | cn = BVBI_P_LCOP_GET_isr (o2, linko); |
|---|
| 432 | printf ("After create, object 2 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 433 | |
|---|
| 434 | /* Create object 3 */ |
|---|
| 435 | o3 = MALLOC (My_owner); |
|---|
| 436 | c3 = MALLOC (My_counted); |
|---|
| 437 | c3->sn = ++sn; |
|---|
| 438 | c3->version = ++version; |
|---|
| 439 | BVBI_P_LCOP_CREATE_isr (o3, linko, c3, linkc); |
|---|
| 440 | cn = BVBI_P_LCOP_GET_isr (o3, linko); |
|---|
| 441 | printf ("After create, object 3 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 442 | |
|---|
| 443 | /* Write (modify) object 1 */ |
|---|
| 444 | BVBI_P_LCOP_WRITE_isr (o1, linko, &fl, linkc); |
|---|
| 445 | cn = BVBI_P_LCOP_GET_isr (o1, linko); |
|---|
| 446 | cn->version = ++version; |
|---|
| 447 | cn = BVBI_P_LCOP_GET_isr (o1, linko); |
|---|
| 448 | printf ("After write, object 1 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 449 | cn = BVBI_P_LCOP_GET_isr (o2, linko); |
|---|
| 450 | printf (" object 2 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 451 | |
|---|
| 452 | /* Copy object 1 to object 2 */ |
|---|
| 453 | BVBI_P_LCOP_COPY_isr (o1, linko, o2, linko, &fl, linkc); |
|---|
| 454 | cn = BVBI_P_LCOP_GET_isr (o1, linko); |
|---|
| 455 | printf ("After copy, object 1 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 456 | cn = BVBI_P_LCOP_GET_isr (o2, linko); |
|---|
| 457 | printf (" object 2 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 458 | |
|---|
| 459 | /* Copy object 2 to object 3 */ |
|---|
| 460 | BVBI_P_LCOP_COPY_isr (o2, linko, o3, linko, &fl, linkc); |
|---|
| 461 | cn = BVBI_P_LCOP_GET_isr (o2, linko); |
|---|
| 462 | printf ("After copy, object 2 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 463 | cn = BVBI_P_LCOP_GET_isr (o3, linko); |
|---|
| 464 | printf (" object 3 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 465 | |
|---|
| 466 | /* Transfer object 2 to object 1, then modify object 2. */ |
|---|
| 467 | BVBI_P_LCOP_TRANSFER_isr (o2, linko, o1, linko, &fl, linkc); |
|---|
| 468 | cn = BVBI_P_LCOP_GET_isr (o2, linko); |
|---|
| 469 | cn->version = ++version; |
|---|
| 470 | cn = BVBI_P_LCOP_GET_isr (o1, linko); |
|---|
| 471 | printf ( |
|---|
| 472 | "After transfer, object 1 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 473 | cn = BVBI_P_LCOP_GET_isr (o2, linko); |
|---|
| 474 | printf ( |
|---|
| 475 | " object 2 sn %d, version %d\n", cn->sn, cn->version); |
|---|
| 476 | |
|---|
| 477 | BVBI_P_LCOP_DESTROY_isr (o1, linko, &fl, linkc); |
|---|
| 478 | FREE (BVBI_P_LCOP_GET_isr (o1, linko)); |
|---|
| 479 | FREE (o1); |
|---|
| 480 | |
|---|
| 481 | BVBI_P_LCOP_DESTROY_isr (o2, linko, &fl, linkc); |
|---|
| 482 | FREE (BVBI_P_LCOP_GET_isr (o2, linko)); |
|---|
| 483 | FREE (o2); |
|---|
| 484 | |
|---|
| 485 | BVBI_P_LCOP_DESTROY_isr (o3, linko, &fl, linkc); |
|---|
| 486 | FREE (BVBI_P_LCOP_GET_isr (o3, linko)); |
|---|
| 487 | FREE (o3); |
|---|
| 488 | |
|---|
| 489 | return 0; |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | #endif /** } BVBI_P_LCOP_TEST_PROGRAM **/ |
|---|
| 493 | |
|---|
| 494 | #endif /** BVBI_LCOP_H__ */ |
|---|