1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851
|
/* hazardpointer.c generated by valac 0.52.0, the Vala compiler
* generated from hazardpointer.vala, do not modify */
/* hazardpointer.vala
*
* Copyright (C) 2011 Maciej Piechotka
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Maciej Piechotka <uzytkownik2@gmail.com>
*/
#include "gee.h"
#include <glib.h>
#include <glib-object.h>
#include <free.h>
#include <string.h>
typedef struct _GeeHazardPointerNode GeeHazardPointerNode;
typedef struct _GeeHazardPointerFreeNode GeeHazardPointerFreeNode;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_thread_unref0(var) ((var == NULL) ? NULL : (var = (g_thread_unref (var), NULL)))
#define _gee_hazard_pointer_context_free0(var) ((var == NULL) ? NULL : (var = (gee_hazard_pointer_context_free (var), NULL)))
typedef struct _Block10Data Block10Data;
#define _gee_hazard_pointer_free0(var) ((var == NULL) ? NULL : (var = (gee_hazard_pointer_free (var), NULL)))
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
struct _Block10Data {
int _ref_count_;
GeeCollection* to_free;
};
struct _GeeHazardPointerFreeNode {
void* pointer;
GDestroyNotify destroy_notify;
};
struct _GeeHazardPointerNode {
GeeHazardPointerNode* _next;
gint _active;
void* _hazard;
};
extern gint gee_hazard_pointer__default_policy;
extern gint gee_hazard_pointer__thread_exit_policy;
extern GStaticMutex gee_hazard_pointer__queue_mutex;
extern GeeQueue* gee_hazard_pointer__queue;
extern GeeArrayList* gee_hazard_pointer__global_to_free;
extern gint gee_hazard_pointer_release_policy;
extern GeeHazardPointerNode* gee_hazard_pointer__head;
GeeHazardPointerNode* gee_hazard_pointer__head = NULL;
gint gee_hazard_pointer__default_policy = (gint) GEE_HAZARD_POINTER_POLICY_TRY_FREE;
gint gee_hazard_pointer__thread_exit_policy = (gint) GEE_HAZARD_POINTER_POLICY_RELEASE;
gint gee_hazard_pointer_release_policy = 0;
GeeQueue* gee_hazard_pointer__queue = NULL;
GStaticMutex gee_hazard_pointer__queue_mutex = G_STATIC_MUTEX_INIT;
GeeArrayList* gee_hazard_pointer__global_to_free = NULL;
static guint gee_hazard_pointer_context_THRESHOLD;
extern GStaticPrivate gee_hazard_pointer_context__current_context;
GStaticPrivate gee_hazard_pointer_context__current_context = G_STATIC_PRIVATE_INIT;
extern GStaticPrivate gee_hazard_pointer_context__root_context;
GStaticPrivate gee_hazard_pointer_context__root_context = G_STATIC_PRIVATE_INIT;
static guint gee_hazard_pointer_context_THRESHOLD = (guint) 10;
static void gee_hazard_pointer_instance_init (GeeHazardPointer * self);
G_GNUC_INTERNAL void gee_hazard_pointer_node_free (GeeHazardPointerNode * self);
G_GNUC_INTERNAL void gee_hazard_pointer_node_release (GeeHazardPointerNode* self);
G_GNUC_INTERNAL void gee_hazard_pointer_free_node_free (GeeHazardPointerFreeNode * self);
G_GNUC_INTERNAL gboolean gee_hazard_pointer_policy_perform (GeeHazardPointerPolicy self,
GeeArrayList* * to_free);
G_GNUC_INTERNAL gboolean gee_hazard_pointer_try_free (GeeArrayList* to_free);
G_GNUC_INTERNAL void gee_hazard_pointer_release_policy_ensure_start (void);
static void gee_hazard_pointer_release_policy_start (GeeHazardPointerReleasePolicy _self_);
static gboolean ___lambda54_ (void);
static inline void gee_hazard_pointer_release_policy_pull_from_queue (GeeCollection* to_free,
gboolean do_lock);
static gpointer ____lambda54__gthread_func (gpointer self);
static gboolean ___lambda56_ (void);
static void gee_hazard_pointer_release_policy_swap (GType t_type,
GBoxedCopyFunc t_dup_func,
GDestroyNotify t_destroy_func,
gpointer* a,
gpointer* b);
static gboolean ____lambda56__gsource_func (gpointer self);
static Block10Data* block10_data_ref (Block10Data* _data10_);
static void block10_data_unref (void * _userdata_);
static gboolean ___lambda55_ (Block10Data* _data10_,
GeeArrayList* x);
static gboolean ____lambda55__gee_forall_func (gpointer g,
gpointer self);
G_GNUC_INTERNAL GeeHazardPointerNode* gee_hazard_pointer_acquire (void);
G_GNUC_INTERNAL void gee_hazard_pointer_node_set (GeeHazardPointerNode* self,
void* ptr);
G_GNUC_INTERNAL GeeHazardPointer* gee_hazard_pointer_new_from_node (GeeHazardPointerNode* node);
G_GNUC_INTERNAL GeeHazardPointerContext* gee_hazard_pointer_context_get_current_context (void);
G_GNUC_INTERNAL void gee_hazard_pointer_context_release_ptr (GeeHazardPointerContext* self,
void* ptr,
GDestroyNotify notify);
G_GNUC_INTERNAL void* gee_hazard_pointer_node_get (GeeHazardPointerNode* self,
gboolean safe);
G_GNUC_INTERNAL GeeHazardPointerNode* gee_hazard_pointer_get_head (void);
G_GNUC_INTERNAL GeeHazardPointerNode* gee_hazard_pointer_node_get_next (GeeHazardPointerNode* self);
G_GNUC_INTERNAL gboolean gee_hazard_pointer_node_activate (GeeHazardPointerNode* self);
G_GNUC_INTERNAL GeeHazardPointerNode* gee_hazard_pointer_node_new (void);
G_GNUC_INTERNAL void gee_hazard_pointer_node_set_next (GeeHazardPointerNode* self,
GeeHazardPointerNode* next);
static void gee_hazard_pointer_context_instance_init (GeeHazardPointerContext * self);
static GeeHazardPointerPolicy* _gee_hazard_pointer_policy_dup (GeeHazardPointerPolicy* self);
G_GNUC_INTERNAL GeeHazardPointerFreeNode* gee_hazard_pointer_free_node_new (void);
static void gee_hazard_pointer_free_node_instance_init (GeeHazardPointerFreeNode * self);
static void gee_hazard_pointer_node_instance_init (GeeHazardPointerNode * self);
G_GNUC_INTERNAL gboolean gee_hazard_pointer_node_is_active (GeeHazardPointerNode* self);
/**
* Policy determines what happens on exit from Context.
*/
/**
* Checks if the policy is concrete or if it depends on global variables.
*
* @return ``true`` if this policy does not depend on global variables
*/
gboolean
gee_hazard_pointer_policy_is_concrete (GeeHazardPointerPolicy self)
{
gboolean result = FALSE;
switch (self) {
case GEE_HAZARD_POINTER_POLICY_DEFAULT:
case GEE_HAZARD_POINTER_POLICY_THREAD_EXIT:
{
result = FALSE;
return result;
}
case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
case GEE_HAZARD_POINTER_POLICY_FREE:
case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
case GEE_HAZARD_POINTER_POLICY_RELEASE:
{
result = TRUE;
return result;
}
default:
{
g_assert_not_reached ();
}
}
}
/**
* Checks if policy blocks or is lock-free.
* Please note that it works on a concrete policy only.
*
* @return ``true`` if the policy may block the thread.
*/
gboolean
gee_hazard_pointer_policy_is_blocking (GeeHazardPointerPolicy self)
{
gboolean result = FALSE;
_vala_return_val_if_fail (gee_hazard_pointer_policy_is_concrete (self), "this.is_concrete ()", FALSE);
switch (self) {
case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
{
result = FALSE;
return result;
}
case GEE_HAZARD_POINTER_POLICY_FREE:
case GEE_HAZARD_POINTER_POLICY_RELEASE:
{
result = TRUE;
return result;
}
default:
{
g_assert_not_reached ();
}
}
}
/**
* Checks if policy guarantees freeing all elements.
* Please note that it works on a concrete policy only.
*
* @return ``true`` if the policy guarantees freeing all elements.
*/
gboolean
gee_hazard_pointer_policy_is_safe (GeeHazardPointerPolicy self)
{
gboolean result = FALSE;
_vala_return_val_if_fail (gee_hazard_pointer_policy_is_concrete (self), "this.is_concrete ()", FALSE);
switch (self) {
case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
{
result = FALSE;
return result;
}
case GEE_HAZARD_POINTER_POLICY_FREE:
case GEE_HAZARD_POINTER_POLICY_RELEASE:
{
result = TRUE;
return result;
}
default:
{
g_assert_not_reached ();
}
}
}
/**
* Finds concrete policy which corresponds to given policy.
*
* @return Policy that corresponds to given policy at given time in given thread.
*/
GeeHazardPointerPolicy
gee_hazard_pointer_policy_to_concrete (GeeHazardPointerPolicy self)
{
GeeHazardPointerPolicy result = 0;
switch (self) {
case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
case GEE_HAZARD_POINTER_POLICY_FREE:
case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
case GEE_HAZARD_POINTER_POLICY_RELEASE:
{
GeeHazardPointerPolicy _tmp0_;
result = self;
_tmp0_ = result;
_vala_warn_if_fail (gee_hazard_pointer_policy_is_concrete (_tmp0_), "result.is_concrete ()");
return result;
}
case GEE_HAZARD_POINTER_POLICY_DEFAULT:
{
gint _tmp1_;
GeeHazardPointerPolicy _tmp2_;
_tmp1_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer__default_policy));
result = (GeeHazardPointerPolicy) _tmp1_;
_tmp2_ = result;
_vala_warn_if_fail (gee_hazard_pointer_policy_is_concrete (_tmp2_), "result.is_concrete ()");
return result;
}
case GEE_HAZARD_POINTER_POLICY_THREAD_EXIT:
{
gint _tmp3_;
GeeHazardPointerPolicy _tmp4_;
_tmp3_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer__thread_exit_policy));
result = (GeeHazardPointerPolicy) _tmp3_;
_tmp4_ = result;
_vala_warn_if_fail (gee_hazard_pointer_policy_is_concrete (_tmp4_), "result.is_concrete ()");
return result;
}
default:
{
g_assert_not_reached ();
}
}
}
/**
* Runs the policy.
* @param to_free List containing elements to free.
* @return Non-empty list of not freed elements or ``null`` if all elements have been disposed.
*/
G_GNUC_INTERNAL gboolean
gee_hazard_pointer_policy_perform (GeeHazardPointerPolicy self,
GeeArrayList* * to_free)
{
gboolean result = FALSE;
g_return_val_if_fail (*to_free != NULL, FALSE);
switch (gee_hazard_pointer_policy_to_concrete (self)) {
case GEE_HAZARD_POINTER_POLICY_TRY_FREE:
{
result = gee_hazard_pointer_try_free (*to_free);
return result;
}
case GEE_HAZARD_POINTER_POLICY_FREE:
{
while (TRUE) {
if (!gee_hazard_pointer_try_free (*to_free)) {
break;
}
g_thread_yield ();
}
break;
}
case GEE_HAZARD_POINTER_POLICY_TRY_RELEASE:
{
gee_hazard_pointer_release_policy_ensure_start ();
if (g_static_mutex_trylock (&gee_hazard_pointer__queue_mutex)) {
GeeQueue* _tmp0_;
GeeArrayList* _tmp1_;
GeeArrayList* _tmp2_;
_tmp0_ = gee_hazard_pointer__queue;
_tmp1_ = *to_free;
*to_free = NULL;
_tmp2_ = _tmp1_;
gee_queue_offer (_tmp0_, _tmp2_);
_g_object_unref0 (_tmp2_);
g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
result = TRUE;
return result;
} else {
result = FALSE;
return result;
}
}
case GEE_HAZARD_POINTER_POLICY_RELEASE:
{
GeeQueue* _tmp3_;
GeeArrayList* _tmp4_;
GeeArrayList* _tmp5_;
gee_hazard_pointer_release_policy_ensure_start ();
g_static_mutex_lock (&gee_hazard_pointer__queue_mutex);
_tmp3_ = gee_hazard_pointer__queue;
_tmp4_ = *to_free;
*to_free = NULL;
_tmp5_ = _tmp4_;
gee_queue_offer (_tmp3_, _tmp5_);
_g_object_unref0 (_tmp5_);
g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
result = TRUE;
return result;
}
default:
{
g_assert_not_reached ();
}
}
result = FALSE;
return result;
}
static GType
gee_hazard_pointer_policy_get_type_once (void)
{
static const GEnumValue values[] = {{GEE_HAZARD_POINTER_POLICY_DEFAULT, "GEE_HAZARD_POINTER_POLICY_DEFAULT", "default"}, {GEE_HAZARD_POINTER_POLICY_THREAD_EXIT, "GEE_HAZARD_POINTER_POLICY_THREAD_EXIT", "thread-exit"}, {GEE_HAZARD_POINTER_POLICY_TRY_FREE, "GEE_HAZARD_POINTER_POLICY_TRY_FREE", "try-free"}, {GEE_HAZARD_POINTER_POLICY_FREE, "GEE_HAZARD_POINTER_POLICY_FREE", "free"}, {GEE_HAZARD_POINTER_POLICY_TRY_RELEASE, "GEE_HAZARD_POINTER_POLICY_TRY_RELEASE", "try-release"}, {GEE_HAZARD_POINTER_POLICY_RELEASE, "GEE_HAZARD_POINTER_POLICY_RELEASE", "release"}, {0, NULL, NULL}};
GType gee_hazard_pointer_policy_type_id;
gee_hazard_pointer_policy_type_id = g_enum_register_static ("GeeHazardPointerPolicy", values);
return gee_hazard_pointer_policy_type_id;
}
GType
gee_hazard_pointer_policy_get_type (void)
{
static volatile gsize gee_hazard_pointer_policy_type_id__volatile = 0;
if (g_once_init_enter (&gee_hazard_pointer_policy_type_id__volatile)) {
GType gee_hazard_pointer_policy_type_id;
gee_hazard_pointer_policy_type_id = gee_hazard_pointer_policy_get_type_once ();
g_once_init_leave (&gee_hazard_pointer_policy_type_id__volatile, gee_hazard_pointer_policy_type_id);
}
return gee_hazard_pointer_policy_type_id__volatile;
}
/**
* Release policy determines what happens with object freed by Policy.TRY_RELEASE
* and Policy.RELEASE.
*/
static gboolean
___lambda54_ (void)
{
GeeHazardPointerContext* ctx = NULL;
GeeHazardPointerPolicy _tmp0_;
GeeHazardPointerContext* _tmp1_;
_tmp0_ = GEE_HAZARD_POINTER_POLICY_TRY_FREE;
_tmp1_ = gee_hazard_pointer_context_new (&_tmp0_);
ctx = _tmp1_;
while (TRUE) {
GeeHazardPointerContext* _tmp2_;
GeeArrayList* _tmp3_;
GeeHazardPointerContext* _tmp4_;
GeeArrayList* _tmp5_;
gboolean _tmp6_;
gboolean _tmp7_;
GeeHazardPointerContext* _tmp8_;
GeeHazardPointerContext* _tmp9_;
GeeArrayList* _tmp10_;
gboolean _tmp11_;
gboolean _tmp12_;
g_thread_yield ();
_tmp2_ = ctx;
_tmp3_ = _tmp2_->_to_free;
_tmp4_ = ctx;
_tmp5_ = _tmp4_->_to_free;
_tmp6_ = gee_collection_get_is_empty ((GeeCollection*) _tmp5_);
_tmp7_ = _tmp6_;
gee_hazard_pointer_release_policy_pull_from_queue ((GeeCollection*) _tmp3_, _tmp7_);
_tmp8_ = ctx;
gee_hazard_pointer_context_try_free (_tmp8_);
_tmp9_ = ctx;
_tmp10_ = _tmp9_->_to_free;
_tmp11_ = gee_collection_get_is_empty ((GeeCollection*) _tmp10_);
_tmp12_ = _tmp11_;
if (_tmp12_) {
g_usleep ((gulong) 100000);
}
}
}
static gpointer
____lambda54__gthread_func (gpointer self)
{
gpointer result;
result = (gpointer) ((gintptr) ___lambda54_ ());
return result;
}
static gboolean
___lambda56_ (void)
{
GeeHazardPointerContext* ctx = NULL;
GeeHazardPointerPolicy _tmp0_;
GeeHazardPointerContext* _tmp1_;
GeeArrayList* _tmp2_;
gboolean result = FALSE;
_tmp0_ = GEE_HAZARD_POINTER_POLICY_TRY_FREE;
_tmp1_ = gee_hazard_pointer_context_new (&_tmp0_);
ctx = _tmp1_;
gee_hazard_pointer_release_policy_swap (GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, &gee_hazard_pointer__global_to_free, &ctx->_to_free);
_tmp2_ = ctx->_to_free;
gee_hazard_pointer_release_policy_pull_from_queue ((GeeCollection*) _tmp2_, FALSE);
gee_hazard_pointer_context_try_free (ctx);
gee_hazard_pointer_release_policy_swap (GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, &gee_hazard_pointer__global_to_free, &ctx->_to_free);
result = TRUE;
_gee_hazard_pointer_context_free0 (ctx);
return result;
}
static gboolean
____lambda56__gsource_func (gpointer self)
{
gboolean result;
result = ___lambda56_ ();
return result;
}
static void
gee_hazard_pointer_release_policy_start (GeeHazardPointerReleasePolicy _self_)
{
switch (_self_) {
case GEE_HAZARD_POINTER_RELEASE_POLICY_HELPER_THREAD:
{
GThread* _tmp0_;
GThread* _tmp1_;
_tmp0_ = g_thread_new ("<<libgee hazard pointer>>", ____lambda54__gthread_func, NULL);
_tmp1_ = _tmp0_;
_g_thread_unref0 (_tmp1_);
break;
}
case GEE_HAZARD_POINTER_RELEASE_POLICY_MAIN_LOOP:
{
GeeArrayList* _tmp2_;
_tmp2_ = gee_array_list_new (G_TYPE_POINTER, NULL, NULL, NULL, NULL, NULL);
_g_object_unref0 (gee_hazard_pointer__global_to_free);
gee_hazard_pointer__global_to_free = _tmp2_;
g_idle_add_full (G_PRIORITY_LOW, ____lambda56__gsource_func, NULL, NULL);
break;
}
default:
{
g_assert_not_reached ();
}
}
}
static void
gee_hazard_pointer_release_policy_swap (GType t_type,
GBoxedCopyFunc t_dup_func,
GDestroyNotify t_destroy_func,
gpointer* a,
gpointer* b)
{
gpointer tmp = NULL;
gpointer _tmp0_;
gpointer _tmp1_;
gpointer _tmp2_;
_tmp0_ = *a;
*a = NULL;
tmp = _tmp0_;
_tmp1_ = *b;
*b = NULL;
(((*a) == NULL) || (t_destroy_func == NULL)) ? NULL : (*a = (t_destroy_func (*a), NULL));
*a = _tmp1_;
_tmp2_ = tmp;
tmp = NULL;
(((*b) == NULL) || (t_destroy_func == NULL)) ? NULL : (*b = (t_destroy_func (*b), NULL));
*b = _tmp2_;
((tmp == NULL) || (t_destroy_func == NULL)) ? NULL : (tmp = (t_destroy_func (tmp), NULL));
}
/**
* Ensures that helper methods are started.
*/
G_GNUC_INTERNAL inline void
gee_hazard_pointer_release_policy_ensure_start (void)
{
gint policy = 0;
gint _tmp0_;
_tmp0_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer_release_policy));
policy = _tmp0_;
if ((policy & (1 << ((sizeof (gint) * 8) - 1))) != 0) {
return;
}
if (g_static_mutex_trylock (&gee_hazard_pointer__queue_mutex)) {
gint _tmp1_;
_tmp1_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer_release_policy));
policy = _tmp1_;
if ((policy & (1 << ((sizeof (gint) * 8) - 1))) == 0) {
GeeLinkedList* _tmp2_;
gint _tmp3_;
_tmp2_ = gee_linked_list_new (GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
_g_object_unref0 (gee_hazard_pointer__queue);
gee_hazard_pointer__queue = (GeeQueue*) _tmp2_;
_tmp3_ = g_atomic_int_add ((volatile gint *) (&gee_hazard_pointer_release_policy), (gint) (1 << ((sizeof (gint) * 8) - 1)));
policy = _tmp3_;
gee_hazard_pointer_release_policy_start ((GeeHazardPointerReleasePolicy) policy);
}
g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
}
}
static gpointer
_g_object_ref0 (gpointer self)
{
return self ? g_object_ref (self) : NULL;
}
static Block10Data*
block10_data_ref (Block10Data* _data10_)
{
g_atomic_int_inc (&_data10_->_ref_count_);
return _data10_;
}
static void
block10_data_unref (void * _userdata_)
{
Block10Data* _data10_;
_data10_ = (Block10Data*) _userdata_;
if (g_atomic_int_dec_and_test (&_data10_->_ref_count_)) {
_g_object_unref0 (_data10_->to_free);
g_slice_free (Block10Data, _data10_);
}
}
static gboolean
___lambda55_ (Block10Data* _data10_,
GeeArrayList* x)
{
gboolean result = FALSE;
g_return_val_if_fail (x != NULL, FALSE);
gee_collection_add_all (_data10_->to_free, (GeeCollection*) x);
result = TRUE;
_g_object_unref0 (x);
return result;
}
static gboolean
____lambda55__gee_forall_func (gpointer g,
gpointer self)
{
gboolean result;
result = ___lambda55_ (self, (GeeArrayList*) g);
return result;
}
static inline void
gee_hazard_pointer_release_policy_pull_from_queue (GeeCollection* to_free,
gboolean do_lock)
{
Block10Data* _data10_;
GeeCollection* _tmp0_;
gboolean locked = FALSE;
g_return_if_fail (to_free != NULL);
_data10_ = g_slice_new0 (Block10Data);
_data10_->_ref_count_ = 1;
_tmp0_ = _g_object_ref0 (to_free);
_g_object_unref0 (_data10_->to_free);
_data10_->to_free = _tmp0_;
locked = do_lock;
if (do_lock) {
g_static_mutex_lock (&gee_hazard_pointer__queue_mutex);
} else {
locked = g_static_mutex_trylock (&gee_hazard_pointer__queue_mutex);
}
if (locked) {
GeeCollection* temp = NULL;
GeeArrayList* _tmp1_;
GeeQueue* _tmp2_;
GeeCollection* _tmp3_;
GeeCollection* _tmp4_;
_tmp1_ = gee_array_list_new (GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
temp = (GeeCollection*) _tmp1_;
_tmp2_ = gee_hazard_pointer__queue;
_tmp3_ = temp;
gee_queue_drain (_tmp2_, _tmp3_, -1);
g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
_tmp4_ = temp;
gee_traversable_foreach ((GeeTraversable*) _tmp4_, ____lambda55__gee_forall_func, _data10_);
_g_object_unref0 (temp);
}
block10_data_unref (_data10_);
_data10_ = NULL;
}
static GType
gee_hazard_pointer_release_policy_get_type_once (void)
{
static const GEnumValue values[] = {{GEE_HAZARD_POINTER_RELEASE_POLICY_HELPER_THREAD, "GEE_HAZARD_POINTER_RELEASE_POLICY_HELPER_THREAD", "helper-thread"}, {GEE_HAZARD_POINTER_RELEASE_POLICY_MAIN_LOOP, "GEE_HAZARD_POINTER_RELEASE_POLICY_MAIN_LOOP", "main-loop"}, {0, NULL, NULL}};
GType gee_hazard_pointer_release_policy_type_id;
gee_hazard_pointer_release_policy_type_id = g_enum_register_static ("GeeHazardPointerReleasePolicy", values);
return gee_hazard_pointer_release_policy_type_id;
}
GType
gee_hazard_pointer_release_policy_get_type (void)
{
static volatile gsize gee_hazard_pointer_release_policy_type_id__volatile = 0;
if (g_once_init_enter (&gee_hazard_pointer_release_policy_type_id__volatile)) {
GType gee_hazard_pointer_release_policy_type_id;
gee_hazard_pointer_release_policy_type_id = gee_hazard_pointer_release_policy_get_type_once ();
g_once_init_leave (&gee_hazard_pointer_release_policy_type_id__volatile, gee_hazard_pointer_release_policy_type_id);
}
return gee_hazard_pointer_release_policy_type_id__volatile;
}
/**
* Creates a hazard pointer for a pointer.
*
* @param ptr Protected pointer
*/
GeeHazardPointer*
gee_hazard_pointer_new (gconstpointer* ptr)
{
GeeHazardPointer* self;
GeeHazardPointerNode* _tmp0_;
GeeHazardPointerNode* _tmp1_;
self = g_slice_new0 (GeeHazardPointer);
gee_hazard_pointer_instance_init (self);
_tmp0_ = gee_hazard_pointer_acquire ();
self->_node = _tmp0_;
_tmp1_ = self->_node;
gee_hazard_pointer_node_set (_tmp1_, (void*) ptr);
return self;
}
/**
* Create a hazard pointer from Node.
*/
G_GNUC_INTERNAL GeeHazardPointer*
gee_hazard_pointer_new_from_node (GeeHazardPointerNode* node)
{
GeeHazardPointer* self;
g_return_val_if_fail (node != NULL, NULL);
self = g_slice_new0 (GeeHazardPointer);
gee_hazard_pointer_instance_init (self);
self->_node = node;
return self;
}
/**
* Gets hazard pointer from atomic pointer safely.
*
* @param aptr Atomic pointer.
* @param mask Mask of bits.
* @param mask_out Result of mask.
* @return Hazard pointer containing the element.
*/
GeeHazardPointer*
gee_hazard_pointer_get_hazard_pointer (GType g_type,
GBoxedCopyFunc g_dup_func,
GDestroyNotify g_destroy_func,
gconstpointer** aptr,
gsize mask,
gsize* mask_out)
{
gsize _vala_mask_out = 0UL;
GeeHazardPointerNode* node = NULL;
GeeHazardPointerNode* _tmp0_;
void* rptr = NULL;
void* ptr = NULL;
void* _tmp9_;
GeeHazardPointer* result = NULL;
_tmp0_ = gee_hazard_pointer_acquire ();
node = _tmp0_;
rptr = NULL;
ptr = NULL;
_vala_mask_out = (gsize) 0;
{
gboolean _tmp1_ = FALSE;
_tmp1_ = TRUE;
while (TRUE) {
void* _tmp4_;
void* _tmp5_;
void* _tmp6_;
GeeHazardPointerNode* _tmp7_;
void* _tmp8_;
if (!_tmp1_) {
void* _tmp2_;
void* _tmp3_;
_tmp2_ = rptr;
_tmp3_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) aptr));
if (!(_tmp2_ != _tmp3_)) {
break;
}
}
_tmp1_ = FALSE;
_tmp4_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) aptr));
rptr = _tmp4_;
_tmp5_ = rptr;
ptr = (void*) (((gsize) _tmp5_) & (~mask));
_tmp6_ = rptr;
_vala_mask_out = ((gsize) _tmp6_) & mask;
_tmp7_ = node;
_tmp8_ = ptr;
gee_hazard_pointer_node_set (_tmp7_, _tmp8_);
}
}
_tmp9_ = ptr;
if (_tmp9_ != NULL) {
GeeHazardPointerNode* _tmp10_;
GeeHazardPointer* _tmp11_;
_tmp10_ = node;
_tmp11_ = gee_hazard_pointer_new_from_node (_tmp10_);
result = _tmp11_;
if (mask_out) {
*mask_out = _vala_mask_out;
}
return result;
} else {
GeeHazardPointerNode* _tmp12_;
_tmp12_ = node;
gee_hazard_pointer_node_release (_tmp12_);
result = NULL;
if (mask_out) {
*mask_out = _vala_mask_out;
}
return result;
}
}
/**
* Copy an object from atomic pointer.
*
* @param aptr Atomic pointer.
* @param mask Mask of flags.
* @param mask_out Result of mask.
* @return A copy of object from atomic pointer.
*/
gpointer
gee_hazard_pointer_get_pointer (GType g_type,
GBoxedCopyFunc g_dup_func,
GDestroyNotify g_destroy_func,
gconstpointer** aptr,
gsize mask,
gsize* mask_out)
{
gsize _vala_mask_out = 0UL;
GeeHazardPointerNode* node = NULL;
GeeHazardPointerNode* _tmp0_;
void* rptr = NULL;
void* ptr = NULL;
gpointer res = NULL;
void* _tmp9_;
gpointer _tmp10_;
GeeHazardPointerNode* _tmp11_;
gpointer result = NULL;
_tmp0_ = gee_hazard_pointer_acquire ();
node = _tmp0_;
rptr = NULL;
ptr = NULL;
_vala_mask_out = (gsize) 0;
{
gboolean _tmp1_ = FALSE;
_tmp1_ = TRUE;
while (TRUE) {
void* _tmp4_;
void* _tmp5_;
void* _tmp6_;
GeeHazardPointerNode* _tmp7_;
void* _tmp8_;
if (!_tmp1_) {
void* _tmp2_;
void* _tmp3_;
_tmp2_ = rptr;
_tmp3_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) aptr));
if (!(_tmp2_ != _tmp3_)) {
break;
}
}
_tmp1_ = FALSE;
_tmp4_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) aptr));
rptr = _tmp4_;
_tmp5_ = rptr;
ptr = (void*) (((gsize) _tmp5_) & (~mask));
_tmp6_ = rptr;
_vala_mask_out = ((gsize) _tmp6_) & mask;
_tmp7_ = node;
_tmp8_ = ptr;
gee_hazard_pointer_node_set (_tmp7_, _tmp8_);
}
}
_tmp9_ = ptr;
_tmp10_ = ((((gconstpointer*) _tmp9_) != NULL) && (g_dup_func != NULL)) ? g_dup_func ((gpointer) ((gconstpointer*) _tmp9_)) : ((gpointer) ((gconstpointer*) _tmp9_));
res = _tmp10_;
_tmp11_ = node;
gee_hazard_pointer_node_release (_tmp11_);
result = res;
if (mask_out) {
*mask_out = _vala_mask_out;
}
return result;
}
/**
* Exchange objects safely.
*
* @param aptr Atomic pointer.
* @param new_ptr New value
* @param mask Mask of flags.
* @param new_mask New mask.
* @param old_mask Previous mask mask.
* @return Hazard pointer containing old value.
*/
GeeHazardPointer*
gee_hazard_pointer_exchange_hazard_pointer (GType g_type,
GBoxedCopyFunc g_dup_func,
GDestroyNotify g_destroy_func,
gconstpointer** aptr,
gpointer new_ptr,
gsize mask,
gsize new_mask,
gsize* old_mask)
{
gsize _vala_old_mask = 0UL;
GeeHazardPointerNode* new_node = NULL;
void* new_rptr = NULL;
gpointer _tmp2_;
GeeHazardPointerNode* node = NULL;
GeeHazardPointerNode* _tmp3_;
void* rptr = NULL;
void* ptr = NULL;
GeeHazardPointerNode* _tmp12_;
void* _tmp14_;
GeeHazardPointer* result = NULL;
new_node = NULL;
if (new_ptr != NULL) {
GeeHazardPointerNode* _tmp0_;
GeeHazardPointerNode* _tmp1_;
_tmp0_ = gee_hazard_pointer_acquire ();
new_node = _tmp0_;
_tmp1_ = new_node;
gee_hazard_pointer_node_set (_tmp1_, new_ptr);
}
_vala_old_mask = (gsize) 0;
_tmp2_ = new_ptr;
new_ptr = NULL;
new_rptr = (void*) (((gsize) _tmp2_) | (mask & new_mask));
_tmp3_ = gee_hazard_pointer_acquire ();
node = _tmp3_;
rptr = NULL;
ptr = NULL;
{
gboolean _tmp4_ = FALSE;
_tmp4_ = TRUE;
while (TRUE) {
void* _tmp7_;
void* _tmp8_;
void* _tmp9_;
GeeHazardPointerNode* _tmp10_;
void* _tmp11_;
if (!_tmp4_) {
void* _tmp5_;
void* _tmp6_;
_tmp5_ = rptr;
_tmp6_ = new_rptr;
if (!(!g_atomic_pointer_compare_and_exchange ((volatile gpointer *) ((void**) aptr), _tmp5_, _tmp6_))) {
break;
}
}
_tmp4_ = FALSE;
_tmp7_ = g_atomic_pointer_get ((volatile gpointer *) ((void**) aptr));
rptr = _tmp7_;
_tmp8_ = rptr;
ptr = (void*) (((gsize) _tmp8_) & (~mask));
_tmp9_ = rptr;
_vala_old_mask = ((gsize) _tmp9_) & mask;
_tmp10_ = node;
_tmp11_ = ptr;
gee_hazard_pointer_node_set (_tmp10_, _tmp11_);
}
}
_tmp12_ = new_node;
if (_tmp12_ != NULL) {
GeeHazardPointerNode* _tmp13_;
_tmp13_ = new_node;
gee_hazard_pointer_node_release (_tmp13_);
}
_tmp14_ = ptr;
if (_tmp14_ != NULL) {
GeeHazardPointerNode* _tmp15_;
GeeHazardPointer* _tmp16_;
_tmp15_ = node;
_tmp16_ = gee_hazard_pointer_new_from_node (_tmp15_);
result = _tmp16_;
((new_ptr == NULL) || (g_destroy_func == NULL)) ? NULL : (new_ptr = (g_destroy_func (new_ptr), NULL));
if (old_mask) {
*old_mask = _vala_old_mask;
}
return result;
} else {
GeeHazardPointerNode* _tmp17_;
_tmp17_ = node;
gee_hazard_pointer_node_release (_tmp17_);
result = NULL;
((new_ptr == NULL) || (g_destroy_func == NULL)) ? NULL : (new_ptr = (g_destroy_func (new_ptr), NULL));
if (old_mask) {
*old_mask = _vala_old_mask;
}
return result;
}
}
/**
* Sets object safely
*
* @param aptr Atomic pointer.
* @param new_ptr New value
* @param mask Mask of flags.
* @param new_mask New mask.
*/
void
gee_hazard_pointer_set_pointer (GType g_type,
GBoxedCopyFunc g_dup_func,
GDestroyNotify g_destroy_func,
gconstpointer** aptr,
gpointer new_ptr,
gsize mask,
gsize new_mask)
{
GeeHazardPointer* ptr = NULL;
gpointer _tmp0_;
GeeHazardPointer* _tmp1_;
GeeHazardPointer* _tmp2_;
_tmp0_ = ((new_ptr != NULL) && (g_dup_func != NULL)) ? g_dup_func ((gpointer) new_ptr) : ((gpointer) new_ptr);
_tmp1_ = gee_hazard_pointer_exchange_hazard_pointer (g_type, (GBoxedCopyFunc) g_dup_func, (GDestroyNotify) g_destroy_func, aptr, _tmp0_, mask, new_mask, NULL);
ptr = _tmp1_;
_tmp2_ = ptr;
if (_tmp2_ != NULL) {
GDestroyNotify notify = NULL;
GDestroyNotify _tmp3_;
GDestroyNotify _tmp4_;
_tmp3_ = gee_utils_free_get_destroy_notify (g_type, (GBoxedCopyFunc) g_dup_func, (GDestroyNotify) g_destroy_func);
notify = _tmp3_;
_tmp4_ = notify;
if (_tmp4_ != NULL) {
GeeHazardPointer* _tmp5_;
GDestroyNotify _tmp6_;
_tmp5_ = ptr;
_tmp6_ = notify;
notify = NULL;
gee_hazard_pointer_release (_tmp5_, _tmp6_);
}
}
_gee_hazard_pointer_free0 (ptr);
((new_ptr == NULL) || (g_destroy_func == NULL)) ? NULL : (new_ptr = (g_destroy_func (new_ptr), NULL));
}
/**
* Exchange objects safely.
*
* @param aptr Atomic pointer.
* @param new_ptr New value
* @param mask Mask of flags.
* @param new_mask New mask.
* @param old_mask Previous mask mask.
* @return Value that was previously stored.
*/
gpointer
gee_hazard_pointer_exchange_pointer (GType g_type,
GBoxedCopyFunc g_dup_func,
GDestroyNotify g_destroy_func,
gconstpointer** aptr,
gpointer new_ptr,
gsize mask,
gsize new_mask,
gsize* old_mask)
{
gsize _vala_old_mask = 0UL;
GeeHazardPointer* ptr = NULL;
gpointer _tmp0_;
gsize _tmp1_ = 0UL;
GeeHazardPointer* _tmp2_;
gconstpointer _tmp3_ = NULL;
GeeHazardPointer* _tmp4_;
gpointer rptr = NULL;
gpointer _tmp7_;
gpointer result = NULL;
_tmp0_ = ((new_ptr != NULL) && (g_dup_func != NULL)) ? g_dup_func ((gpointer) new_ptr) : ((gpointer) new_ptr);
_tmp2_ = gee_hazard_pointer_exchange_hazard_pointer (g_type, (GBoxedCopyFunc) g_dup_func, (GDestroyNotify) g_destroy_func, aptr, _tmp0_, mask, new_mask, &_tmp1_);
_vala_old_mask = _tmp1_;
ptr = _tmp2_;
_tmp4_ = ptr;
if (_tmp4_ != NULL) {
GeeHazardPointer* _tmp5_;
gconstpointer _tmp6_;
_tmp5_ = ptr;
_tmp6_ = gee_hazard_pointer_get (_tmp5_, FALSE);
_tmp3_ = _tmp6_;
} else {
_tmp3_ = NULL;
}
_tmp7_ = ((_tmp3_ != NULL) && (g_dup_func != NULL)) ? g_dup_func ((gpointer) _tmp3_) : ((gpointer) _tmp3_);
rptr = _tmp7_;
result = rptr;
_gee_hazard_pointer_free0 (ptr);
((new_ptr == NULL) || (g_destroy_func == NULL)) ? NULL : (new_ptr = (g_destroy_func (new_ptr), NULL));
if (old_mask) {
*old_mask = _vala_old_mask;
}
return result;
}
/**
* Compares and exchanges objects.
*
* @param aptr Atomic pointer.
* @param old_ptr Old pointer.
* @param _new_ptr New value.
* @param old_mask Old mask.
* @param new_mask New mask.
* @return Value that was previously stored.
*/
gboolean
gee_hazard_pointer_compare_and_exchange_pointer (GType g_type,
GBoxedCopyFunc g_dup_func,
GDestroyNotify g_destroy_func,
gconstpointer** aptr,
gconstpointer old_ptr,
gpointer _new_ptr,
gsize mask,
gsize old_mask,
gsize new_mask)
{
gconstpointer* new_ptr = NULL;
gpointer _tmp0_;
void* new_rptr = NULL;
gconstpointer* _tmp1_;
void* old_rptr = NULL;
gboolean success = FALSE;
void* _tmp2_;
void* _tmp3_;
gboolean result = FALSE;
_tmp0_ = _new_ptr;
_new_ptr = NULL;
new_ptr = _tmp0_;
_tmp1_ = new_ptr;
new_rptr = (void*) (((gsize) _tmp1_) | (mask & new_mask));
old_rptr = (void*) (((gsize) old_ptr) | (mask & old_mask));
_tmp2_ = old_rptr;
_tmp3_ = new_rptr;
success = g_atomic_pointer_compare_and_exchange ((volatile gpointer *) ((void**) aptr), _tmp2_, _tmp3_);
if (success) {
GDestroyNotify notify = NULL;
GDestroyNotify _tmp4_;
gboolean _tmp5_ = FALSE;
_tmp4_ = gee_utils_free_get_destroy_notify (g_type, (GBoxedCopyFunc) g_dup_func, (GDestroyNotify) g_destroy_func);
notify = _tmp4_;
if (old_ptr != NULL) {
GDestroyNotify _tmp6_;
_tmp6_ = notify;
_tmp5_ = _tmp6_ != NULL;
} else {
_tmp5_ = FALSE;
}
if (_tmp5_) {
GeeHazardPointerContext* _tmp7_;
GDestroyNotify _tmp8_;
_tmp7_ = gee_hazard_pointer_context_get_current_context ();
_tmp8_ = notify;
notify = NULL;
gee_hazard_pointer_context_release_ptr (_tmp7_, old_ptr, _tmp8_);
}
} else {
gconstpointer* _tmp9_;
_tmp9_ = new_ptr;
if (_tmp9_ != NULL) {
gconstpointer* _tmp10_;
_tmp10_ = new_ptr;
new_ptr = NULL;
((_new_ptr == NULL) || (g_destroy_func == NULL)) ? NULL : (_new_ptr = (g_destroy_func (_new_ptr), NULL));
_new_ptr = _tmp10_;
}
}
result = success;
((_new_ptr == NULL) || (g_destroy_func == NULL)) ? NULL : (_new_ptr = (g_destroy_func (_new_ptr), NULL));
return result;
}
/**
* Gets the pointer hold by hazard pointer.
*
* @param other_thread Have to be set to ``true`` if accessed from thread that did not create this thread.
* @return The value hold by pointer.
*/
inline gconstpointer
gee_hazard_pointer_get (GeeHazardPointer* self,
gboolean other_thread)
{
GeeHazardPointerNode* _tmp0_;
void* _tmp1_;
gconstpointer result = NULL;
g_return_val_if_fail (self != NULL, NULL);
_tmp0_ = self->_node;
_tmp1_ = gee_hazard_pointer_node_get (_tmp0_, other_thread);
result = _tmp1_;
return result;
}
/**
* Free the pointer.
*
* @param notify method freeing object
*/
void
gee_hazard_pointer_release (GeeHazardPointer* self,
GDestroyNotify notify)
{
gconstpointer item = NULL;
GeeHazardPointerNode* _tmp0_;
void* _tmp1_;
GeeHazardPointerNode* _tmp2_;
gconstpointer _tmp3_;
g_return_if_fail (self != NULL);
_tmp0_ = self->_node;
_tmp1_ = gee_hazard_pointer_node_get (_tmp0_, FALSE);
item = _tmp1_;
_tmp2_ = self->_node;
gee_hazard_pointer_node_set (_tmp2_, NULL);
_tmp3_ = item;
if (_tmp3_ != NULL) {
GeeHazardPointerContext* _tmp4_;
gconstpointer _tmp5_;
GDestroyNotify _tmp6_;
_tmp4_ = gee_hazard_pointer_context_get_current_context ();
_tmp5_ = item;
_tmp6_ = notify;
notify = NULL;
gee_hazard_pointer_context_release_ptr (_tmp4_, _tmp5_, _tmp6_);
}
}
/**
* Sets default policy (i.e. default policy for user-created contexts).
* The policy must be concrete and should not be blocking.
*
* @param policy New default policy.
*/
void
gee_hazard_pointer_set_default_policy (GeeHazardPointerPolicy policy)
{
_vala_return_if_fail (gee_hazard_pointer_policy_is_concrete (policy), "policy.is_concrete ()");
if (gee_hazard_pointer_policy_is_blocking (policy)) {
g_warning ("hazardpointer.vala:252: Setting blocking default Gee.HazardPointer.Pol" \
"icy (there may be a deadlock).\n");
}
g_atomic_int_set ((volatile gint *) (&gee_hazard_pointer__default_policy), (gint) policy);
}
/**
* Sets thread exit policy (i.e. default policy for the top-most Context).
* The policy must be concrete and should not be unsafe.
*
* @param policy New thread policy.
*/
void
gee_hazard_pointer_set_thread_exit_policy (GeeHazardPointerPolicy policy)
{
_vala_return_if_fail (gee_hazard_pointer_policy_is_concrete (policy), "policy.is_concrete ()");
if (!gee_hazard_pointer_policy_is_safe (policy)) {
g_warning ("hazardpointer.vala:264: Setting unsafe globale thread-exit Gee.HazardP" \
"ointer.Policy (there may be a memory leak).\n");
}
g_atomic_int_set ((volatile gint *) (&gee_hazard_pointer__thread_exit_policy), (gint) policy);
}
/**
* Sets release (i.e. how exactly the released objects arefreed).
*
* The method can be only set before any objects is released and is not thread-safe.
*
* @param policy New release policy.
*/
gboolean
gee_hazard_pointer_set_release_policy (GeeHazardPointerReleasePolicy policy)
{
gint old_policy = 0;
gint _tmp0_;
gboolean _tmp1_;
gboolean result = FALSE;
_tmp0_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer_release_policy));
old_policy = _tmp0_;
if ((old_policy & ((sizeof (gint) * 8) - 1)) != 0) {
g_critical ("hazardpointer.vala:278: Attempt to change the policy of running helper" \
". Failing.");
result = FALSE;
return result;
}
_tmp1_ = g_atomic_int_compare_and_exchange ((volatile gint *) (&gee_hazard_pointer_release_policy), old_policy, (gint) policy);
if (!_tmp1_) {
g_critical ("hazardpointer.vala:282: Concurrent access to release policy detected. " \
"Failing.");
result = FALSE;
return result;
}
result = TRUE;
return result;
}
/**
* Gets a new hazard pointer node.
*
* @return new hazard pointer node.
*/
G_GNUC_INTERNAL inline GeeHazardPointerNode*
gee_hazard_pointer_acquire (void)
{
GeeHazardPointerNode* node = NULL;
GeeHazardPointerNode* _tmp7_;
GeeHazardPointerNode* old_head = NULL;
GeeHazardPointerNode* _tmp14_;
GeeHazardPointerNode* result = NULL;
{
GeeHazardPointerNode* curr = NULL;
GeeHazardPointerNode* _tmp0_;
_tmp0_ = gee_hazard_pointer_get_head ();
curr = _tmp0_;
{
gboolean _tmp1_ = FALSE;
_tmp1_ = TRUE;
while (TRUE) {
GeeHazardPointerNode* _tmp4_;
GeeHazardPointerNode* _tmp5_;
if (!_tmp1_) {
GeeHazardPointerNode* _tmp2_;
GeeHazardPointerNode* _tmp3_;
_tmp2_ = curr;
_tmp3_ = gee_hazard_pointer_node_get_next (_tmp2_);
curr = _tmp3_;
}
_tmp1_ = FALSE;
_tmp4_ = curr;
if (!(_tmp4_ != NULL)) {
break;
}
_tmp5_ = curr;
if (gee_hazard_pointer_node_activate (_tmp5_)) {
GeeHazardPointerNode* _tmp6_;
_tmp6_ = curr;
result = _tmp6_;
return result;
}
}
}
}
_tmp7_ = gee_hazard_pointer_node_new ();
node = _tmp7_;
old_head = NULL;
{
gboolean _tmp8_ = FALSE;
_tmp8_ = TRUE;
while (TRUE) {
GeeHazardPointerNode* _tmp11_;
void* _tmp12_;
GeeHazardPointerNode* _tmp13_;
if (!_tmp8_) {
GeeHazardPointerNode* _tmp9_;
GeeHazardPointerNode* _tmp10_;
_tmp9_ = old_head;
_tmp10_ = node;
if (!(!g_atomic_pointer_compare_and_exchange ((volatile gpointer *) (&gee_hazard_pointer__head), _tmp9_, _tmp10_))) {
break;
}
}
_tmp8_ = FALSE;
_tmp11_ = node;
_tmp12_ = g_atomic_pointer_get ((volatile gpointer *) (&gee_hazard_pointer__head));
old_head = (GeeHazardPointerNode*) _tmp12_;
_tmp13_ = old_head;
gee_hazard_pointer_node_set_next (_tmp11_, _tmp13_);
}
}
_tmp14_ = node;
result = _tmp14_;
return result;
}
/**
* Tries to free from list.
*
* @return ``true`` if list is empty.
*/
G_GNUC_INTERNAL gboolean
gee_hazard_pointer_try_free (GeeArrayList* to_free)
{
GeeCollection* used = NULL;
GeeHashSet* _tmp0_;
gint _tmp30_;
gint _tmp31_;
gboolean result = FALSE;
g_return_val_if_fail (to_free != NULL, FALSE);
_tmp0_ = gee_hash_set_new (G_TYPE_POINTER, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
used = (GeeCollection*) _tmp0_;
{
GeeHazardPointerNode* current = NULL;
GeeHazardPointerNode* _tmp1_;
_tmp1_ = gee_hazard_pointer_get_head ();
current = _tmp1_;
{
gboolean _tmp2_ = FALSE;
_tmp2_ = TRUE;
while (TRUE) {
GeeHazardPointerNode* _tmp5_;
GeeCollection* _tmp6_;
GeeHazardPointerNode* _tmp7_;
void* _tmp8_;
if (!_tmp2_) {
GeeHazardPointerNode* _tmp3_;
GeeHazardPointerNode* _tmp4_;
_tmp3_ = current;
_tmp4_ = gee_hazard_pointer_node_get_next (_tmp3_);
current = _tmp4_;
}
_tmp2_ = FALSE;
_tmp5_ = current;
if (!(_tmp5_ != NULL)) {
break;
}
_tmp6_ = used;
_tmp7_ = current;
_tmp8_ = gee_hazard_pointer_node_get (_tmp7_, TRUE);
gee_collection_add (_tmp6_, _tmp8_);
}
}
}
{
gint i = 0;
i = 0;
{
gboolean _tmp9_ = FALSE;
_tmp9_ = TRUE;
while (TRUE) {
gint _tmp10_;
gint _tmp11_;
GeeHazardPointerFreeNode* current = NULL;
gpointer _tmp12_;
GeeCollection* _tmp13_;
GeeHazardPointerFreeNode* _tmp14_;
void* _tmp15_;
if (!_tmp9_) {
}
_tmp9_ = FALSE;
_tmp10_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) to_free);
_tmp11_ = _tmp10_;
if (!(i < _tmp11_)) {
break;
}
_tmp12_ = gee_abstract_list_get ((GeeAbstractList*) to_free, i);
current = _tmp12_;
_tmp13_ = used;
_tmp14_ = current;
_tmp15_ = _tmp14_->pointer;
if (gee_collection_contains (_tmp13_, _tmp15_)) {
gint _tmp16_;
_tmp16_ = i;
i = _tmp16_ + 1;
} else {
GeeHazardPointerFreeNode* cur = NULL;
gint _tmp17_;
gint _tmp18_;
gpointer _tmp19_;
gint _tmp20_;
gint _tmp21_;
GeeHazardPointerFreeNode* _tmp25_;
GDestroyNotify _tmp26_;
GeeHazardPointerFreeNode* _tmp27_;
void* _tmp28_;
GeeHazardPointerFreeNode* _tmp29_;
_tmp17_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) to_free);
_tmp18_ = _tmp17_;
_tmp19_ = gee_abstract_list_remove_at ((GeeAbstractList*) to_free, _tmp18_ - 1);
cur = _tmp19_;
_tmp20_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) to_free);
_tmp21_ = _tmp20_;
if (i != _tmp21_) {
GeeHazardPointerFreeNode* temp = NULL;
gpointer _tmp22_;
GeeHazardPointerFreeNode* _tmp23_;
GeeHazardPointerFreeNode* _tmp24_;
_tmp22_ = gee_abstract_list_get ((GeeAbstractList*) to_free, i);
temp = _tmp22_;
_tmp23_ = cur;
gee_abstract_list_set ((GeeAbstractList*) to_free, i, _tmp23_);
_tmp24_ = temp;
cur = _tmp24_;
}
_tmp25_ = cur;
_tmp26_ = _tmp25_->destroy_notify;
_tmp27_ = cur;
_tmp28_ = _tmp27_->pointer;
_tmp26_ (_tmp28_);
_tmp29_ = cur;
gee_hazard_pointer_free_node_free (_tmp29_);
}
}
}
}
_tmp30_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) to_free);
_tmp31_ = _tmp30_;
result = _tmp31_ > 0;
_g_object_unref0 (used);
return result;
}
/**
* Gets head of hazard pointers.
* @return Hazard pointer head.
*/
G_GNUC_INTERNAL GeeHazardPointerNode*
gee_hazard_pointer_get_head (void)
{
void* _tmp0_;
GeeHazardPointerNode* result = NULL;
_tmp0_ = g_atomic_pointer_get ((volatile gpointer *) (&gee_hazard_pointer__head));
result = (GeeHazardPointerNode*) _tmp0_;
return result;
}
static GeeHazardPointerPolicy*
_gee_hazard_pointer_policy_dup (GeeHazardPointerPolicy* self)
{
GeeHazardPointerPolicy* dup;
dup = g_new0 (GeeHazardPointerPolicy, 1);
memcpy (dup, self, sizeof (GeeHazardPointerPolicy));
return dup;
}
static gpointer
__gee_hazard_pointer_policy_dup0 (gpointer self)
{
return self ? _gee_hazard_pointer_policy_dup (self) : NULL;
}
GeeHazardPointerContext*
gee_hazard_pointer_context_new (GeeHazardPointerPolicy* policy)
{
GeeHazardPointerContext* self;
GeeArrayList* _tmp0_;
void* _tmp1_;
self = g_slice_new0 (GeeHazardPointerContext);
gee_hazard_pointer_context_instance_init (self);
_tmp0_ = gee_array_list_new (G_TYPE_POINTER, NULL, NULL, NULL, NULL, NULL);
_g_object_unref0 (self->_to_free);
self->_to_free = _tmp0_;
_tmp1_ = g_static_private_get (&gee_hazard_pointer_context__current_context);
self->_parent = _tmp1_;
g_static_private_set (&gee_hazard_pointer_context__current_context, self, NULL);
if (policy == NULL) {
GeeHazardPointerContext* _tmp2_;
_tmp2_ = self->_parent;
if (_tmp2_ == NULL) {
gint _tmp3_;
GeeHazardPointerPolicy _tmp4_;
GeeHazardPointerPolicy* _tmp5_;
_tmp3_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer__thread_exit_policy));
_tmp4_ = (GeeHazardPointerPolicy) _tmp3_;
_tmp5_ = __gee_hazard_pointer_policy_dup0 (&_tmp4_);
_g_free0 (self->_policy);
self->_policy = _tmp5_;
} else {
gint _tmp6_;
GeeHazardPointerPolicy _tmp7_;
GeeHazardPointerPolicy* _tmp8_;
_tmp6_ = g_atomic_int_get ((volatile gint *) (&gee_hazard_pointer__default_policy));
_tmp7_ = (GeeHazardPointerPolicy) _tmp6_;
_tmp8_ = __gee_hazard_pointer_policy_dup0 (&_tmp7_);
_g_free0 (self->_policy);
self->_policy = _tmp8_;
}
} else {
GeeHazardPointerPolicy _tmp9_;
GeeHazardPointerPolicy* _tmp10_;
_tmp9_ = gee_hazard_pointer_policy_to_concrete (*policy);
_tmp10_ = __gee_hazard_pointer_policy_dup0 (&_tmp9_);
_g_free0 (self->_policy);
self->_policy = _tmp10_;
}
return self;
}
/**
* Tries to free all freed pointer in current context.
*/
void
gee_hazard_pointer_context_try_free (GeeHazardPointerContext* self)
{
GeeArrayList* _tmp0_;
g_return_if_fail (self != NULL);
_tmp0_ = self->_to_free;
gee_hazard_pointer_try_free (_tmp0_);
}
/**
* Ensure that whole context is freed. Please note that it might block.
*/
void
gee_hazard_pointer_context_free_all (GeeHazardPointerContext* self)
{
g_return_if_fail (self != NULL);
while (TRUE) {
GeeArrayList* _tmp0_;
_tmp0_ = self->_to_free;
if (!gee_hazard_pointer_try_free (_tmp0_)) {
break;
}
g_thread_yield ();
}
}
/**
* Tries to push the current context to releaser.
*/
void
gee_hazard_pointer_context_try_release (GeeHazardPointerContext* self)
{
g_return_if_fail (self != NULL);
if (g_static_mutex_trylock (&gee_hazard_pointer__queue_mutex)) {
GeeQueue* _tmp0_;
GeeArrayList* _tmp1_;
GeeArrayList* _tmp2_;
GeeArrayList* _tmp3_;
_tmp0_ = gee_hazard_pointer__queue;
_tmp1_ = self->_to_free;
self->_to_free = NULL;
_tmp2_ = _tmp1_;
gee_queue_offer (_tmp0_, _tmp2_);
_g_object_unref0 (_tmp2_);
_tmp3_ = gee_array_list_new (G_TYPE_POINTER, NULL, NULL, NULL, NULL, NULL);
_g_object_unref0 (self->_to_free);
self->_to_free = _tmp3_;
g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
}
}
/**
* Pushes the current context to releaser. Please note that it might block.
*/
void
gee_hazard_pointer_context_release (GeeHazardPointerContext* self)
{
GeeQueue* _tmp0_;
GeeArrayList* _tmp1_;
GeeArrayList* _tmp2_;
GeeArrayList* _tmp3_;
g_return_if_fail (self != NULL);
g_static_mutex_lock (&gee_hazard_pointer__queue_mutex);
_tmp0_ = gee_hazard_pointer__queue;
_tmp1_ = self->_to_free;
self->_to_free = NULL;
_tmp2_ = _tmp1_;
gee_queue_offer (_tmp0_, _tmp2_);
_g_object_unref0 (_tmp2_);
_tmp3_ = gee_array_list_new (G_TYPE_POINTER, NULL, NULL, NULL, NULL, NULL);
_g_object_unref0 (self->_to_free);
self->_to_free = _tmp3_;
g_static_mutex_unlock (&gee_hazard_pointer__queue_mutex);
}
/**
* Add pointer to freed array.
*/
G_GNUC_INTERNAL inline void
gee_hazard_pointer_context_release_ptr (GeeHazardPointerContext* self,
void* ptr,
GDestroyNotify notify)
{
GeeHazardPointerFreeNode* node = NULL;
GeeHazardPointerFreeNode* _tmp0_;
GeeHazardPointerFreeNode* _tmp1_;
GeeHazardPointerFreeNode* _tmp2_;
GDestroyNotify _tmp3_;
GeeArrayList* _tmp4_;
GeeHazardPointerFreeNode* _tmp5_;
GeeArrayList* _tmp6_;
gint _tmp7_;
gint _tmp8_;
g_return_if_fail (self != NULL);
_tmp0_ = gee_hazard_pointer_free_node_new ();
node = _tmp0_;
_tmp1_ = node;
_tmp1_->pointer = ptr;
_tmp2_ = node;
_tmp3_ = notify;
notify = NULL;
_tmp2_->destroy_notify = _tmp3_;
_tmp4_ = self->_to_free;
_tmp5_ = node;
gee_abstract_collection_add ((GeeAbstractCollection*) _tmp4_, _tmp5_);
_tmp6_ = self->_to_free;
_tmp7_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp6_);
_tmp8_ = _tmp7_;
if (((guint) _tmp8_) >= gee_hazard_pointer_context_THRESHOLD) {
GeeArrayList* _tmp9_;
_tmp9_ = self->_to_free;
gee_hazard_pointer_try_free (_tmp9_);
}
}
/**
* Gets current context.
*/
G_GNUC_INTERNAL inline GeeHazardPointerContext*
gee_hazard_pointer_context_get_current_context (void)
{
void* _tmp0_;
GeeHazardPointerContext* result = NULL;
_tmp0_ = g_static_private_get (&gee_hazard_pointer_context__current_context);
result = _tmp0_;
return result;
}
static void
gee_hazard_pointer_context_instance_init (GeeHazardPointerContext * self)
{
}
void
gee_hazard_pointer_context_free (GeeHazardPointerContext * self)
{
gint size = 0;
GeeArrayList* _tmp0_;
gint _tmp1_;
gint _tmp2_;
gboolean clean_parent = FALSE;
GeeHazardPointerContext* _tmp13_;
_tmp0_ = self->_to_free;
_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
_tmp2_ = _tmp1_;
size = _tmp2_;
clean_parent = FALSE;
if (size > 0) {
gboolean _tmp3_ = FALSE;
GeeHazardPointerContext* _tmp4_;
_tmp4_ = self->_parent;
if (_tmp4_ == NULL) {
_tmp3_ = TRUE;
} else {
_tmp3_ = ((guint) size) >= gee_hazard_pointer_context_THRESHOLD;
}
if (_tmp3_) {
GeeHazardPointerPolicy* _tmp5_;
gboolean _tmp6_;
_tmp5_ = self->_policy;
_tmp6_ = gee_hazard_pointer_policy_perform (*_tmp5_, &self->_to_free);
if (!_tmp6_) {
gboolean _tmp7_ = FALSE;
GeeHazardPointerContext* _tmp8_;
GeeHazardPointerContext* _tmp10_;
GeeArrayList* _tmp11_;
GeeArrayList* _tmp12_;
_tmp8_ = self->_parent;
if (_tmp8_ != NULL) {
GeeArrayList* _tmp9_;
_tmp9_ = self->_to_free;
_tmp7_ = _tmp9_ != NULL;
} else {
_tmp7_ = FALSE;
}
_vala_assert (_tmp7_, "_parent != null && _to_free != null");
_tmp10_ = self->_parent;
_tmp11_ = _tmp10_->_to_free;
_tmp12_ = self->_to_free;
gee_array_list_add_all (_tmp11_, (GeeCollection*) _tmp12_);
clean_parent = TRUE;
}
}
}
_tmp13_ = self->_parent;
g_static_private_set (&gee_hazard_pointer_context__current_context, _tmp13_, NULL);
if (clean_parent) {
GeeHazardPointerContext* _tmp14_;
GeeArrayList* _tmp15_;
_tmp14_ = self->_parent;
_tmp15_ = _tmp14_->_to_free;
gee_hazard_pointer_try_free (_tmp15_);
}
_g_object_unref0 (self->_to_free);
_g_free0 (self->_policy);
g_slice_free (GeeHazardPointerContext, self);
}
G_GNUC_INTERNAL GeeHazardPointerFreeNode*
gee_hazard_pointer_free_node_new (void)
{
GeeHazardPointerFreeNode* self;
self = g_slice_new0 (GeeHazardPointerFreeNode);
gee_hazard_pointer_free_node_instance_init (self);
return self;
}
static void
gee_hazard_pointer_free_node_instance_init (GeeHazardPointerFreeNode * self)
{
}
G_GNUC_INTERNAL void
gee_hazard_pointer_free_node_free (GeeHazardPointerFreeNode * self)
{
g_slice_free (GeeHazardPointerFreeNode, self);
}
G_GNUC_INTERNAL GeeHazardPointerNode*
gee_hazard_pointer_node_new (void)
{
GeeHazardPointerNode* self;
self = g_slice_new0 (GeeHazardPointerNode);
gee_hazard_pointer_node_instance_init (self);
g_atomic_pointer_set ((volatile gpointer *) (&self->_hazard), NULL);
g_atomic_int_set ((volatile gint *) (&self->_active), 1);
return self;
}
G_GNUC_INTERNAL void
gee_hazard_pointer_node_release (GeeHazardPointerNode* self)
{
g_return_if_fail (self != NULL);
g_atomic_pointer_set ((volatile gpointer *) (&self->_hazard), NULL);
g_atomic_int_set ((volatile gint *) (&self->_active), 0);
}
G_GNUC_INTERNAL inline gboolean
gee_hazard_pointer_node_is_active (GeeHazardPointerNode* self)
{
gint _tmp0_;
gboolean result = FALSE;
g_return_val_if_fail (self != NULL, FALSE);
_tmp0_ = g_atomic_int_get ((volatile gint *) (&self->_active));
result = _tmp0_ != 0;
return result;
}
G_GNUC_INTERNAL inline gboolean
gee_hazard_pointer_node_activate (GeeHazardPointerNode* self)
{
gboolean _tmp0_;
gboolean result = FALSE;
g_return_val_if_fail (self != NULL, FALSE);
_tmp0_ = g_atomic_int_compare_and_exchange ((volatile gint *) (&self->_active), 0, 1);
result = _tmp0_;
return result;
}
G_GNUC_INTERNAL inline void
gee_hazard_pointer_node_set (GeeHazardPointerNode* self,
void* ptr)
{
g_return_if_fail (self != NULL);
g_atomic_pointer_set ((volatile gpointer *) (&self->_hazard), ptr);
}
G_GNUC_INTERNAL inline void*
gee_hazard_pointer_node_get (GeeHazardPointerNode* self,
gboolean safe)
{
void* result = NULL;
g_return_val_if_fail (self != NULL, NULL);
if (safe) {
void* _tmp0_;
_tmp0_ = g_atomic_pointer_get ((volatile gpointer *) (&self->_hazard));
result = (void*) _tmp0_;
return result;
} else {
void* _tmp1_;
_tmp1_ = self->_hazard;
result = (void*) _tmp1_;
return result;
}
}
G_GNUC_INTERNAL inline GeeHazardPointerNode*
gee_hazard_pointer_node_get_next (GeeHazardPointerNode* self)
{
void* _tmp0_;
GeeHazardPointerNode* result = NULL;
g_return_val_if_fail (self != NULL, NULL);
_tmp0_ = g_atomic_pointer_get ((volatile gpointer *) (&self->_next));
result = (GeeHazardPointerNode*) _tmp0_;
return result;
}
G_GNUC_INTERNAL inline void
gee_hazard_pointer_node_set_next (GeeHazardPointerNode* self,
GeeHazardPointerNode* next)
{
g_return_if_fail (self != NULL);
g_atomic_pointer_set ((volatile gpointer *) (&self->_next), next);
}
static void
gee_hazard_pointer_node_instance_init (GeeHazardPointerNode * self)
{
}
G_GNUC_INTERNAL void
gee_hazard_pointer_node_free (GeeHazardPointerNode * self)
{
GeeHazardPointerNode* _tmp0_;
_tmp0_ = self->_next;
gee_hazard_pointer_node_free (_tmp0_);
g_slice_free (GeeHazardPointerNode, self);
}
static void
gee_hazard_pointer_instance_init (GeeHazardPointer * self)
{
}
void
gee_hazard_pointer_free (GeeHazardPointer * self)
{
GeeHazardPointerNode* _tmp0_;
_tmp0_ = self->_node;
gee_hazard_pointer_node_release (_tmp0_);
g_slice_free (GeeHazardPointer, self);
}
|