added experimental multi thread support
[NeonServV5.git] / src / UserNode.c
index 21b618d1118b51a16fac594e638f44976378ba6b..f90e72f2c1876fc95dcf315bb0b376d34bd6d276 100644 (file)
@@ -15,6 +15,7 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
  */
 #include "UserNode.h"
+#include "ChanNode.h"
 #include "ChanUser.h"
 #include "tools.h"
 #include "IRCEvents.h"
@@ -205,8 +206,10 @@ struct UserNode* addUser(const char *nick) {
     user->flags = 0;
     user->channel = NULL;
     user->last_who = 0;
+    SYNCHRONIZE(cache_sync);
     user->next = userList[userListIndex];
     userList[userListIndex] = user;
+    DESYNCHRONIZE(cache_sync);
     return user;
 }
 
@@ -269,8 +272,10 @@ struct UserNode* createTempUser(const char *nick) {
         user->flags &= ~USERFLAG_ISAUTHED; //remove authed flag (security reasons)
     strcpy(user->nick, nick);
     if(!already_on_list) {
+        SYNCHRONIZE(cache_sync);
         user->next = userList[TEMPUSER_LIST_INDEX];
         userList[TEMPUSER_LIST_INDEX] = user;
+        DESYNCHRONIZE(cache_sync);
     }
     return user;
 }
@@ -361,8 +366,10 @@ struct UserNode* createTempUserMask(const char *mask) {
         }
     }
     if(!already_on_list) {
+        SYNCHRONIZE(cache_sync);
         user->next = userList[TEMPUSER_LIST_INDEX];
         userList[TEMPUSER_LIST_INDEX] = user;
+        DESYNCHRONIZE(cache_sync);
     }
     return user;
 }
@@ -376,6 +383,7 @@ int renameUser(struct UserNode* user, const char *new_nick) {
     }
     //delUser(user, 0); //EPIC FAIL! This deletes the user from the channel Userlist -.-
     //manually remove the user from the old userList
+    SYNCHRONIZE(cache_sync);
     int userListIndex = get_nicklist_entry(user->nick[0]);
     if(userListIndex != -1) {
         struct UserNode *cuser, *last_user = NULL;
@@ -394,12 +402,14 @@ int renameUser(struct UserNode* user, const char *new_nick) {
     strcpy(user->nick, new_nick);
     user->next = userList[userListIndex];
     userList[userListIndex] = user;
+    DESYNCHRONIZE(cache_sync);
     return 1;
 }
 
 void delUser(struct UserNode* user, int freeUser) {
     int userListIndex = ((user->flags & USERFLAG_ISTMPUSER) ? TEMPUSER_LIST_INDEX : get_nicklist_entry(user->nick[0]));
     if(userListIndex == -1) return;
+    SYNCHRONIZE(cache_sync);
     event_freeuser(user);
     struct UserNode *cuser, *last_user = NULL;
     for(cuser = userList[userListIndex]; cuser; cuser = cuser->next) {
@@ -429,9 +439,11 @@ void delUser(struct UserNode* user, int freeUser) {
         free(user);
     } else
         user->next = NULL;
+    DESYNCHRONIZE(cache_sync);
 }
 
 void clearTempUsers() {
+    SYNCHRONIZE(cache_sync);
     int userListIndex = TEMPUSER_LIST_INDEX;
     struct UserNode *cuser, *next;
     time_t now = time(0);
@@ -441,4 +453,5 @@ void clearTempUsers() {
             delUser(cuser, 1);
         }
     }
+    DESYNCHRONIZE(cache_sync);
 }