Advertisement
Guest User

anthony gorecki anthony@anthonygorecki.ca

a guest
Dec 9th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.86 KB | None | 0 0
  1. Wed, Dec 09, 2015 2:56:35 AM
  2. ./doc/code-style.txt
  3. Soft limit for line length is 80 characters, hard limit is 100 characters.
  4.  
  5. Conditional statements requiring multiple lines should indent the subsequent
  6. lines with two tabs (one additional tab, relative the the code following the
  7. conditional statement).
  8. ./doc/errors.txt
  9. Code that is (potentially) buggy enough to need asserts should include <gc/err.h>.
  10. ./doc/func-args.txt
  11. Structs are always used for info and conf varaibles so their contents /
  12. implementation can easily be changed later and without modifying the code of
  13. software using the libraries.
  14. ./doc/func-naming.txt
  15. Hard limit for function name first part is five characters. Soft limit is
  16. four characters.
  17.  
  18. Function name hard limit for second part is five characters (initialization /
  19. activation). Does not apply to names that have been shortened to individual
  20. characters per word.
  21.  
  22. Struct member name soft limit is four characters.
  23. ./doc/includes.txt
  24. External Gc headers, Gc header for local file, all other headers; groups
  25. separated by a single new line.
  26.  
  27. All Gc headers must ultimately include <gc/base.h>. This is to get system
  28. wide defines like _GNU_SOURCE and primitive types (u8, etc).
  29.  
  30. Includes for files that have a one line description must duplicate that
  31. description.
  32. ./doc/secure-coding.txt
  33. Parser memory errors are treated as "no match".
  34.  
  35. Invalid flag arguments are treated as "no match".
  36. ./gc-base-lib/1/0/gc-proj.txt
  37. #===============================================================================
  38. # This file is part of Gc-Base-Lib.
  39. # Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  40. #
  41. # Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  42. # the terms of the GNU General Public License as published by the Free Software
  43. # Foundation, either version 3 of the License, or (at your option) any later
  44. # version.
  45. #
  46. # Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  47. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  48. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  49. #
  50. # You should have received a copy of the GNU General Public License along with
  51. # Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  52. #===============================================================================
  53. # gc-proj-conf (tracks config; can reconfigure; if you aren't going to make 'dev'
  54. # it won't be configured -- per target config)
  55. # gc-proj-make (will rebuild changed files; will rebuild only necessary after conf change)
  56. # gc-proj-inst (installs all built targets)
  57. #
  58. # Note: This file does not include operating system specific support yet.
  59.  
  60.  
  61. TGEN dev # Make this into TDEV after parser works properly.
  62. CONF
  63. VARS
  64. DIR inc
  65. DIR pkgconfig
  66.  
  67. MAKE
  68. EXEC lib/pkgconfig/make.sh $DPKGCONFIG # This should be replaced with 'sed'.
  69.  
  70. INST
  71. COPY inc/gc $DINC
  72. MOVE lib/pkgconfig/gc-base.pc.tmp $DPKGCONFIG/gc-base.pc
  73.  
  74.  
  75. TLIB lib
  76. CONF
  77. # DEF (default target; overrides first lib or exe target if specified)
  78. # note that the precedence of targets to be chosen first could (and
  79. # probably should be determined by selecting a profile for the given
  80. # programming language / project type. Documentation projects, for
  81. # instance would not have the same precedence settings as a c project.
  82.  
  83. # NDIR LIB (implied by target type).
  84.  
  85. DLNK pthread # Need pthread library.
  86.  
  87. FEAT alloc # Feature to select memory allocator.
  88. llalloc # Lockless alloc. Default option is first.
  89. DLNK llalloc # Add to the list of libraries to link dynamically.
  90.  
  91. libc # Fall back to standard libc allocator.
  92. # Nothing to do.
  93.  
  94. FEAT st # Feature to select stack tracing implementation.
  95. unwind # libunwind
  96. PCFG unwind # Use pkg-config to add cflags and libs.
  97.  
  98. gnubt # GNU backtrace functions
  99. LNKF rdynamic # Add -rdynamic linker flag.
  100. ./gc-base-lib/1/0/inc/gc/atmc.h
  101. //==============================================================================
  102. // This file is part of Gc-Base-Lib.
  103. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  104. //
  105. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  106. // the terms of the GNU General Public License as published by the Free Software
  107. // Foundation, either version 3 of the License, or (at your option) any later
  108. // version.
  109. //
  110. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  111. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  112. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  113. // details.
  114. //
  115. // You should have received a copy of the GNU General Public License along with
  116. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  117. //==============================================================================
  118. #pragma once
  119.  
  120. #if defined(__STDC_NO_ATOMICS__)
  121. #error "C library implementation does not support atomics."
  122. #endif
  123.  
  124. #include <gc/base.h>
  125.  
  126. #include <stdatomic.h>
  127.  
  128.  
  129.  
  130. //==============================================================================
  131. // Definitions
  132. //==============================================================================
  133. #define MO_REL memory_order_relaxed
  134. #define MO_CSM memory_order_consume
  135. #define MO_ACQ memory_order_acquire
  136. #define MO_REL memory_order_release
  137. #define MO_ACQ_REL memory_order_acq_rel
  138. #define MO_SEQ_CST memory_order_seq_cst
  139.  
  140.  
  141.  
  142. //==============================================================================
  143. // Type definitions
  144. //==============================================================================
  145. typedef _Atomic s8 sa8;
  146. typedef _Atomic s16 sa16;
  147. typedef _Atomic s32 sa32;
  148. typedef _Atomic s64 sa64;
  149.  
  150. typedef _Atomic u8 ua8;
  151. typedef _Atomic u16 ua16;
  152. typedef _Atomic u32 ua32;
  153. typedef _Atomic u64 ua64;
  154.  
  155.  
  156.  
  157. //==============================================================================
  158. // Function aliases
  159. //==============================================================================
  160. #define atmc_fetch_add atomic_fetch_add_explicit
  161. #define atmc_fetch_sub atomic_fetch_sub_explicit
  162. #define atmc_fetch_and atomic_fetch_and_explicit
  163. #define atmc_fetch_or atomic_fetch_or_explicit
  164. #define atmc_fetch_xor atomic_fetch_xor_explicit
  165.  
  166. #define atmc_load atomic_load_explicit
  167. #define atmc_store atomic_store_explicit
  168.  
  169. #define atmc_thrd_fence atomic_thread_fence
  170. ./gc-base-lib/1/0/inc/gc/base.h
  171. //==============================================================================
  172. // This file is part of Gc-Base-Lib.
  173. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  174. //
  175. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  176. // the terms of the GNU General Public License as published by the Free Software
  177. // Foundation, either version 3 of the License, or (at your option) any later
  178. // version.
  179. //
  180. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  181. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  182. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  183. // details.
  184. //
  185. // You should have received a copy of the GNU General Public License along with
  186. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  187. //==============================================================================
  188. #pragma once
  189.  
  190. #include <stddef.h>
  191. #include <stdint.h>
  192.  
  193. // "__unused" is expected to be provided by a system library. Define it in this
  194. // file only if it is missing on the host system.
  195.  
  196. #define likely(EXPR) __builtin_expect(EXPR, 1)
  197. #define unlikely(EXPR) __builtin_expect(EXPR, 0)
  198.  
  199. typedef int8_t s8;
  200. typedef int16_t s16;
  201. typedef int32_t s32;
  202. typedef int64_t s64;
  203.  
  204. typedef uint8_t u8;
  205. typedef uint16_t u16;
  206. typedef uint32_t u32;
  207. typedef uint64_t u64;
  208. ./gc-base-lib/1/0/inc/gc/ct.h
  209. //==============================================================================
  210. // This file is part of Gc-Base-Lib.
  211. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  212. //
  213. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  214. // the terms of the GNU General Public License as published by the Free Software
  215. // Foundation, either version 3 of the License, or (at your option) any later
  216. // version.
  217. //
  218. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  219. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  220. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  221. // details.
  222. //
  223. // You should have received a copy of the GNU General Public License along with
  224. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  225. //==============================================================================
  226. #pragma once
  227.  
  228. #include <gc/macro/ms.h>
  229.  
  230. // Configuration for composite types needs space for two offsets (u16's), to
  231. // allow for two variable types (such as "u8_a").
  232.  
  233. #define CT_M1V 1 // Member 1 pass by value.
  234. #define CT_M2V 2 // Member 2 pass by value.
  235. #define CT_M2D 4 // Member 2 pass to deinit.
  236.  
  237. #define CT_WRAP_MSI2D1(PREF) \
  238. u8 PREF##_init_ms(struct PREF##_i*, struct PREF##_c*); \
  239. void PREF##_deinit_ms(struct PREF##_i*); \
  240. u8 PREF##_init(struct PREF##_i *info, struct PREF##_c *conf) \
  241. { \
  242. u8 step = PREF##_init_ms(info, conf); \
  243. if (!step) \
  244. return 0; \
  245. PREF##_deinit_ms(info, step); \
  246. return 1; \
  247. } \
  248. void PREF##_deinit(struct PREF##_i *info) \
  249. { \
  250. PREF##_deinit_ms(info, 0); \
  251. }
  252. ./gc-base-lib/1/0/inc/gc/err.h
  253. //==============================================================================
  254. // This file is part of Gc-Base-Lib.
  255. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  256. //
  257. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  258. // the terms of the GNU General Public License as published by the Free Software
  259. // Foundation, either version 3 of the License, or (at your option) any later
  260. // version.
  261. //
  262. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  263. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  264. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  265. // details.
  266. //
  267. // You should have received a copy of the GNU General Public License along with
  268. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  269. //==============================================================================
  270. #pragma once
  271.  
  272. #include <gc/base.h>
  273.  
  274. #include <assert.h>
  275.  
  276.  
  277.  
  278. //==============================================================================
  279. // Configurable definitions
  280. //==============================================================================
  281. // These definitions should be set by "gc-proj-conf" in the future.
  282. #define ERR_ENBEG 2200 // Begin numbering of additional error types from here.
  283. #define ERR_ENMAX 3000 // Maximum sane value of "errno". Must be "<= U16_MAX".
  284.  
  285.  
  286.  
  287. //==============================================================================
  288. // Additional error types
  289. //==============================================================================
  290. #define EINVALRET (ERR_ENBEG + 0)
  291.  
  292.  
  293.  
  294. //==============================================================================
  295. // Function prototypes
  296. //==============================================================================
  297. __dllexp void err(void);
  298. __dllexp void err_en(int);
  299. __dllexp void err_msg(const char*);./gc-base-lib/1/0/inc/gc/file.h
  300. //==============================================================================
  301. // This file is part of Gc-Base-Lib.
  302. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  303. //
  304. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  305. // the terms of the GNU General Public License as published by the Free Software
  306. // Foundation, either version 3 of the License, or (at your option) any later
  307. // version.
  308. //
  309. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  310. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  311. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  312. // details.
  313. //
  314. // You should have received a copy of the GNU General Public License along with
  315. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  316. //==============================================================================
  317. #pragma once
  318.  
  319. #include <gc/u8b.h>
  320.  
  321. #include <sys/stat.h>
  322. #include <fcntl.h>
  323.  
  324. struct file_i {
  325. int fd;
  326. };
  327.  
  328. struct file_c {
  329. const char *path;
  330. int flags;
  331. mode_t mode;
  332. };
  333.  
  334. struct file_stats {
  335. struct stat data;
  336. };
  337. ./gc-base-lib/1/0/inc/gc/macro/ms.h
  338. //==============================================================================
  339. // This file is part of Gc-Base-Lib.
  340. // Copyright (C) 2015-2016 Anthony Gorecki <agorecki@gcproj.org>
  341. //
  342. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  343. // the terms of the GNU General Public License as published by the Free Software
  344. // Foundation, either version 3 of the License, or (at your option) any later
  345. // version.
  346. //
  347. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  348. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  349. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  350. // details.
  351. //
  352. // You should have received a copy of the GNU General Public License along with
  353. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  354. //==============================================================================
  355. #pragma once
  356.  
  357. #define MS_BEG(STEP)
  358. #define MS_EM
  359. #define MS_SP
  360. #define MS_EV
  361. ./gc-base-lib/1/0/inc/gc/macro/wrap_posix.h
  362. //==============================================================================
  363. // This file is part of Gc-Base-Lib.
  364. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  365. //
  366. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  367. // the terms of the GNU General Public License as published by the Free Software
  368. // Foundation, either version 3 of the License, or (at your option) any later
  369. // version.
  370. //
  371. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  372. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  373. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  374. // details.
  375. //
  376. // You should have received a copy of the GNU General Public License along with
  377. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  378. //==============================================================================
  379. #pragma once
  380.  
  381. #include <gc/err.h>
  382.  
  383.  
  384.  
  385. //==============================================================================
  386. // Templates
  387. //==============================================================================
  388. #define _WRAP_POSIX(SUCC, FAIL, FNAME, ...) \
  389. { \
  390. int _ret = FNAME(__VA_ARGS__); \
  391. if (unlikely(_ret)) { \
  392. err_en(_ret); \
  393. FAIL; \
  394. } \
  395. SUCC; \
  396. }
  397.  
  398.  
  399.  
  400. //==============================================================================
  401. // Wrappers
  402. //==============================================================================
  403. #define WRAP_POSIX(FNAME, ...) \
  404. _WRAP_POSIX(return 0, return 1, FNAME, __VA_ARGS__);
  405.  
  406. #define WRAP_POSIX_NR(FNAME, ...) \
  407. _WRAP_POSIX(,, FNAME, __VA_ARGS__);./gc-base-lib/1/0/inc/gc/macro/wrap_unix.h
  408. //==============================================================================
  409. // This file is part of Gc-Base-Lib.
  410. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  411. //
  412. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  413. // the terms of the GNU General Public License as published by the Free Software
  414. // Foundation, either version 3 of the License, or (at your option) any later
  415. // version.
  416. //
  417. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  418. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  419. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  420. // details.
  421. //
  422. // You should have received a copy of the GNU General Public License along with
  423. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  424. //==============================================================================
  425. #pragma once
  426.  
  427. #include <gc/err.h>
  428.  
  429.  
  430.  
  431. //==============================================================================
  432. // Templates
  433. //==============================================================================
  434. #define _WRAP_UNIX(SUCC, FAIL, FNAME, ...) \
  435. { \
  436. int _ret = FNAME(__VA_ARGS__); \
  437. if (unlikely(_ret)) { \
  438. if (unlikely(_ret != -1)) \
  439. errno = EINVALRET; \
  440. err(); \
  441. FAIL; \
  442. } \
  443. SUCC; \
  444. }
  445.  
  446.  
  447.  
  448. //==============================================================================
  449. // Wrappers
  450. //==============================================================================
  451. #define WRAP_UNIX(FNAME, ...) \
  452. _WRAP_UNIX(return 0, return 1, FNAME, __VA_ARGS__);
  453.  
  454. #define WRAP_UNIX_NR(FNAME, ...) \
  455. _WRAP_UNIX(,, FNAME, __VA_ARGS__);./gc-base-lib/1/0/inc/gc/mem.h
  456. //==============================================================================
  457. // This file is part of Gc-Base-Lib.
  458. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  459. //
  460. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  461. // the terms of the GNU General Public License as published by the Free Software
  462. // Foundation, either version 3 of the License, or (at your option) any later
  463. // version.
  464. //
  465. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  466. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  467. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  468. // details.
  469. //
  470. // You should have received a copy of the GNU General Public License along with
  471. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  472. //==============================================================================
  473. #pragma once
  474.  
  475. #include <gc/common.h>
  476.  
  477. void* mem_alloc(size_t);
  478. void* mem_realloc(void*, size_t);
  479. void mem_dealloc(void*);
  480.  
  481. u8 mem_comp(void*, void*, size_t);
  482. void mem_copy(void*, void*, size_t);
  483. void mem_move(void*, void*, size_t);
  484. void mem_set(void*, u8, size_t);
  485. ./gc-base-lib/1/0/inc/gc/pars.h
  486. //==============================================================================
  487. // This file is part of Gc-Base-Lib.
  488. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  489. //
  490. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  491. // the terms of the GNU General Public License as published by the Free Software
  492. // Foundation, either version 3 of the License, or (at your option) any later
  493. // version.
  494. //
  495. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  496. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  497. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  498. // details.
  499. //
  500. // You should have received a copy of the GNU General Public License along with
  501. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  502. //==============================================================================
  503. #pragma once
  504.  
  505. #include <gc/u8b.h>
  506.  
  507. struct pars_i {
  508. struct u8b_i buf;
  509. };
  510. ./gc-base-lib/1/0/inc/gc/proc.h
  511. //==============================================================================
  512. // This file is part of Gc-Base-Lib.
  513. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  514. //
  515. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  516. // the terms of the GNU General Public License as published by the Free Software
  517. // Foundation, either version 3 of the License, or (at your option) any later
  518. // version.
  519. //
  520. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  521. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  522. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  523. // details.
  524. //
  525. // You should have received a copy of the GNU General Public License along with
  526. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  527. //==============================================================================
  528. #pragma once
  529.  
  530. #include <gc/common.h>
  531.  
  532. #if defined(__use_gnu_bktrc)
  533. #include <gc/proc-gnu-bktrc.h>
  534. #endif
  535.  
  536. #if defined(__use_lunwind)
  537. #include <gc/proc-lunwind.h>
  538. #endif
  539.  
  540. // Null function pointers for systems where back traces are not supported.
  541. ./gc-base-lib/1/0/inc/gc/u8b.h
  542. //==============================================================================
  543. // This file is part of Gc-Base-Lib.
  544. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  545. //
  546. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  547. // the terms of the GNU General Public License as published by the Free Software
  548. // Foundation, either version 3 of the License, or (at your option) any later
  549. // version.
  550. //
  551. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  552. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  553. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  554. // details.
  555. //
  556. // You should have received a copy of the GNU General Public License along with
  557. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  558. //==============================================================================
  559. #pragma once
  560.  
  561. #include <gc/atmc.h>
  562.  
  563. struct u8b_i {
  564. u32 cbeg;
  565. au32 cin;
  566. au32 cout;
  567. u8 *dbeg;
  568. u8 *din;
  569. u8 *dout;
  570. };
  571. ./gc-base-lib/1/0/inc/gc/u8_ib.h
  572. //==============================================================================
  573. // This file is part of Gc-Base-Lib.
  574. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  575. //
  576. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  577. // the terms of the GNU General Public License as published by the Free Software
  578. // Foundation, either version 3 of the License, or (at your option) any later
  579. // version.
  580. //
  581. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  582. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  583. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  584. // details.
  585. //
  586. // You should have received a copy of the GNU General Public License along with
  587. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  588. //==============================================================================
  589. #pragma once
  590.  
  591. #include <gc/ct.h>
  592.  
  593. struct u8_ib_i {
  594. };
  595.  
  596. struct u8_ib_c {
  597. };
  598. ./gc-base-lib/1/0/make.sh
  599. gcc -o libgc-base -shared -I inc \
  600. -std=c11 \
  601. -Wall \
  602. -Wextra \
  603. -Wpedantic -Werror \
  604. src/ct/u8a.c \
  605. src/os/unix/*.c \
  606. src/pt/u8.c
  607. # `find src -type f -name '*.c'`
  608. ./gc-base-lib/1/0/src/ct/u8_a.c
  609. //==============================================================================
  610. // This file is part of Gc-Base-Lib.
  611. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  612. //
  613. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  614. // the terms of the GNU General Public License as published by the Free Software
  615. // Foundation, either version 3 of the License, or (at your option) any later
  616. // version.
  617. //
  618. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  619. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  620. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  621. // details.
  622. //
  623. // You should have received a copy of the GNU General Public License along with
  624. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  625. //==============================================================================
  626. #include <gc/mem.h>
  627.  
  628. #include <gc/u8_a.h>
  629.  
  630.  
  631.  
  632. //==============================================================================
  633. // Initialization and deinitialization
  634. //==============================================================================
  635. __dllexp u8 u8_a_init(u8 **arr, u32 *size, struct u8_a_c *conf)
  636. {
  637. *arr = mem_alloc(conf->size);
  638.  
  639. if (unlikely(*arr == NULL && conf->size))
  640. return 1;
  641.  
  642. *size = conf->size;
  643. return 0;
  644. }
  645.  
  646.  
  647. __dllexp void u8_a_deinit(u8 **arr)
  648. {
  649. mem_dealloc(*arr);
  650. }
  651.  
  652.  
  653.  
  654. //==============================================================================
  655. // Ranges
  656. //==============================================================================
  657. __dllexp u32 u8_a_rm(u8 *arr, u32 size, u8 lower, u8 upper)
  658. {
  659. while (size && *arr >= lower && *arr <= upper) {
  660. ++arr;
  661. --size;
  662. }
  663.  
  664. return size;
  665. }
  666.  
  667.  
  668. __dllexp u32 u8_a_rma(u8 *arr, u32 size, u8 *arng, u8 crng)
  669. {
  670. while (size && !u8_rma(*arr, arng, crng)) {
  671. ++arr;
  672. --size;
  673. }
  674.  
  675. return size;
  676. }
  677.  
  678.  
  679.  
  680. //==============================================================================
  681. // Values
  682. //==============================================================================
  683. __dllexp u32 u8_a_vm(u8 *arr, u32 size, u8 val)
  684. {
  685. while (size && *arr == val) {
  686. ++arr;
  687. --size;
  688. }
  689.  
  690. return size;
  691. }
  692.  
  693.  
  694. __dllexp u32 u8_a_vm2(u8 *arr, u32 size, u8 val1, u8 val2) // For new lines.
  695. {
  696. while (size >= 2 && *arr == val1 && *(arr+1) == val2) {
  697. arr += 2;
  698. size -= 2;
  699. }
  700.  
  701. return size;
  702. }
  703.  
  704.  
  705. __dllexp u32 u8_a_vma(u8 *arr, u32 size, u8 *aval, u8 cval)
  706. {
  707. while (size && !u8_vma(*arr, aval, cval)) {
  708. ++arr;
  709. --size;
  710. }
  711.  
  712. return size;
  713. }
  714.  
  715.  
  716.  
  717. //==============================================================================
  718. // Special characters
  719. //==============================================================================
  720. __dllexp u32 u8_a_sm(u8 *arr, u32 size, u8 spec, u8 esc)
  721. {
  722. return size;
  723. }
  724.  
  725.  
  726. __dllexp u32 u8_a_sma(u8 *arr, u32 size, u8 *aspec, u8 cspec, u8 esc)
  727. {
  728. // Match array of nonescaped special characters; escape character can also
  729. // be escaped (use bool "escaped" var)
  730. //
  731. // use separate function to match escape char?
  732.  
  733. return size;
  734. }
  735.  
  736.  
  737.  
  738. //==============================================================================
  739. // New line characters
  740. //==============================================================================
  741. __dllexp u8 u8_a_nld(u8 *arr, u32 size, u8 types)
  742. {
  743. assert((types & NL_RN) || (types & NL_N) || (types & NL_R));
  744.  
  745. if (size >= 2 && (types & NL_RN) && *arr == '\r' && *(arr+1) == '\n')
  746. return NL_RN;
  747.  
  748. if (size) {
  749. if ((types & NL_N) && *arr == '\n')
  750. return NL_N;
  751.  
  752. if ((types & NL_R) && *arr == '\r')
  753. return NL_R;
  754. }
  755.  
  756. return 0;
  757. }
  758.  
  759.  
  760. __dllexp u32 u8_a_nlm(u8 *arr, u32 size, u8 types)
  761. {
  762. assert((types & NL_RN) || (types & NL_N) || (types & NL_R));
  763.  
  764. if ((types & NL_RN))
  765. return u8_a_vm2(arr, size, '\r', '\n');
  766.  
  767. if ((types & NL_N))
  768. return u8_a_vm(arr, size, '\n');
  769.  
  770. return u8_a_vm(arr, size, '\r');
  771. }
  772.  
  773.  
  774. __dllexp u32 u8_a_nlmm(u8 *arr, u32 size, u8 types)
  775. {
  776. u32 rem;
  777.  
  778. for (;;) {
  779. rem = u8_a_nlm(arr, size, types);
  780.  
  781. if (rem >= size)
  782. break;
  783.  
  784. arr += size - rem;
  785. size = rem;
  786. }
  787.  
  788. return size;
  789. }
  790. ./gc-base-lib/1/0/src/ct/u8_b.c
  791. //==============================================================================
  792. // This file is part of Gc-Base-Lib.
  793. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  794. //
  795. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  796. // the terms of the GNU General Public License as published by the Free Software
  797. // Foundation, either version 3 of the License, or (at your option) any later
  798. // version.
  799. //
  800. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  801. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  802. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  803. // details.
  804. //
  805. // You should have received a copy of the GNU General Public License along with
  806. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  807. //==============================================================================
  808. #include <gc/mem.h>
  809.  
  810. #include <gc/u8_b.h>
  811. ./gc-base-lib/1/0/src/ct/u8_bc.c
  812. //==============================================================================
  813. // This file is part of Gc-Base-Lib.
  814. // Simple circular buffer, supporting nonsimultaneous input and output.
  815. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  816. //
  817. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  818. // the terms of the GNU General Public License as published by the Free Software
  819. // Foundation, either version 3 of the License, or (at your option) any later
  820. // version.
  821. //
  822. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  823. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  824. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  825. // details.
  826. //
  827. // You should have received a copy of the GNU General Public License along with
  828. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  829. //==============================================================================
  830. #include <gc/mem.h>
  831.  
  832. #include <gc/u8_bc.h>
  833.  
  834.  
  835.  
  836. //==============================================================================
  837. // Initialization and deinitialization
  838. //==============================================================================
  839. u8 u8_bc_init(struct u8_bc_i *buf, struct u8_bc_c *conf)
  840. {
  841. // Minimum size for this buffer implementation is two bytes. Check for this
  842. // in conf validation.
  843.  
  844. buf->dbeg = mem_alloc(conf->size);
  845.  
  846. if (unlikely(buf->dbeg == NULL))
  847. return 1;
  848.  
  849. buf->cbeg = size;
  850. return 0;
  851. }
  852.  
  853.  
  854. void u8_bc_deinit(struct u8_bc_i *buf)
  855. {
  856. mem_dealloc(buf->dbeg);
  857. }
  858.  
  859.  
  860.  
  861. //==============================================================================
  862. // Advance
  863. //==============================================================================
  864. void u8_bc_ia(struct u8_bc_i *buf, u32 size)
  865. {
  866. u32 off = buf->din - buf->dbeg + size;
  867.  
  868. if (off < buf->cbeg - 1)
  869. buf->din += size;
  870.  
  871. else // Wrap around.
  872. buf->din = buf->dbeg + off - buf->cbeg;
  873.  
  874. atmc_fsub(&buf->cin, size);
  875. atmc_fadd(&buf->cout, size);
  876. }
  877.  
  878.  
  879. void u8_bc_oa(struct u8_bc_i *buf, u32 size)
  880. {
  881. u32 off = buf->dout - buf->dbeg + size;
  882.  
  883. if (off < buf->cbeg - 1)
  884. buf->dout += size;
  885.  
  886. else // Wrap around.
  887. buf->dout = buf->dbeg + off - buf->cbeg;
  888.  
  889. atmc_fsub(&buf->cout, size);
  890. atmc_fadd(&buf->cin, size);
  891. }
  892.  
  893.  
  894.  
  895. //==============================================================================
  896. // Count
  897. //==============================================================================
  898. u32 u8_bc_igc(struct u8_bc_i *buf)
  899. {
  900. return atmc_load(&buf->cin);
  901. }
  902.  
  903.  
  904. u32 u8_bc_ogc(struct u8_bc_i *buf)
  905. {
  906. return atmc_load(&buf->cout);
  907. }
  908.  
  909.  
  910.  
  911. //==============================================================================
  912. // Contiguous count and pointer
  913. //==============================================================================
  914. u32 u8_bc_igcc(struct u8_bc_i *buf)
  915. {
  916. u32 off_in = buf->din - buf->dbeg;
  917. u32 orig_cin = atmc_load(&buf->cin);
  918.  
  919. if (off_in + orig_cin < buf->cbeg - 1)
  920. return orig_cout;
  921.  
  922. return buf->cbeg - off_in;
  923. }
  924.  
  925.  
  926. u8 *u8_bc_igcp(struct u8_bc_i *buf)
  927. {
  928. return buf->din;
  929. }
  930.  
  931.  
  932. u32 u8_bc_ogcc(struct u8_bc_i *buf)
  933. {
  934. u32 off_out = buf->dout - buf->dbeg;
  935. u32 orig_cout = atmc_load(&buf->cout);
  936.  
  937. if (off_out + orig_cout < buf->cbeg - 1)
  938. return orig_cout;
  939.  
  940. return buf->cbeg - off_out;
  941. }
  942.  
  943.  
  944. u8 *u8_bc_ogcp(struct u8_bc_i *buf)
  945. {
  946. return buf->dout;
  947. }
  948.  
  949.  
  950.  
  951. //==============================================================================
  952. // Peeking
  953. //==============================================================================
  954. u8 u8_bc_op1(struct u8_bc_i *buf)
  955. {
  956. return buf->dout[0];
  957. }
  958.  
  959.  
  960. u16 u8_bc_op2(struct u8_bc_i *buf)
  961. {
  962. u8 data[2];
  963.  
  964. data[0] = buf->dout[0];
  965.  
  966. if (buf->dout <= buf->dbeg + buf->cbeg - 2)
  967. data[1] = buf->dout[1];
  968.  
  969. else
  970. data[1] = buf->dbeg[0];
  971.  
  972. return (u16)data;
  973. }
  974.  
  975.  
  976.  
  977. //==============================================================================
  978. // Input and output
  979. //==============================================================================
  980. u8 u8_bc_if(struct u8_bc_i *buf, u8 (*fin)(void*, u8*, u32, u32*),
  981. void *arg)
  982. {
  983. u32 ret;
  984.  
  985. if (unlikely(fin(arg, buf->din, u8_bc_igcc(buf), &ret)))
  986. return 1;
  987.  
  988. u8_bc_ia(buf, ret);
  989. return 0;
  990. }
  991.  
  992.  
  993. u8 u8_bc_of(struct u8_bc_i *buf, u8 (*fout)(void*, u8*, u32, u32*),
  994. void *arg)
  995. {
  996. u32 ret;
  997.  
  998. if (unlikely(fout(arg, buf->dout, u8_bc_ogcc(buf), &ret)))
  999. return 1;
  1000.  
  1001. u8_bc_oa(buf, ret);
  1002. return 0;
  1003. }
  1004. ./gc-base-lib/1/0/src/ct/u8_bcss.c
  1005. //==============================================================================
  1006. // This file is part of Gc-Base-Lib.
  1007. // Lockless circular buffer, supporting a single producer and single consumer.
  1008. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1009. //
  1010. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1011. // the terms of the GNU General Public License as published by the Free Software
  1012. // Foundation, either version 3 of the License, or (at your option) any later
  1013. // version.
  1014. //
  1015. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1016. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1017. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1018. // details.
  1019. //
  1020. // You should have received a copy of the GNU General Public License along with
  1021. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1022. //==============================================================================
  1023. #include <gc/mem.h>
  1024.  
  1025. #include <gc/u8_bcss.h>
  1026.  
  1027. // Two variable "u8_a" type, member 1 is "dbeg", member 2 is "cbeg".
  1028. //
  1029. // Minimum size for this buffer implementation is two bytes. Check for this in
  1030. // conf validation.
  1031. //
  1032. // Implementation should work out figures using the nonatomic 'scout' member.
  1033. // Contig is inteded for buffer output, where parsers might need a certain
  1034. // number of contiguous bytes to function properly. Support is also provided for
  1035. // contiguous bytes for buffer input, should it be useful. These numbers are
  1036. // designed to represent the /minimum/ that the application can handle.
  1037. //
  1038. // This buffer is not designed to handle circumstances in which the read or
  1039. // write address needs to be aligned to some specific value, or when the reads
  1040. // and writes need to be of a particular size. In other words, it is not
  1041. // designed for linux kernel aio or any other kind of disk aio.
  1042. //
  1043. // This buffer is a candidate for sync and async network io, and sync disk io,
  1044. // as well as unix pipes.
  1045. //
  1046. // Buffer conversion will be available: u8_bcss -> u8_b for pars_ -> publish
  1047. // changes back to original u8_bcss once finished. This will work for more
  1048. // advanced to less advanced buffers, and the other way around. Will have a
  1049. // similar style to the (file) input and output functions at the end of this
  1050. // file. This might only be for contiguous io segments. The buffer conversion
  1051. // function is not responsible for doing any initialization or deinitialization
  1052. // of the target buffer.
  1053.  
  1054.  
  1055.  
  1056. //==============================================================================
  1057. // Initialization
  1058. //==============================================================================
  1059. __dllexp u8 u8_bcss_init(struct u8_bcss_i *buf, struct u8_bcss_c *conf)
  1060. {
  1061. // Atomic members need to be initialized before being used. Do that here.
  1062.  
  1063. buf->scin = conf->scin; // U16
  1064. buf->scout = conf->scout;
  1065. buf->cin = buf->cbeg - conf->scntg;
  1066. buf->cout = 0;
  1067. buf->din = buf->dbeg + conf->scntg;
  1068. buf->dout = buf->dbeg + conf->scntg;
  1069. return 0;
  1070. }
  1071.  
  1072.  
  1073.  
  1074. //==============================================================================
  1075. // Advance
  1076. //==============================================================================
  1077. __dllexp void u8_bcss_ia(struct u8_bcss_i *buf, u32 size)
  1078. {
  1079. u32 off = buf->din - buf->dbeg + size;
  1080.  
  1081. if (off < buf->cbeg - 1)
  1082. buf->din += size;
  1083.  
  1084. else // Wrap around.
  1085. buf->din = buf->dbeg + off - buf->cbeg;
  1086.  
  1087. atmc_fsub(&buf->cin, size);
  1088. atmc_fadd(&buf->cout, size);
  1089. }
  1090.  
  1091.  
  1092. __dllexp void u8_bcss_oa(struct u8_bcss_i *buf, u32 size)
  1093. {
  1094. u32 off = buf->dout - buf->dbeg + size;
  1095.  
  1096. if (off < buf->cbeg - 1)
  1097. buf->dout += size;
  1098.  
  1099. else // Wrap around.
  1100. buf->dout = buf->dbeg + off - buf->cbeg;
  1101.  
  1102. atmc_fsub(&buf->cout, size);
  1103. atmc_fadd(&buf->cin, size);
  1104. }
  1105.  
  1106.  
  1107.  
  1108. //==============================================================================
  1109. // Count
  1110. //==============================================================================
  1111. __dllexp u32 u8_bcss_igc(struct u8_bcss_i *buf)
  1112. {
  1113. return atmc_load(&buf->cin);
  1114. }
  1115.  
  1116.  
  1117. __dllexp u32 u8_bcss_ogc(struct u8_bcss_i *buf)
  1118. {
  1119. return atmc_load(&buf->cout);
  1120. }
  1121.  
  1122.  
  1123.  
  1124. //==============================================================================
  1125. // Contiguous count and pointer
  1126. //==============================================================================
  1127. __dllexp u32 u8_bcss_igcc(struct u8_bcss_i *buf)
  1128. {
  1129. u32 off_in = buf->din - buf->dbeg;
  1130. u32 orig_cin = atmc_load(&buf->cin);
  1131.  
  1132. if (off_in + orig_cin < buf->cbeg - 1)
  1133. return orig_cout;
  1134.  
  1135. return buf->cbeg - off_in;
  1136. }
  1137.  
  1138.  
  1139. __dllexp u8 *u8_bcss_igcp(struct u8_bcss_i *buf)
  1140. {
  1141. return buf->din;
  1142. }
  1143.  
  1144.  
  1145. __dllexp u32 u8_bcss_ogcc(struct u8_bcss_i *buf)
  1146. {
  1147. u32 off_out = buf->dout - buf->dbeg;
  1148. u32 orig_cout = atmc_load(&buf->cout);
  1149.  
  1150. if (off_out + orig_cout < buf->cbeg - 1)
  1151. return orig_cout;
  1152.  
  1153. return buf->cbeg - off_out;
  1154. }
  1155.  
  1156.  
  1157. __dllexp u8 *u8_bcss_ogcp(struct u8_bcss_i *buf)
  1158. {
  1159. return buf->dout;
  1160. }
  1161.  
  1162.  
  1163.  
  1164. //==============================================================================
  1165. // Peeking
  1166. //==============================================================================
  1167. __dllexp u8 u8_bcss_op1(struct u8_bcss_i *buf)
  1168. {
  1169. return buf->dout[0];
  1170. }
  1171.  
  1172.  
  1173. __dllexp u16 u8_bcss_op2(struct u8_bcss_i *buf)
  1174. {
  1175. u8 data[2];
  1176.  
  1177. data[0] = buf->dout[0];
  1178.  
  1179. if (buf->dout <= buf->dbeg + buf->cbeg - 2)
  1180. data[1] = buf->dout[1];
  1181.  
  1182. else
  1183. data[1] = buf->dbeg[0];
  1184.  
  1185. return (u16)data;
  1186. }
  1187.  
  1188.  
  1189.  
  1190. //==============================================================================
  1191. // Input and output
  1192. //==============================================================================
  1193. __dllexp u8 u8_bcss_if(struct u8_bcss_i *buf, u8 (*fin)(void*, u8*, u32, u32*),
  1194. void *arg)
  1195. {
  1196. u32 ret;
  1197.  
  1198. if (unlikely(fin(arg, buf->din, u8_bcss_igcc(buf), &ret)))
  1199. return 1;
  1200.  
  1201. u8_bcss_ia(buf, ret);
  1202. return 0;
  1203. }
  1204.  
  1205.  
  1206. __dllexp u8 u8_bcss_of(struct u8_bcss_i *buf, u8 (*fout)(void*, u8*, u32, u32*),
  1207. void *arg)
  1208. {
  1209. u32 ret;
  1210.  
  1211. if (unlikely(fout(arg, buf->dout, u8_bcss_ogcc(buf), &ret)))
  1212. return 1;
  1213.  
  1214. u8_bcss_oa(buf, ret);
  1215. return 0;
  1216. }
  1217. ./gc-base-lib/1/0/src/ct/u8_ib.c
  1218. //==============================================================================
  1219. // This file is part of Gc-Base-Lib.
  1220. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1221. //
  1222. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1223. // the terms of the GNU General Public License as published by the Free Software
  1224. // Foundation, either version 3 of the License, or (at your option) any later
  1225. // version.
  1226. //
  1227. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1228. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1229. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1230. // details.
  1231. //
  1232. // You should have received a copy of the GNU General Public License along with
  1233. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1234. //==============================================================================
  1235. #include <gc/mem.h>
  1236.  
  1237. #include <gc/u8_ib.h>
  1238.  
  1239.  
  1240.  
  1241. //==============================================================================
  1242. // Initialization and deinitialization
  1243. //==============================================================================
  1244. CT_WRAP_MSI2D1(__dllexp, u8_ib);
  1245.  
  1246.  
  1247. u8 u8_ib_init_ms(struct u8_ib_i *ibuf, struct u8_ib_c *conf)
  1248. {
  1249. MS_BEG(0);
  1250.  
  1251. MS_SP {
  1252. ibuf->buf = mem_alloc(conf->sbuf);
  1253. MS_EV(ibuf->buf != NULL || !conf->sbuf);
  1254. }
  1255.  
  1256. MS_SP { MS_EV(!conf->f->init(ibuf->buf, conf->buf)); }
  1257. MS_SP { ibuf->f = conf->f; }
  1258. return 0;
  1259. }
  1260.  
  1261.  
  1262. void u8_ib_deinit_ms(struct u8_ib_i *ibuf, u8 step)
  1263. {
  1264. MS_BEG(step);
  1265. MS_EM;
  1266. MS_SP { ibuf->f->deinit(ibuf->buf); }
  1267. MS_SP { mem_dealloc(ibuf->buf); }
  1268. }
  1269.  
  1270.  
  1271.  
  1272. //==============================================================================
  1273. // Advance
  1274. //==============================================================================
  1275. __dllexp void u8_ib_ia(struct u8_ib_i *ibuf, u32 size)
  1276. {
  1277. ibuf->f->ia(ibuf->buf, size);
  1278. }
  1279.  
  1280.  
  1281. __dllexp void u8_ib_oa(struct u8_ib_i *ibuf, u32 size)
  1282. {
  1283. ibuf->f->oa(ibuf->buf, size);
  1284. }
  1285.  
  1286.  
  1287.  
  1288. //==============================================================================
  1289. // Count
  1290. //==============================================================================
  1291. __dllexp u32 u8_ib_igc(struct u8_ib_i *ibuf)
  1292. {
  1293. return ibuf->f->igc(ibuf->buf);
  1294. }
  1295.  
  1296.  
  1297. __dllexp u32 u8_ib_ogc(struct u8_ib_i *ibuf)
  1298. {
  1299. return ibuf->f->ogc(ibuf->buf);
  1300. }
  1301.  
  1302.  
  1303.  
  1304. //==============================================================================
  1305. // Contiguous count and pointer
  1306. //==============================================================================
  1307. __dllexp u32 u8_ib_igcc(struct u8_ib_i *ibuf)
  1308. {
  1309. return ibuf->f->igcc(ibuf->buf);
  1310. }
  1311.  
  1312.  
  1313. __dllexp u8 *u8_ib_igcp(struct u8_ib_i *ibuf)
  1314. {
  1315. return ibuf->f->igcp(ibuf->buf);
  1316. }
  1317.  
  1318.  
  1319. __dllexp u32 u8_ib_ogcc(struct u8_ib_i *ibuf)
  1320. {
  1321. return ibuf->f->ogcc(ibuf->buf);
  1322. }
  1323.  
  1324.  
  1325. __dllexp u8 *u8_ib_ogcp(struct u8_ib_i *ibuf)
  1326. {
  1327. return ibuf->f->ogcp(ibuf->buf);
  1328. }
  1329.  
  1330.  
  1331.  
  1332. //==============================================================================
  1333. // Peeking
  1334. //==============================================================================
  1335. __dllexp u8 u8_ib_op1(struct u8_ib_i *ibuf)
  1336. {
  1337. return ibuf->f->op1(ibuf->buf);
  1338. }
  1339.  
  1340.  
  1341. __dllexp u16 u8_ib_op2(struct u8_ib_i *ibuf)
  1342. {
  1343. return ibuf->f->op2(ibuf->buf);
  1344. }
  1345.  
  1346.  
  1347.  
  1348. //==============================================================================
  1349. // Input and output
  1350. //==============================================================================
  1351. __dllexp u8 u8_ib_if(struct u8_ib_i *ibuf, u8 (*fin)(void*, u8*, u32, u32*),
  1352. void *arg)
  1353. {
  1354. return ibuf->if(ibuf->buf, fin, arg);
  1355. }
  1356.  
  1357.  
  1358. __dllexp u8 u8_ib_of(struct u8_ib_i *ibuf, u8 (*fout)(void*, u8*, u32, u32*),
  1359. void *arg)
  1360. {
  1361. return ibuf->of(ibuf->buf, fout, arg);
  1362. }
  1363. ./gc-base-lib/1/0/src/os/unix/err.c
  1364. //==============================================================================
  1365. // This file is part of Gc-Base-Lib.
  1366. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1367. //
  1368. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1369. // the terms of the GNU General Public License as published by the Free Software
  1370. // Foundation, either version 3 of the License, or (at your option) any later
  1371. // version.
  1372. //
  1373. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1374. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1375. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1376. // details.
  1377. //
  1378. // You should have received a copy of the GNU General Public License along with
  1379. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1380. //==============================================================================
  1381. #include <gc/err.h>
  1382.  
  1383. #include <stdio.h>
  1384. #include <string.h>
  1385.  
  1386.  
  1387.  
  1388. //==============================================================================
  1389. // Error handling
  1390. //==============================================================================
  1391. __dllexp void err(void)
  1392. {
  1393. err_en(errno);
  1394. }
  1395.  
  1396.  
  1397. __dllexp void err_en(int en)
  1398. {
  1399. char *msg;
  1400. char buf[256];
  1401.  
  1402. msg = strerror_r(en, buf, 256);
  1403. assert(msg != NULL);
  1404.  
  1405. if (msg != NULL) // Sanity checking.
  1406. err_msg(msg);
  1407. }
  1408.  
  1409.  
  1410. __dllexp void err_msg(const char *msg)
  1411. {
  1412. fprintf(stderr, "%s" ENDL);
  1413. }./gc-base-lib/1/0/src/os/unix/file.c
  1414. //==============================================================================
  1415. // This file is part of Gc-Base-Lib.
  1416. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1417. //
  1418. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1419. // the terms of the GNU General Public License as published by the Free Software
  1420. // Foundation, either version 3 of the License, or (at your option) any later
  1421. // version.
  1422. //
  1423. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1424. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1425. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1426. // details.
  1427. //
  1428. // You should have received a copy of the GNU General Public License along with
  1429. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1430. //==============================================================================
  1431. #include <gc/file.h>
  1432.  
  1433. #include <unistd.h>
  1434.  
  1435.  
  1436.  
  1437. //==============================================================================
  1438. // Initialization and deinitialization
  1439. //==============================================================================
  1440. __dllexp u8 file_init(struct file_i *file, struct file_c *conf)
  1441. {
  1442. if (!(conf->flags & FILE_CREAT))
  1443. file->fd = open(conf->path, conf->flags);
  1444.  
  1445. else
  1446. file->fd = open(conf->path, conf->flags, conf->mode);
  1447.  
  1448. if (unlikely(file->fd == -1))
  1449. return 1;
  1450.  
  1451. return 0;
  1452. }
  1453.  
  1454.  
  1455. __dllexp void file_deinit(struct file_i *file)
  1456. {
  1457. close(file->fd);
  1458. }
  1459.  
  1460.  
  1461.  
  1462. //==============================================================================
  1463. // Read and write
  1464. //==============================================================================
  1465. __dllexp u8 file_read(struct file_i *file, u8 *buf, u32 size, u32 *ret)
  1466. {
  1467. ssize_t bytes = read(file->fd, buf, size);
  1468.  
  1469. if (unlikely(bytes == -1))
  1470. return 1;
  1471.  
  1472. *ret = bytes;
  1473. return 0;
  1474. }
  1475.  
  1476.  
  1477. __dllexp u8 file_write(struct file_i *file, u8 *buf, u32 size, u32 *ret)
  1478. {
  1479. ssize_t bytes = write(file->fd, buf, size);
  1480.  
  1481. if (unlikely(bytes == -1))
  1482. return 1;
  1483.  
  1484. *ret = bytes;
  1485. return 0;
  1486. }
  1487.  
  1488.  
  1489.  
  1490. //==============================================================================
  1491. // Utility
  1492. //==============================================================================
  1493. __dllexp u8 file_gstats(struct file_i *file, struct file_stats *stats)
  1494. {
  1495. if (unlikely(fstat(file->fd, &stats->data)))
  1496. return 1;
  1497.  
  1498. return 0;
  1499. }
  1500. ./gc-base-lib/1/0/src/os/unix/mem.c
  1501. //==============================================================================
  1502. // This file is part of Gc-Base-Lib.
  1503. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1504. //
  1505. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1506. // the terms of the GNU General Public License as published by the Free Software
  1507. // Foundation, either version 3 of the License, or (at your option) any later
  1508. // version.
  1509. //
  1510. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1511. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1512. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1513. // details.
  1514. //
  1515. // You should have received a copy of the GNU General Public License along with
  1516. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1517. //==============================================================================
  1518. #include <gc/mem.h>
  1519.  
  1520. #include <stdlib.h>
  1521. #include <string.h>
  1522.  
  1523.  
  1524.  
  1525. //==============================================================================
  1526. // Allocation, reallocation and deallocation
  1527. //==============================================================================
  1528. __dllexp void *mem_alloc(size_t size)
  1529. {
  1530. return malloc(size);
  1531. }
  1532.  
  1533.  
  1534. __dllexp void *mem_realloc(void *ptr, size_t size)
  1535. {
  1536. return realloc(ptr, size);
  1537. }
  1538.  
  1539.  
  1540. __dllexp void mem_dealloc(void *ptr)
  1541. {
  1542. free(ptr);
  1543. }
  1544.  
  1545.  
  1546.  
  1547. //==============================================================================
  1548. // Utility
  1549. //==============================================================================
  1550. __dllexp s8 mem_comp(void *data1, void *data2, size_t size)
  1551. {
  1552. return memcmp(data1, data2, size);
  1553. }
  1554.  
  1555.  
  1556. __dllexp void mem_copy(void *dest, void *src, size_t size)
  1557. {
  1558. memcpy(dest, src, size);
  1559. }
  1560.  
  1561.  
  1562. __dllexp void mem_move(void *dest, void *src, size_t size)
  1563. {
  1564. memmove(dest, src, size);
  1565. }
  1566.  
  1567.  
  1568. __dllexp void mem_set(void *ptr, u8 data, size_t size)
  1569. {
  1570. memset(ptr, data, size);
  1571. }
  1572. ./gc-base-lib/1/0/src/os/unix/proc.c
  1573. //==============================================================================
  1574. // This file is part of Gc-Base-Lib.
  1575. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1576. //
  1577. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1578. // the terms of the GNU General Public License as published by the Free Software
  1579. // Foundation, either version 3 of the License, or (at your option) any later
  1580. // version.
  1581. //
  1582. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1583. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1584. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1585. // details.
  1586. //
  1587. // You should have received a copy of the GNU General Public License along with
  1588. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1589. //==============================================================================
  1590. // proc_st_init, proc_st_next, ...
  1591. #include <gc/proc.h>
  1592.  
  1593.  
  1594.  
  1595. //==============================================================================
  1596. // Execution
  1597. //==============================================================================
  1598. __dllexp u8 proc_exec(void)
  1599. {
  1600. }
  1601. ./gc-base-lib/1/0/src/pt/u8.c
  1602. //==============================================================================
  1603. // This file is part of Gc-Base-Lib.
  1604. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1605. //
  1606. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1607. // the terms of the GNU General Public License as published by the Free Software
  1608. // Foundation, either version 3 of the License, or (at your option) any later
  1609. // version.
  1610. //
  1611. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1612. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1613. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1614. // details.
  1615. //
  1616. // You should have received a copy of the GNU General Public License along with
  1617. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1618. //==============================================================================
  1619. #include <gc/u8.h>
  1620.  
  1621.  
  1622.  
  1623. //==============================================================================
  1624. // Ranges and values
  1625. //==============================================================================
  1626. __dllexp u8 u8_rma(u8 data, u8 *arng, u8 crng)
  1627. {
  1628. while (crng) {
  1629. if (data >= *arng && data <= *(++arng))
  1630. return 0;
  1631.  
  1632. ++arng;
  1633. --crng;
  1634. }
  1635.  
  1636. return 1;
  1637. }
  1638.  
  1639.  
  1640. __dllexp u8_vma(u8 data, u8 *aval, u8 cval)
  1641. {
  1642. while (cval) {
  1643. if (data == *aval)
  1644. return 0;
  1645.  
  1646. ++aval;
  1647. --cval;
  1648. }
  1649.  
  1650. return 1;
  1651. }
  1652. ./gc-base-lib/1/0/src/util/pars.c
  1653. //==============================================================================
  1654. // This file is part of Gc-Base-Lib.
  1655. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1656. //
  1657. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1658. // the terms of the GNU General Public License as published by the Free Software
  1659. // Foundation, either version 3 of the License, or (at your option) any later
  1660. // version.
  1661. //
  1662. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1663. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1664. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1665. // details.
  1666. //
  1667. // You should have received a copy of the GNU General Public License along with
  1668. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1669. //==============================================================================
  1670. #include <gc/pars.h>
  1671.  
  1672. // If it is possible to convert between buffer types, this should probably be
  1673. // moved to u8_a. u8_a_nlcs et al.
  1674. //
  1675. // This parser requires exclusive access the the buffer region provided by buf.
  1676. // For multiple reader buffers, it's expected that a block of data will be read,
  1677. // converted to a u8_b for the parser, and treated as a contiguous array.
  1678.  
  1679. ./gc-base-lib/1/0/test/conf/strerror_r-1.c
  1680. //==============================================================================
  1681. // This file is part of Gc-Base-Lib.
  1682. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1683. //
  1684. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1685. // the terms of the GNU General Public License as published by the Free Software
  1686. // Foundation, either version 3 of the License, or (at your option) any later
  1687. // version.
  1688. //
  1689. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1690. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1691. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1692. // details.
  1693. //
  1694. // You should have received a copy of the GNU General Public License along with
  1695. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1696. //==============================================================================
  1697. #include <gc/err.h>
  1698.  
  1699. #include <string.h>
  1700.  
  1701.  
  1702.  
  1703. //==============================================================================
  1704. // Handle invalid "errno"
  1705. //==============================================================================
  1706. // Ideally, this kind of test would be loaded by "dlopen()", used and then
  1707. // unloaded.
  1708. int main(void)
  1709. {
  1710. int aen[] = {INT_MIN, -ERR_ENMAX, -1, ERR_ENMAX, INT_MAX};
  1711. char *msg;
  1712. char buf[256];
  1713.  
  1714. for (i = 0; i < 5; ++i) {
  1715. // The manual page for "strerror()" states that the function can return
  1716. // "NULL" on some systems if it encounters an unknown error number.
  1717. //
  1718. // This test verifies that "strerror_r()" does not return "NULL" if it
  1719. // encounters an unknown error number. It does not, however, confirm
  1720. // that the system actually has an implementation of "strerror()" that
  1721. // is problematic. In the future, dependency tracking for tests should
  1722. // be added to ensure that the number of unnecessary tests being run is
  1723. // kept to a minimum.
  1724. msg = strerror_r(aen[i], buf, 256);
  1725.  
  1726. if (msg != NULL)
  1727. continue;
  1728.  
  1729. fprintf(stderr,
  1730. "Test failed: \"strerror_r()\" - Handle invalid \"errno\"." ENDL);
  1731. return 1;
  1732. }
  1733.  
  1734. return 0;
  1735. }./gc-base-lib/2/0/inc/gc/aiobk.h
  1736. 3//==============================================================================
  1737. // This file is part of Gc-Base-Lib.
  1738. // Kernel asynchronous, unbuffered I/O for block devices and files
  1739. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1740. //
  1741. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1742. // the terms of the GNU General Public License as published by the Free Software
  1743. // Foundation, either version 3 of the License, or (at your option) any later
  1744. // version.
  1745. //
  1746. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1747. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1748. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1749. // details.
  1750. //
  1751. // You should have received a copy of the GNU General Public License along with
  1752. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1753. //==============================================================================
  1754. #pragma once
  1755.  
  1756. #include <gc/base.h>
  1757.  
  1758. #include <linux/aio_abi.h>
  1759.  
  1760.  
  1761.  
  1762. //==============================================================================
  1763. // General
  1764. //==============================================================================
  1765. struct aiobk_i {
  1766. aio_context_t ctx;
  1767. };
  1768.  
  1769. struct aiobk_c {
  1770. u16 cev;
  1771. };./gc-base-lib/2/0/src/ct/it.c
  1772. ./gc-base-lib/2/0/src/ct/tavl.c
  1773. ./gc-base-lib/2/0/src/ct/trbll.c
  1774. ./gc-base-lib/2/0/src/os/linux/aio.txt
  1775. kernel aio linux 512, 2048 or other sector size, as determined by the underlying
  1776. block device. can get this value via ioctl.
  1777.  
  1778. also can do simple kernel aio implementation better than libaio. use this instead.
  1779. see firefox bookmark "own aio impl" x2
  1780.  
  1781. aio works for block size increments. reads / writes other than that size to the
  1782. beginning or end of the file will be blocking. see firefox bookmark "blocking aio".
  1783. this has not been verified.
  1784. ./gc-base-lib/2/0/src/os/linux/aiobk.c
  1785. //==============================================================================
  1786. // This file is part of Gc-Base-Lib.
  1787. // Kernel asynchronous, unbuffered I/O for block devices and files
  1788. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1789. //
  1790. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1791. // the terms of the GNU General Public License as published by the Free Software
  1792. // Foundation, either version 3 of the License, or (at your option) any later
  1793. // version.
  1794. //
  1795. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1796. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1797. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1798. // details.
  1799. //
  1800. // You should have received a copy of the GNU General Public License along with
  1801. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1802. //==============================================================================
  1803. #include <gc/macro/wrap_unix.h>
  1804.  
  1805. #include <gc/aiobk.h>
  1806.  
  1807. #include <sys/syscall.h>
  1808.  
  1809.  
  1810.  
  1811. //==============================================================================
  1812. // Initialization and deinitialization
  1813. //==============================================================================
  1814. __dllexp u8 aiobk_init(struct aiobk_i *aiobk, struct aiobk_c *conf)
  1815. {
  1816. aiobk->ctx = 0; // Required by the kernel.
  1817. WRAP_UNIX(io_setup(conf->cev, &aiobk->ctx));
  1818. }
  1819.  
  1820.  
  1821. __dllexp void aiobk_deinit(struct aiobk_i *aiobk)
  1822. WRAP_UNIX_NR(io_destroy(aiobk->ctx));./gc-base-lib/2/0/src/os/linux/this_dir.txt
  1823. linux specific things like signalfd, timerfd, kernel aio go in this directory
  1824. ./gc-base-lib/2/0/src/os/unix/cnd.c
  1825. ./gc-base-lib/2/0/src/os/unix/cnd_attr.c
  1826. ./gc-base-lib/2/0/src/os/unix/mtx.c
  1827. ./gc-base-lib/2/0/src/os/unix/mtx_attr.c
  1828. ./gc-base-lib/2/0/src/os/unix/pcnd.c
  1829. ./gc-base-lib/2/0/src/os/unix/pmtx.c
  1830. ./gc-base-lib/2/0/src/os/unix/thrd.c
  1831. ./gc-base-lib/2/0/src/svc/atq.c
  1832. ./gc-base-lib/2/0/src/svc/tpool_a.c
  1833. //==============================================================================
  1834. // This file is part of Gc-Base-Lib.
  1835. // Copyright (C) 2016-2017 Anthony Gorecki <agorecki@gcproj.org>
  1836. //
  1837. // Gc-Base-Lib is free software: you can redistribute it and/or modify it under
  1838. // the terms of the GNU General Public License as published by the Free Software
  1839. // Foundation, either version 3 of the License, or (at your option) any later
  1840. // version.
  1841. //
  1842. // Gc-Base-Lib is distributed in the hope that it will be useful, but WITHOUT
  1843. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1844. // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1845. // details.
  1846. //
  1847. // You should have received a copy of the GNU General Public License along with
  1848. // Gc-Base-Lib. If not, see <http://www.gnu.org/licenses/>.
  1849. //==============================================================================
  1850. #include <gc/tpool_a.h>
  1851.  
  1852.  
  1853.  
  1854. //==============================================================================
  1855. // Worker thread functions
  1856. //==============================================================================
  1857. __dllexp u8 tpool_a_t_check(struct tpool_a_i *pool)
  1858. {
  1859. u8 ret = 0;
  1860.  
  1861. // Note: the loop below will initialize new threads until the minimum number
  1862. // of spare and total threads are available. Other spare threads will also
  1863. // be initializing threads, therefore the loop will determine whether to
  1864. // initialize another thread after each iteration.
  1865.  
  1866. for (;;) {
  1867. mtx_lock(&pool->mtx);
  1868.  
  1869. // Check lower bounds.
  1870. if (pool->sc_cur + pool->c_init >= pool->sc_min
  1871. && pool->c_cur + pool->c_init >= pool->c_min)
  1872. break;
  1873.  
  1874. if (!ret)
  1875. ++pool->c_init;
  1876.  
  1877. mtx_unlock(&pool->mtx);
  1878. ret = thrd_init(&tpool_a_t_main, pool); // Needs progressive back off.
  1879. }
  1880.  
  1881. if (unlikely(ret)) {
  1882. --pool->c_init;
  1883. ret = 0;
  1884. }
  1885.  
  1886. // Note: the thread pool might have been reconfigured while a thread was
  1887. // being initialized above. It might be necessary to terminate the current
  1888. // thread just after creating a new thread.
  1889.  
  1890. // Check upper bounds.
  1891. if (unlikely(pool->sc_cur - pool->c_deinit > pool->sc_max
  1892. || pool->c_cur - pool->c_deinit > pool->c_max)) {
  1893. ++pool->c_deinit;
  1894. ret = 1;
  1895. }
  1896.  
  1897. mtx_unlock(&pool->mtx);
  1898. return ret;
  1899. }
  1900.  
  1901.  
  1902. __dllexp void tpool_a_t_main(struct tpool_a_i *pool)
  1903. {
  1904. u8 ret = 0;
  1905. void *cont = pool - pool->off_cont;
  1906.  
  1907. if (pool->fp_init != NULL)
  1908. ret = pool->fp_init(cont);
  1909.  
  1910. mtx_lock(&pool->mtx);
  1911. --pool->c_init;
  1912.  
  1913. if (!ret) {
  1914. ++pool->c_cur;
  1915. ++pool->sc_cur; // ...
  1916. }
  1917.  
  1918. if (unlikely(ret)) {
  1919. mtx_unlock(&pool->mtx);
  1920. return;
  1921. }
  1922.  
  1923. for (;;) {
  1924. --pool->sc_cur;
  1925. mtx_unlock(&pool->mtx);
  1926.  
  1927. ret = pool->fp_run(cont);
  1928.  
  1929. mtx_lock(&pool->mtx);
  1930. ++pool->sc_cur;
  1931.  
  1932. if (unlikely(tpool_a_t_check(pool)))
  1933. break;
  1934.  
  1935. if (unlikely(ret)) {
  1936. mtx_unlock(&pool->mtx);
  1937. pool->fp_wait(cont);
  1938. }
  1939. }
  1940.  
  1941. --pool->c_cur;
  1942. --pool->sc_cur;
  1943. mtx_unlock(&pool->mtx);
  1944.  
  1945. if (pool->fp_deinit != NULL)
  1946. pool->fp_deinit(cont);
  1947. }./gc-base-lib/backup_location.txt
  1948. Sun, Dec 06, 2015 12:22:00 AM: http://pastebin.com/0TM8sLZW
  1949. Wed, Dec 09, 2015 2:56:04 AM:
  1950. ./_script/intrn/upload-pastebin.py
  1951. import pastebin_python
  1952. import sys
  1953.  
  1954. pb = pastebin_python.pastebin.PastebinPython(api_dev_key=sys.argv[1])
  1955. print pb.createPasteFromFile('upload-data.txt', 'anthony gorecki anthony@anthonygorecki.ca', '', '0', 'N')
  1956. ./_script/upload-pastebin.sh
  1957. cd /home/agorecki/dev
  1958.  
  1959. echo 'Files:'
  1960.  
  1961. files=$(find -name '*.c' -o -name '*.h' -o -name '*.py' -o -name '*.sh' -o -name '*.txt' -o -name '.vimrc')
  1962.  
  1963. date > upload-data.txt
  1964.  
  1965. for file in $files; do
  1966. echo " $file"
  1967. echo $file >> upload-data.txt
  1968. cat $file >> upload-data.txt
  1969. done
  1970.  
  1971. echo
  1972. echo -n 'URL: '
  1973. url=$(python2 ./_script/intrn/upload-pastebin.py `cat _script/intrn/dev-key`)
  1974. echo $url
  1975. rm upload-data.txt
  1976.  
  1977. echo -n `date` >> gc-base-lib/backup_location.txt
  1978. echo ": $url" >> gc-base-lib/backup_location.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement