summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-05-24 19:47:16 +0200
committerTyge Løvset <[email protected]>2023-05-24 19:47:16 +0200
commitc3e01470f45f19215fac339302d87b5d73a323e8 (patch)
treea573d484fafc4bee8503c4af7eee1b61ab098010 /include
parent276b8110033aa275f58ce60d096f220ca050738c (diff)
downloadSTC-modified-c3e01470f45f19215fac339302d87b5d73a323e8.tar.gz
STC-modified-c3e01470f45f19215fac339302d87b5d73a323e8.zip
More coro adjustments.
Diffstat (limited to 'include')
-rw-r--r--include/stc/algo/coroutine.h17
-rw-r--r--include/stc/csview.h31
2 files changed, 26 insertions, 22 deletions
diff --git a/include/stc/algo/coroutine.h b/include/stc/algo/coroutine.h
index ebfed613..fdce2629 100644
--- a/include/stc/algo/coroutine.h
+++ b/include/stc/algo/coroutine.h
@@ -141,12 +141,17 @@ typedef struct {
*/
#include <time.h>
-#include <sys/time.h>
-
-static inline void csleep_us(int64_t usec) {
- struct timeval tv = {.tv_sec=(int)(usec/1000000), .tv_usec=usec % 1000000};
- select(0, NULL, NULL, NULL, &tv);
-}
+#if defined _WIN32 && !defined __GNUC__
+ static inline void csleep_ms(long msec) {
+ extern void Sleep(unsigned long);
+ Sleep((unsigned long)msec);
+ }
+#else
+ static inline void csleep_ms(long msec) {
+ struct timespec ts = {msec/1000, 1000000*(msec % 1000)};
+ nanosleep(&ts, NULL);
+ }
+#endif
typedef struct {
clock_t start;
diff --git a/include/stc/csview.h b/include/stc/csview.h
index 571bb278..e8a3ad9b 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -33,7 +33,12 @@
#define csview_lit(literal) c_sv_1(literal)
#define csview_from_n(str, n) c_sv_2(str, n)
-STC_API intptr_t csview_find_sv(csview sv, csview search);
+STC_API csview_iter csview_advance(csview_iter it, intptr_t pos);
+STC_API intptr_t csview_find_sv(csview sv, csview search);
+STC_API uint64_t csview_hash(const csview *self);
+STC_API csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2);
+STC_API csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n);
+STC_API csview csview_token(csview sv, const char* sep, intptr_t* start);
STC_INLINE csview csview_from(const char* str)
{ return c_LITERAL(csview){str, c_strlen(str)}; }
@@ -87,15 +92,6 @@ STC_INLINE void csview_next(csview_iter* it) {
it->u8.chr.size = utf8_chr_size(it->ref);
if (it->ref == it->u8.end) it->ref = NULL;
}
-STC_INLINE csview_iter csview_advance(csview_iter it, intptr_t pos) {
- int inc = -1;
- if (pos > 0) pos = -pos, inc = 1;
- while (pos && it.ref != it.u8.end) pos += (*(it.ref += inc) & 0xC0) != 0x80;
- it.u8.chr.size = utf8_chr_size(it.ref);
- if (it.ref == it.u8.end) it.ref = NULL;
- return it;
-}
-
/* utf8 */
STC_INLINE intptr_t csview_u8_size(csview sv)
@@ -110,10 +106,6 @@ STC_INLINE csview csview_u8_substr(csview sv, intptr_t bytepos, intptr_t u8len)
STC_INLINE bool csview_valid_utf8(csview sv) // depends on src/utf8code.c
{ return utf8_valid_n(sv.str, sv.size); }
-STC_API csview csview_substr_ex(csview sv, intptr_t pos, intptr_t n);
-STC_API csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2);
-STC_API csview csview_token(csview sv, const char* sep, intptr_t* start);
-
#define c_fortoken_sv(it, inputsv, sep) \
for (struct { csview _inp, token, *ref; const char *_sep; intptr_t pos; } \
it = {._inp=inputsv, .token=it._inp, .ref=&it.token, ._sep=sep} \
@@ -155,11 +147,18 @@ STC_INLINE int csview_icmp(const csview* x, const csview* y)
STC_INLINE bool csview_eq(const csview* x, const csview* y)
{ return x->size == y->size && !c_memcmp(x->str, y->str, x->size); }
-STC_API uint64_t csview_hash(const csview *self);
-
/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(i_implement)
+STC_DEF csview_iter csview_advance(csview_iter it, intptr_t pos) {
+ int inc = -1;
+ if (pos > 0) pos = -pos, inc = 1;
+ while (pos && it.ref != it.u8.end) pos += (*(it.ref += inc) & 0xC0) != 0x80;
+ it.u8.chr.size = utf8_chr_size(it.ref);
+ if (it.ref == it.u8.end) it.ref = NULL;
+ return it;
+}
+
STC_DEF intptr_t csview_find_sv(csview sv, csview search) {
char* res = cstrnstrn(sv.str, search.str, sv.size, search.size);
return res ? (res - sv.str) : c_NPOS;