renamed some time functions - e.g. qse_addtime to qse_add_ntime, qse_subtime to qse_sub_ntime, etc
moved the position of result parameter from the third position to the first position in qse_add_ntime() and qse_sub_ntime()
This commit is contained in:
		| @ -969,7 +969,7 @@ static int httpd_main (int argc, qse_char_t* argv[]) | ||||
| 	while (!g_stop_requested) | ||||
| 	{ | ||||
| 		qse_ntime_t tmout; | ||||
| 		qse_cleartime (&tmout); | ||||
| 		qse_clear_ntime (&tmout); | ||||
|  | ||||
| 		/* if there are pending requests, use timeout of 0. | ||||
| 		 * this way, multiplexer events and pending requests can be | ||||
|  | ||||
| @ -130,32 +130,32 @@ struct qse_btime_t | ||||
| typedef qse_long_t qse_mtime_t; | ||||
|  | ||||
| #if defined(QSE_HAVE_INLINE) | ||||
| 	static QSE_INLINE void qse_inittime(qse_ntime_t* x, qse_ntime_sec_t s, qse_ntime_nsec_t nsec) | ||||
| 	static QSE_INLINE void qse_init_ntime(qse_ntime_t* x, qse_ntime_sec_t s, qse_ntime_nsec_t nsec) | ||||
| 	{ | ||||
| 		x->sec = s; | ||||
| 		x->nsec = nsec; | ||||
| 	} | ||||
| 	static QSE_INLINE void qse_cleartime(qse_ntime_t* x) {	qse_inittime (x, 0, 0); } | ||||
| 	/*static QSE_INLINE int qse_cmptime(const qse_ntime_t* x, const qse_ntime_t* y) | ||||
| 	static QSE_INLINE void qse_clear_ntime(qse_ntime_t* x) { qse_init_ntime (x, 0, 0); } | ||||
| 	/*static QSE_INLINE int qse_cmp_ntime(const qse_ntime_t* x, const qse_ntime_t* y) | ||||
| 	{ | ||||
| 		// TODO: fix the type and value range issue and replace the macro below. | ||||
| 		return (x->sec == y->sec)? (x->nsec - y->nsec): (x->sec - y->sec); | ||||
| 	}*/ | ||||
| #	define qse_cmptime(x,y) (((x)->sec == (y)->sec)? ((x)->nsec - (y)->nsec): ((x)->sec - (y)->sec)) | ||||
| #	define qse_cmp_ntime(x,y) (((x)->sec == (y)->sec)? ((x)->nsec - (y)->nsec): ((x)->sec - (y)->sec)) | ||||
|  | ||||
| 	static QSE_INLINE int qse_isnegtime(qse_ntime_t* x) { return x->sec < 0; } | ||||
| 	static QSE_INLINE int qse_ispostime(qse_ntime_t* x) { return x->sec > 0 || (x->sec == 0 && x->nsec > 0); } | ||||
| 	static QSE_INLINE int qse_iszerotime(qse_ntime_t* x) { return x->sec == 0 && x->nsec == 0; } | ||||
| 	static QSE_INLINE int qse_is_neg_ntime(qse_ntime_t* x) { return x->sec < 0; } | ||||
| 	static QSE_INLINE int qse_is_pos_ntime(qse_ntime_t* x) { return x->sec > 0 || (x->sec == 0 && x->nsec > 0); } | ||||
| 	static QSE_INLINE int qse_is_zero_ntime(qse_ntime_t* x) { return x->sec == 0 && x->nsec == 0; } | ||||
| #else | ||||
| #	define qse_inittime(x,s,ns) (((x)->sec = (s)), ((x)->nsec = (ns))) | ||||
| #	define qse_cleartime(x) qse_inittime(x,0,0) | ||||
| #	define qse_cmptime(x,y) (((x)->sec == (y)->sec)? ((x)->nsec - (y)->nsec): ((x)->sec - (y)->sec)) | ||||
| #	define qse_init_ntime(x,s,ns) (((x)->sec = (s)), ((x)->nsec = (ns))) | ||||
| #	define qse_clear_ntime(x) qse_init_ntime(x,0,0) | ||||
| #	define qse_cmp_ntime(x,y) (((x)->sec == (y)->sec)? ((x)->nsec - (y)->nsec): ((x)->sec - (y)->sec)) | ||||
|  | ||||
| /* if time has been normalized properly, nsec must be equal to or | ||||
|  * greater than 0. */ | ||||
| #	define qse_isnegtime(x) ((x)->sec < 0) | ||||
| #	define qse_ispostime(x) ((x)->sec > 0 || ((x)->sec == 0 && (x)->nsec > 0)) | ||||
| #	define qse_iszerotime(x) ((x)->sec == 0 && (x)->nsec == 0) | ||||
| #	define qse_is_neg_ntime(x) ((x)->sec < 0) | ||||
| #	define qse_is_pos_ntime(x) ((x)->sec > 0 || ((x)->sec == 0 && (x)->nsec > 0)) | ||||
| #	define qse_is_zero_ntime(x) ((x)->sec == 0 && (x)->nsec == 0) | ||||
| #endif | ||||
|  | ||||
|  | ||||
| @ -220,26 +220,26 @@ QSE_EXPORT int qse_timelocal ( | ||||
| ); | ||||
|  | ||||
| /** | ||||
|  * The qse_addtime() function adds x and y and stores the result in z  | ||||
|  * The qse_add_time() function adds x and y and stores the result in z  | ||||
|  */ | ||||
| QSE_EXPORT void qse_addtime ( | ||||
| QSE_EXPORT void qse_add_ntime ( | ||||
| 	qse_ntime_t*       z, | ||||
| 	const qse_ntime_t* x, | ||||
| 	const qse_ntime_t* y, | ||||
| 	qse_ntime_t*       z | ||||
| 	const qse_ntime_t* y | ||||
| ); | ||||
|  | ||||
| /** | ||||
|  * The qse_subtime() function subtract y from x and stores the result in z. | ||||
|  * The qse_sub_time() function subtract y from x and stores the result in z. | ||||
|  */ | ||||
| QSE_EXPORT void qse_subtime ( | ||||
| QSE_EXPORT void qse_sub_ntime ( | ||||
| 	qse_ntime_t*       z, | ||||
| 	const qse_ntime_t* x, | ||||
| 	const qse_ntime_t* y, | ||||
| 	qse_ntime_t*       z | ||||
| 	const qse_ntime_t* y | ||||
| ); | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * The qse_strtontime() function converts a numeric text to the numeric time. | ||||
|  * The qse_mbs_to_ntime() function converts a numeric text to the numeric time. | ||||
|  *  seconds.nanoseconds | ||||
|  *  10.231 | ||||
|  */ | ||||
|  | ||||
| @ -614,7 +614,7 @@ int qse_timelocal (const qse_btime_t* bt, qse_ntime_t* nt) | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void qse_addtime (const qse_ntime_t* x, const qse_ntime_t* y, qse_ntime_t* z) | ||||
| void qse_add_ntime (qse_ntime_t* z, const qse_ntime_t* x, const qse_ntime_t* y) | ||||
| { | ||||
| 	QSE_ASSERT (x->nsec >= 0 && x->nsec < QSE_NSECS_PER_SEC); | ||||
| 	QSE_ASSERT (y->nsec >= 0 && y->nsec < QSE_NSECS_PER_SEC); | ||||
| @ -679,7 +679,7 @@ void qse_addtime (const qse_ntime_t* x, const qse_ntime_t* y, qse_ntime_t* z) | ||||
| #endif | ||||
| } | ||||
|  | ||||
| void qse_subtime (const qse_ntime_t* x, const qse_ntime_t* y, qse_ntime_t* z) | ||||
| void qse_sub_ntime (qse_ntime_t* z, const qse_ntime_t* x, const qse_ntime_t* y) | ||||
| { | ||||
| 	QSE_ASSERT (x->nsec >= 0 && x->nsec < QSE_NSECS_PER_SEC); | ||||
| 	QSE_ASSERT (y->nsec >= 0 && y->nsec < QSE_NSECS_PER_SEC); | ||||
|  | ||||
| @ -31,7 +31,7 @@ | ||||
| #define HEAP_LEFT(x)   ((x) * 2 + 1) | ||||
| #define HEAP_RIGHT(x)  ((x) * 2 + 2) | ||||
|  | ||||
| #define YOUNGER_THAN(x,y) (qse_cmptime(&(x)->when, &(y)->when) < 0) | ||||
| #define YOUNGER_THAN(x,y) (qse_cmp_ntime(&(x)->when, &(y)->when) < 0) | ||||
|  | ||||
| qse_tmr_t* qse_tmr_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_size_t capa) | ||||
| { | ||||
| @ -240,7 +240,7 @@ int qse_tmr_fire (qse_tmr_t* tmr, const qse_ntime_t* tm, qse_size_t* firecnt) | ||||
|  | ||||
| 	while (tmr->size > 0) | ||||
| 	{ | ||||
| 		if (qse_cmptime(&tmr->event[0].when, &now) > 0) break; | ||||
| 		if (qse_cmp_ntime(&tmr->event[0].when, &now) > 0) break; | ||||
|  | ||||
| 		event = tmr->event[0]; | ||||
| 		qse_tmr_delete (tmr, 0); /* remove the registered event structure */ | ||||
| @ -264,8 +264,8 @@ int qse_tmr_gettmout (qse_tmr_t* tmr, const qse_ntime_t* tm, qse_ntime_t* tmout) | ||||
| 	if (tm) now = *tm; | ||||
| 	else if (qse_gettime(&now) <= -1) return -1; | ||||
|  | ||||
| 	qse_subtime (&tmr->event[0].when, &now, tmout); | ||||
| 	if (tmout->sec < 0) qse_cleartime (tmout); | ||||
| 	qse_sub_ntime (tmout, &tmr->event[0].when, &now); | ||||
| 	if (qse_is_neg_ntime(tmout)) qse_clear_ntime (tmout); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| @ -838,7 +838,7 @@ static void tmr_dns_tmout_handle (qse_tmr_t* tmr, const qse_ntime_t* now, qse_tm | ||||
|  | ||||
| 		QSE_MEMSET (&tmout_event, 0, QSE_SIZEOF(tmout_event)); | ||||
| 		qse_gettime (&tmout_event.when); | ||||
| 		qse_addtime (&tmout_event.when, &req->dns_tmout, &tmout_event.when); | ||||
| 		qse_add_ntime (&tmout_event.when, &req->dns_tmout, &tmout_event.when); | ||||
| 		tmout_event.ctx = req; | ||||
| 		tmout_event.handler = tmr_dns_tmout_handle; | ||||
| 		tmout_event.updater = tmr_dns_tmout_update; | ||||
| @ -1006,7 +1006,7 @@ static int dns_send (qse_httpd_t* httpd, qse_httpd_dns_t* dns, const qse_mchar_t | ||||
|  | ||||
| 	QSE_MEMSET (&tmout_event, 0, QSE_SIZEOF(tmout_event)); | ||||
| 	qse_gettime (&tmout_event.when); | ||||
| 	qse_addtime (&tmout_event.when, &req->dns_tmout, &tmout_event.when); | ||||
| 	qse_add_ntime (&tmout_event.when, &req->dns_tmout, &tmout_event.when); | ||||
| 	tmout_event.ctx = req; | ||||
| 	tmout_event.handler = tmr_dns_tmout_handle; | ||||
| 	tmout_event.updater = tmr_dns_tmout_update; | ||||
|  | ||||
| @ -364,7 +364,7 @@ static void tmr_urs_tmout_handle (qse_tmr_t* tmr, const qse_ntime_t* now, qse_tm | ||||
|  | ||||
| 		QSE_MEMSET (&tmout_event, 0, QSE_SIZEOF(tmout_event)); | ||||
| 		qse_gettime (&tmout_event.when); | ||||
| 		qse_addtime (&tmout_event.when, &req->urs_tmout, &tmout_event.when); | ||||
| 		qse_add_ntime (&tmout_event.when, &req->urs_tmout, &tmout_event.when); | ||||
| 		tmout_event.ctx = req; | ||||
| 		tmout_event.handler = tmr_urs_tmout_handle; | ||||
| 		tmout_event.updater = tmr_urs_tmout_update; | ||||
| @ -506,7 +506,7 @@ static int urs_send (qse_httpd_t* httpd, qse_httpd_urs_t* urs, const qse_mchar_t | ||||
|  | ||||
| 	QSE_MEMSET (&tmout_event, 0, QSE_SIZEOF(tmout_event)); | ||||
| 	qse_gettime (&tmout_event.when); | ||||
| 	qse_addtime (&tmout_event.when, &req->urs_tmout, &tmout_event.when); | ||||
| 	qse_add_ntime (&tmout_event.when, &req->urs_tmout, &tmout_event.when); | ||||
| 	tmout_event.ctx = req; | ||||
| 	tmout_event.handler = tmr_urs_tmout_handle; | ||||
| 	tmout_event.updater = tmr_urs_tmout_update; | ||||
|  | ||||
| @ -558,8 +558,8 @@ qse_httpd_peer_t* qse_httpd_decacheproxypeer ( | ||||
| 	{ | ||||
| 		next = peer->next; | ||||
|  | ||||
| 		qse_subtime (&now, &peer->timestamp, &diff); | ||||
| 		if (qse_cmptime(&diff, &diff_limit) >= 0) | ||||
| 		qse_sub_ntime (&diff, &now, &peer->timestamp); | ||||
| 		if (qse_cmp_ntime(&diff, &diff_limit) >= 0) | ||||
| 		{ | ||||
| 			/* the entry is too old */ | ||||
| 			purge_cached_proxy_peer (httpd, client, peer); | ||||
| @ -644,7 +644,7 @@ static qse_httpd_client_t* new_client (qse_httpd_t* httpd, qse_httpd_client_t* t | ||||
| 		/* idle limit is enabled when the limit is greater than 0.0 */ | ||||
| 		QSE_MEMSET (&idle_event, 0, QSE_SIZEOF(idle_event)); | ||||
| 		qse_gettime (&idle_event.when); | ||||
| 		qse_addtime (&idle_event.when, &httpd->opt.idle_limit, &idle_event.when); | ||||
| 		qse_add_ntime (&idle_event.when, &httpd->opt.idle_limit, &idle_event.when); | ||||
| 		idle_event.ctx = client; | ||||
| 		idle_event.handler = tmr_idle_handle; | ||||
| 		idle_event.updater = tmr_idle_update; | ||||
| @ -894,11 +894,11 @@ static void tmr_idle_handle (qse_tmr_t* tmr, const qse_ntime_t* now, qse_tmr_eve | ||||
| { | ||||
| 	qse_httpd_client_t* client = (qse_httpd_client_t*)evt->ctx; | ||||
|  | ||||
| 	if (qse_cmptime(now, &client->last_active) >= 0) | ||||
| 	if (qse_cmp_ntime(now, &client->last_active) >= 0) | ||||
| 	{ | ||||
| 		qse_ntime_t diff; | ||||
| 		qse_subtime (now, &client->last_active, &diff); | ||||
| 		if (qse_cmptime(&diff, &client->server->httpd->opt.idle_limit) >= 0) | ||||
| 		qse_sub_ntime (&diff, now, &client->last_active); | ||||
| 		if (qse_cmp_ntime(&diff, &client->server->httpd->opt.idle_limit) >= 0) | ||||
| 		{ | ||||
| 			/* this client is idle */ | ||||
| 			HTTPD_DBGOUT1 ("Purging idle client %zd\n", (qse_size_t)client->handle); | ||||
| @ -913,7 +913,7 @@ static void tmr_idle_handle (qse_tmr_t* tmr, const qse_ntime_t* now, qse_tmr_eve | ||||
| 			/*qse_gettime (&idle_event.when);*/ | ||||
| 			QSE_MEMSET (&idle_event, 0, QSE_SIZEOF(idle_event)); | ||||
| 			idle_event.when = *now; | ||||
| 			qse_addtime (&idle_event.when, &client->server->httpd->opt.idle_limit, &idle_event.when); | ||||
| 			qse_add_ntime (&idle_event.when, &client->server->httpd->opt.idle_limit, &idle_event.when); | ||||
| 			idle_event.ctx = client; | ||||
| 			idle_event.handler = tmr_idle_handle; | ||||
| 			idle_event.updater = tmr_idle_update; | ||||
|  | ||||
| @ -363,7 +363,7 @@ void qse_cnd_wait (qse_cnd_t* cnd, qse_mtx_t* mutex, const qse_ntime_t* waiting_ | ||||
| 		struct timespec ts; | ||||
|  | ||||
| 		qse_gettime (&t); | ||||
| 		qse_addtime (&t, waiting_time, &t); | ||||
| 		qse_add_ntime (&t, waiting_time, &t); | ||||
|  | ||||
| 		ts.tv_sec = t.sec; | ||||
| 		ts.tv_nsec = t.nsec; | ||||
|  | ||||
| @ -220,7 +220,7 @@ int qse_mtx_lock (qse_mtx_t* mtx, const qse_ntime_t* waiting_time) | ||||
| 		struct timespec ts; | ||||
|  | ||||
| 		qse_gettime (&t); | ||||
| 		qse_addtime (&t, waiting_time, &t); | ||||
| 		qse_add_ntime (&t, waiting_time, &t); | ||||
|  | ||||
| 		ts.tv_sec = t.sec; | ||||
| 		ts.tv_nsec = t.nsec; | ||||
|  | ||||
| @ -106,9 +106,9 @@ int qse_rwl_lockr (qse_rwl_t* rwl, const qse_ntime_t* waiting_time) | ||||
|  | ||||
| 	if (waiting_time) | ||||
| 	{ | ||||
| 		qse_cleartime (&zero); | ||||
| 		qse_clear_ntime (&zero); | ||||
| 		qse_gettime (&now); | ||||
| 		qse_addtime (&now, waiting_time, &dead_line); | ||||
| 		qse_add_ntime (&dead_line, &now, waiting_time); | ||||
| 	} | ||||
| 	if (qse_mtx_lock (&rwl->mtx, waiting_time) <= -1) return -1; | ||||
|  | ||||
| @ -120,8 +120,8 @@ int qse_rwl_lockr (qse_rwl_t* rwl, const qse_ntime_t* waiting_time) | ||||
| 			if (waiting_time) | ||||
| 			{ | ||||
| 				qse_gettime (&now); | ||||
| 				qse_subtime (&dead_line, &now, &rem); | ||||
| 				if (qse_cmptime(&rem, &zero) <= 0) | ||||
| 				qse_sub_ntime (&rem, &dead_line, &now); | ||||
| 				if (qse_cmp_ntime(&rem, &zero) <= 0) | ||||
| 				{ | ||||
| 					/* timed out */ | ||||
| 					rwl->rwait_count--; | ||||
| @ -170,9 +170,9 @@ int qse_rwl_lockw (qse_rwl_t* rwl, const qse_ntime_t* waiting_time) | ||||
|  | ||||
| 	if (waiting_time) | ||||
| 	{ | ||||
| 		qse_cleartime (&zero); | ||||
| 		qse_clear_ntime (&zero); | ||||
| 		qse_gettime (&now); | ||||
| 		qse_addtime (&now, waiting_time, &dead_line); | ||||
| 		qse_add_ntime (&dead_line, &now, waiting_time); | ||||
| 	} | ||||
| 	if (qse_mtx_lock (&rwl->mtx, waiting_time) <= -1) return -1; | ||||
|  | ||||
| @ -184,8 +184,8 @@ int qse_rwl_lockw (qse_rwl_t* rwl, const qse_ntime_t* waiting_time) | ||||
| 			if (waiting_time) | ||||
| 			{ | ||||
| 				qse_gettime (&now); | ||||
| 				qse_subtime (&dead_line, &now, &rem); | ||||
| 				if (qse_cmptime(&rem, &zero) <= 0) | ||||
| 				qse_sub_ntime (&rem, &dead_line, &now); | ||||
| 				if (qse_cmp_ntime(&rem, &zero) <= 0) | ||||
| 				{ | ||||
| 					/* timed out */ | ||||
| 					rwl->wwait_count--; | ||||
|  | ||||
| @ -84,7 +84,7 @@ static int httpd_main (int argc, qse_char_t* argv[]) | ||||
| 		int trait = QSE_HTTPD_CGIERRTONUL; | ||||
| 		qse_httpd_setopt (httpd, QSE_HTTPD_TRAIT,  &trait); | ||||
|  | ||||
| 		qse_inittime (&tmout, 10, 0); | ||||
| 		qse_init_ntime (&tmout, 10, 0); | ||||
| 		qse_httpd_setopt (httpd, QSE_HTTPD_TMOUT,  &tmout); | ||||
| 	} | ||||
|  | ||||
|  | ||||
| @ -57,7 +57,7 @@ static int thr_exec (qse_thr_t* thr, void* ctx) | ||||
| 			qse_ntime_t x; | ||||
| 			OUTMSG (QSE_T("write waiting"), xtn->id); | ||||
|  | ||||
| 			qse_inittime (&x, 3, 0); | ||||
| 			qse_init_ntime (&x, 3, 0); | ||||
| 			/*if (qse_rwl_lockw (rwl, QSE_NULL) >= 0)*/ | ||||
| 			if (qse_rwl_lockw (rwl, &x) >= 0) | ||||
| 			{ | ||||
|  | ||||
		Reference in New Issue
	
	Block a user