aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2011-03-29 08:45:04 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-03-29 08:45:04 -0700
commit4fecade5f21d5d062ebe1c70535367d3407bb68f (patch)
tree8997c814b16a593c8915a36e5f3e0d2db430bfec /include
parent15b15c4b4acede0b999e6a7af9ce797c6a58a62a (diff)
parentcb1e616e3c108a9c8b159bb95c3356acf5797ba2 (diff)
downloadsystem_core-4fecade5f21d5d062ebe1c70535367d3407bb68f.tar.gz
system_core-4fecade5f21d5d062ebe1c70535367d3407bb68f.tar.bz2
system_core-4fecade5f21d5d062ebe1c70535367d3407bb68f.zip
am cb1e616e: am 7c556549: Merge changes Icdefb5ff,Icd7f5f03
* commit 'cb1e616e3c108a9c8b159bb95c3356acf5797ba2': Fix potential race introduced in Icd7f5f03 SocketClient: add optional reference counting
Diffstat (limited to 'include')
-rw-r--r--include/sysutils/SocketClient.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/sysutils/SocketClient.h b/include/sysutils/SocketClient.h
index 2fcc3311..d6bb7d5d 100644
--- a/include/sysutils/SocketClient.h
+++ b/include/sysutils/SocketClient.h
@@ -19,6 +19,10 @@ class SocketClient {
/* Peer group ID */
gid_t mGid;
+ /* Reference count (starts at 1) */
+ pthread_mutex_t mRefCountMutex;
+ int mRefCount;
+
public:
SocketClient(int sock);
virtual ~SocketClient() {}
@@ -34,6 +38,13 @@ public:
// Sending binary data:
int sendData(const void *data, int len);
+
+ // Optional reference counting. Reference count starts at 1. If
+ // it's decremented to 0, it deletes itself.
+ // SocketListener creates a SocketClient (at refcount 1) and calls
+ // decRef() when it's done with the client.
+ void incRef();
+ bool decRef(); // returns true at 0 (but note: SocketClient already deleted)
};
typedef android::List<SocketClient *> SocketClientCollection;