summaryrefslogtreecommitdiff
path: root/core/sharedarea.c
diff options
context:
space:
mode:
authorUnbit <info@unbit.it>2013-11-29 12:47:59 +0000
committerUnbit <info@unbit.it>2013-11-29 12:47:59 +0000
commit5182eaf485674787f3c75e27a95b4140d3f9b637 (patch)
tree1f6e633c2ac5544c5553a3b6feeba9b301f7452f /core/sharedarea.c
parent082d47e15647c1e56aece6abd5f39e8d9571a481 (diff)
downloaduwsgi-5182eaf485674787f3c75e27a95b4140d3f9b637.tar.gz
another round of sharedarea implementations
Diffstat (limited to 'core/sharedarea.c')
-rw-r--r--core/sharedarea.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/core/sharedarea.c b/core/sharedarea.c
index ca75bf3a..920f090d 100644
--- a/core/sharedarea.c
+++ b/core/sharedarea.c
@@ -27,11 +27,25 @@ struct uwsgi_sharedarea *uwsgi_sharedarea_get_by_id(int id, uint64_t pos) {
}
int uwsgi_sharedarea_read(int id, uint64_t pos, char *blob, uint64_t len) {
- return -1;
+ struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
+ if (!sa) return -1;
+ if (pos + len > sa->max_pos + 1) return -1;
+ uwsgi_rlock(sa->lock);
+ memcpy(blob, sa->area + pos, len);
+ sa->hits++;
+ uwsgi_rwunlock(sa->lock);
+ return 0;
}
int uwsgi_sharedarea_write(int id, uint64_t pos, char *blob, uint64_t len) {
- return -1;
+ struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
+ if (!sa) return -1;
+ if (pos + len > sa->max_pos + 1) return -1;
+ uwsgi_wlock(sa->lock);
+ memcpy(sa->area + pos, blob, len);
+ sa->updates++;
+ uwsgi_rwunlock(sa->lock);
+ return 0;
}
int uwsgi_sharedarea_read64(int id, uint64_t pos, int64_t *value) {
@@ -60,7 +74,10 @@ int uwsgi_sharedarea_wait(int id, int freq, int timeout) {
waiting += freq;
// lock sa
uwsgi_rlock(sa->lock);
- if (sa->updates != updates) return 0;
+ if (sa->updates != updates) {
+ uwsgi_rwunlock(sa->lock);
+ return 0;
+ }
// unlock sa
uwsgi_rwunlock(sa->lock);
}
@@ -113,6 +130,9 @@ void uwsgi_sharedareas_init() {
else {
sa = uwsgi_sharedarea_init_keyval(id, usl->value);
}
+ if (sa) {
+ uwsgi_log("sharedaread % initialized at %p\n", id, sa);
+ }
id++;
}
}