MCPcopy Create free account
hub / github.com/acl-dev/acl / cond_wait

Method cond_wait

lib_acl_cpp/src/ipc/rpc.cpp:110–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110bool rpc_request::cond_wait(int timeout /* = -1 */)
111{
112 int status;
113
114 status = acl_pthread_mutex_lock(lock_);
115 if (status != 0) {
116 logger_error("pthread_mutex_lock error: %d", status);
117 return false;
118 }
119
120 if (--cond_count_ >= 0) {
121 status = acl_pthread_mutex_unlock(lock_);
122 if (status != 0) {
123 logger_error("pthread_mutex_unlock error: %d", status);
124 return false;
125 }
126 return true;
127 }
128
129 if (timeout < 0) {
130 status = acl_pthread_cond_wait(cond_, lock_);
131 if (status != 0) {
132 logger_error("pthread_cond_wait error: %d", status);
133 status = acl_pthread_mutex_unlock(lock_);
134 if (status != 0) {
135 logger_error("pthread_mutex_unlock error: %d", status);
136 }
137 return false;
138 }
139 status = acl_pthread_mutex_unlock(lock_);
140 if (status != 0) {
141 logger_error("pthread_mutex_unlock error: %d", status);
142 return false;
143 }
144 return true;
145 }
146
147 struct timeval tv;
148 struct timespec when_ttl;
149 gettimeofday(&tv, NULL);
150 when_ttl.tv_sec = tv.tv_sec + timeout / 1000;
151 when_ttl.tv_nsec = tv.tv_usec * 1000 + (timeout % 1000) * 1000;
152 wait_timedout_ = false;
153
154 status = acl_pthread_cond_timedwait(cond_, lock_, &when_ttl);
155 if (status != 0) {
156 if (status == ACL_ETIMEDOUT) {
157 wait_timedout_ = true;
158 } else {
159 logger_error("pthread_cond_timedwait error: %d", status);
160 }
161 status = acl_pthread_mutex_unlock(lock_);
162 if (status != 0) {
163 logger_error("pthread_mutex_unlock error: %d", status);
164 }
165 return false;
166 } else {
167 status = acl_pthread_mutex_unlock(lock_);

Callers

nothing calls this directly

Calls 5

acl_pthread_mutex_lockFunction · 0.85
acl_pthread_mutex_unlockFunction · 0.85
acl_pthread_cond_waitFunction · 0.85
gettimeofdayFunction · 0.50

Tested by

no test coverage detected